Python Monitoring Agent
Python Monitoring Agent (PMA) is a simple, lightweight, and modular monitoring agent.
PMA serves as a standalone metrics exporter. It requires a database (influxdb) and a frontend tool (such as Grafana) to properly visualize data from influxdb.
Features
- Swap Information: App retrieves information about the swap memory usage, including total swap space, used swap space, free swap space. On frontend side, those are also calculated into SWAP utilization percentage
- RAM Information: App provides insights into RAM usage, including total RAM, used RAM, free RAM, cached RAM, buffers. On frontend side, those are also calculated into RAM utilization percentage
- CPU Information: App gathers CPU-related details such as user CPU time, system CPU time, idle CPU time, I/O wait time, current CPU frequency, maximum CPU frequency, minimum CPU frequency, CPU load averages (1m, 5m, 15m), CPU utilization percentage, CPU temperature, and the number of processors.
- Disk Information: App provides disks and filesystems information such as block device name, mounted filesystem, space used, space avaliable and space total. On frontend side, those are also calculated into filesystem utilization percentage
- Network Information App gathers network interface related metrics like bytes/packets sent/retrived, errors on interfaces and dropped packets. On frontend side, those are also calculated into network utilization over time (Bytes per second)
- Exception Handling and Logging: App encapsulates each value retrieval in a try-except block. If an exception occurs, the value is assigned as
None, and the exception is passed to alogginginstance, allowing for better error tracking and handling.
Usage
Currently, there are two ways to use this software:
- As a Docker container (recommended for Linux)
- As a Python package (requires Python 3.6 or higher)
Note:
Docker usage is recommended on Linux but shouldn't be used on MacOS or Windows! Docker desktop for MacOS and Windows is essentially a Linux virtual machine, so metrics collected from Docker desktop with PMA would be meaningless. For these two systems, using the Python native version is recommended.
Docker Usage
Agent Only:
- Copy the
.env.distfile to.env. - Populate the
.envfile with the appropriate values (only those starting with "AGENT" need to be modified). - Set the docker-compose profile:
export COMPOSE_PROFILE=agent-only. - Build the agent image:
docker compose build. - Start the agent image:
docker compose up -d.
Full Stack:
- Copy the
.env.distfile to.env. - Populate the
.envfile with the proper values. - Set the docker-compose profile:
export COMPOSE_PROFILE=full. - Start the InfluxDB container:
docker compose up -d influxdb. - Access the InfluxDB WebUI (default: http://127.0.0.1:8086).
- Create an API token from the "Load Data" > "API Tokens" menu.
- Copy and paste the API token into the
.envfile. - Build the agent container:
docker compose build. - Start the other containers:
docker compose up -d. - Open the Grafana WebUI (default: http://127.0.0.1:3000).
- From the "Administration" > "Data Sources" menu, create a new InfluxDB datasource:
- Set the query language to Flux.
- Add the InfluxDB URL. Both Grafana and InfluxDB are inside the docker-compose default network, so use
http://influxdb:8086as the URL (modify accordingly if you changed the service name in docker-compose.yml). - Disable basic authentication.
- Fill in the default bucket and default organization. This is important if you want to use the provided dashboard without modification.
- Fill in the API token with your token.
- From the "Dashboards" menu, select "New" > "Import" and drag and drop the
docker/grafana/Python-monitoring-agent.jsonfile. - Open your dashboard and select your host.
Python Package Usage
Agent Only:
- Install the Python package:
pip install ./docker/agent. - Start the app with
pmafrom the terminal. - An empty configuration file will be created in
$XDG_CONFIG_HOMEdirectory. If$XDG_CONFIG_HOMEis not set or you are on Windows or macOS,$HOME/.configwill be used as the base directory. - Edit the configuration file at
$XDG_CONFIG_HOME/python-monitoring-agent/config.yamlor$HOME/.config/python-monitoring-agent/config.yamland replace the default values with your own. - Start the app with
pma. If you want to start the app in the background without binding it to your terminal, usenohup pma &(works on both macOS and Linux).
Configuration explained
| Config Option | Explanation |
|---|---|
| AGENT_INFLUX_URL | The URL of the InfluxDB instance to connect to. |
| AGENT_INFLUX_BUCKET | The name of the InfluxDB bucket to use. |
| AGENT_INFLUX_ORG | The name of the InfluxDB organization to use. |
| AGENT_INFLUX_TOKEN | The API token for accessing InfluxDB. |
| AGENT_HOSTNAME | The hostname of the agent. |
| AGENT_POOLING_RATE | The rate at which the agent performs pooling. |
| AGENT_VERBOSITY | The level of verbosity for logging. |
| AGENT_DOCKER | Docker specific option, needs to exist as environment if docker is used (Can be set to anything, like "True") |
| DOCKER_INFLUXDB_INIT_USERNAME | Initial WebUI username for InfluxDB. |
| DOCKER_INFLUXDB_INIT_PASSWORD | Initial WebUI password for InfluxDB. |
| DOCKER_INFLUXDB_INIT_ORG | Initial organization name for InfluxDB. |
| DOCKER_INFLUXDB_INIT_BUCKET | Initial bucket name for InfluxDB. |
| DOCKER_INFLUXDB_INIT_MODE | Initial Docker setup mode for InfluxDB. |
TODO
- Add sensors metrics
- Add more metrics overall
- Create CI/CD Pipeline that would be building and publishing Docker images and Python package on releases
- Think of a way of allowing new modules to be added easily
- Add cron/systemd timers mode
- Add systemd unit file
Contribution
Contributions Welcome!
We welcome contributions from anyone interested in improving our project. If you have ideas, bug fixes, or new features to propose, we encourage you to create pull requests. Together, we can make this project even better!
Feel free to explore the codebase, find areas where you can contribute, and submit your pull requests. We appreciate your support and look forward to collaborating with you!
Metadata
Release files for python-monitoring-agent 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Python Monitoring Agent-0.2.1.tar.gz | 17.7 kB | Without provenance | Details for Python Monitoring Agent-0.2.1.tar.gz |
Release files / Python Monitoring Agent-0.2.1.tar.gz
| Download URL | Python Monitoring Agent-0.2.1.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31d2f69ccaf80f2ab961c5344072e48877ec64e0ac85b2bf6ce1c7841c4d4029
|
|
BLAKE2b-256 checksum How to use checksums |
da908acce4d4ff7b282cd17904b5071ed69e673edb62ed12896b953090c15704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for python-monitoring-agent 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.