Allow setting a metrics prefix
This commit is contained in:
parent
0b3fb04728
commit
eee65ec84e
2 changed files with 17 additions and 15 deletions
15
README.md
15
README.md
|
@ -33,22 +33,23 @@ The application reads configuration using environment variables:
|
||||||
| `QBITTORRENT_PASS` | `""` | qbittorrent password |
|
| `QBITTORRENT_PASS` | `""` | qbittorrent password |
|
||||||
| `EXPORTER_PORT` | `8000` | Exporter listening port |
|
| `EXPORTER_PORT` | `8000` | Exporter listening port |
|
||||||
| `EXPORTER_LOG_LEVEL` | `INFO` | Log level. One of: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
|
| `EXPORTER_LOG_LEVEL` | `INFO` | Log level. One of: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
|
||||||
|
| `METRICS_PREFIX` | `qbittorrent` | Prefix to add to all the metrics |
|
||||||
|
|
||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
These are the metrics this program exports:
|
These are the metrics this program exports, assuming the `METRICS_PREFIX` is `qbittorrent`:
|
||||||
|
|
||||||
|
|
||||||
| Metric name | Type | Description |
|
| Metric name | Type | Description |
|
||||||
| --------------------------------------------------- | -------- | ---------------- |
|
| --------------------------------------------------- | -------- | ---------------- |
|
||||||
| `qbittorrent_up` | gauge | Whether if the qBittorrent server is answering requests from this exporter. A `version` label with the server version is added |
|
| `qbittorrent_up` | gauge | Whether if the qBittorrent server is answering requests from this exporter. A `version` label with the server version is added |
|
||||||
| `connected` | gauge | Whether if the qBittorrent server is connected to the Bittorrent network. |
|
| `qbittorrent_connected` | gauge | Whether if the qBittorrent server is connected to the Bittorrent network. |
|
||||||
| `firewalled` | gauge | Whether if the qBittorrent server is connected to the Bittorrent network but is behind a firewall. |
|
| `qbittorrent_firewalled` | gauge | Whether if the qBittorrent server is connected to the Bittorrent network but is behind a firewall. |
|
||||||
| `dht_nodes` | gauge | Number of DHT nodes connected to |
|
| `qbittorrent_dht_nodes` | gauge | Number of DHT nodes connected to |
|
||||||
| `dl_info_data` | counter | Data downloaded since the server started, in bytes |
|
| `qbittorrent_dl_info_data` | counter | Data downloaded since the server started, in bytes |
|
||||||
| `up_info_data` | counter | Data uploaded since the server started, in bytes |
|
| `qbittorrent_up_info_data` | counter | Data uploaded since the server started, in bytes |
|
||||||
| `torrents_count` | gauge | Number of torrents for each `category` and `status`. Example: `torrents_count{category="movies",status="downloading"}`|
|
| `qbittorrent_torrents_count` | gauge | Number of torrents for each `category` and `status`. Example: `qbittorrent_torrents_count{category="movies",status="downloading"}`|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -77,34 +77,34 @@ class QbittorrentMetricsCollector():
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"name": "qbittorrent_up",
|
"name": f"{self.config['metrics_prefix']}_up",
|
||||||
"value": response is not None,
|
"value": response is not None,
|
||||||
"labels": {"version": version},
|
"labels": {"version": version},
|
||||||
"help": "Whether if server is alive or not",
|
"help": "Whether if server is alive or not",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "connected",
|
"name": f"{self.config['metrics_prefix']}_connected",
|
||||||
"value": response.get("connection_status", "") == "connected",
|
"value": response.get("connection_status", "") == "connected",
|
||||||
"help": "Whether if server is connected or not",
|
"help": "Whether if server is connected or not",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "firewalled",
|
"name": f"{self.config['metrics_prefix']}_firewalled",
|
||||||
"value": response.get("connection_status", "") == "firewalled",
|
"value": response.get("connection_status", "") == "firewalled",
|
||||||
"help": "Whether if server is under a firewall or not",
|
"help": "Whether if server is under a firewall or not",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "dht_nodes",
|
"name": f"{self.config['metrics_prefix']}_dht_nodes",
|
||||||
"value": response.get("dht_nodes", 0),
|
"value": response.get("dht_nodes", 0),
|
||||||
"help": "DHT nodes connected to",
|
"help": "DHT nodes connected to",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "dl_info_data",
|
"name": f"{self.config['metrics_prefix']}_dl_info_data",
|
||||||
"value": response.get("dl_info_data", 0),
|
"value": response.get("dl_info_data", 0),
|
||||||
"help": "Data downloaded this session (bytes)",
|
"help": "Data downloaded this session (bytes)",
|
||||||
"type": "counter"
|
"type": "counter"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "up_info_data",
|
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
||||||
"value": response.get("up_info_data", 0),
|
"value": response.get("up_info_data", 0),
|
||||||
"help": "Data uploaded this session (bytes)",
|
"help": "Data uploaded this session (bytes)",
|
||||||
"type": "counter"
|
"type": "counter"
|
||||||
|
@ -131,7 +131,7 @@ class QbittorrentMetricsCollector():
|
||||||
t for t in category_torrents if getattr(TorrentStates, status_prop).fget(TorrentStates(t['state']))
|
t for t in category_torrents if getattr(TorrentStates, status_prop).fget(TorrentStates(t['state']))
|
||||||
]
|
]
|
||||||
metrics.append({
|
metrics.append({
|
||||||
"name": "torrents_count",
|
"name": f"{self.config['metrics_prefix']}_torrents_count",
|
||||||
"value": len(status_torrents),
|
"value": len(status_torrents),
|
||||||
"labels": {
|
"labels": {
|
||||||
"status": status,
|
"status": status,
|
||||||
|
@ -166,7 +166,8 @@ def main():
|
||||||
"username": os.environ.get("QBITTORRENT_USER", ""),
|
"username": os.environ.get("QBITTORRENT_USER", ""),
|
||||||
"password": os.environ.get("QBITTORRENT_PASS", ""),
|
"password": os.environ.get("QBITTORRENT_PASS", ""),
|
||||||
"exporter_port": int(os.environ.get("EXPORTER_PORT", "8000")),
|
"exporter_port": int(os.environ.get("EXPORTER_PORT", "8000")),
|
||||||
"log_level": os.environ.get("EXPORTER_LOG_LEVEL", "INFO")
|
"log_level": os.environ.get("EXPORTER_LOG_LEVEL", "INFO"),
|
||||||
|
"metrics_prefix": os.environ.get("METRICS_PREFIX", "qbittorrent"),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Register signal handler
|
# Register signal handler
|
||||||
|
|
Loading…
Reference in a new issue