total dl/up

This commit is contained in:
√(noham)² 2024-01-08 22:28:58 +01:00
parent c10515dc08
commit 62952917be
3 changed files with 203 additions and 42 deletions

View File

@ -79,7 +79,7 @@
}, },
"gridPos": { "gridPos": {
"h": 4, "h": 4,
"w": 3, "w": 2,
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
@ -96,9 +96,10 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -162,8 +163,8 @@
}, },
"gridPos": { "gridPos": {
"h": 4, "h": 4,
"w": 3, "w": 2,
"x": 3, "x": 2,
"y": 0 "y": 0
}, },
"id": 3, "id": 3,
@ -179,9 +180,10 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"expr": "qbittorrent_connected - qbittorrent_firewalled", "expr": "qbittorrent_connected - qbittorrent_firewalled",
@ -239,7 +241,7 @@
"gridPos": { "gridPos": {
"h": 4, "h": 4,
"w": 3, "w": 3,
"x": 6, "x": 4,
"y": 0 "y": 0
}, },
"id": 13, "id": 13,
@ -255,9 +257,10 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"expr": "qbittorrent_dht_nodes", "expr": "qbittorrent_dht_nodes",
@ -294,11 +297,11 @@
}, },
"gridPos": { "gridPos": {
"h": 4, "h": 4,
"w": 3, "w": 2,
"x": 9, "x": 7,
"y": 0 "y": 0
}, },
"id": 5, "id": 18,
"options": { "options": {
"colorMode": "value", "colorMode": "value",
"graphMode": "none", "graphMode": "none",
@ -311,9 +314,10 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -321,14 +325,14 @@
"uid": "${data_source}" "uid": "${data_source}"
}, },
"editorMode": "code", "editorMode": "code",
"expr": "sum by (app) (qbittorrent_dl_info_data_total)", "expr": "sum by (app) (qbittorrent_alltime_dl_total)",
"instant": false, "instant": false,
"interval": "", "interval": "",
"legendFormat": " ", "legendFormat": " ",
"refId": "A" "refId": "A"
} }
], ],
"title": "Data downloaded", "title": "Total downloaded",
"type": "stat" "type": "stat"
}, },
{ {
@ -354,8 +358,8 @@
}, },
"gridPos": { "gridPos": {
"h": 4, "h": 4,
"w": 3, "w": 2,
"x": 12, "x": 9,
"y": 0 "y": 0
}, },
"id": 6, "id": 6,
@ -371,9 +375,132 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${data_source}"
},
"editorMode": "code",
"expr": "sum by (app) (qbittorrent_alltime_ul_total)",
"instant": false,
"interval": "",
"legendFormat": " ",
"refId": "A"
}
],
"title": "Total uploaded",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${data_source}"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 2,
"x": 11,
"y": 0
},
"id": 5,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"last"
],
"fields": "",
"values": false
},
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "10.2.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${data_source}"
},
"editorMode": "code",
"expr": "sum by (app) (qbittorrent_dl_info_data_total)",
"instant": false,
"interval": "",
"legendFormat": " ",
"refId": "A"
}
],
"title": "Session downloaded",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${data_source}"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 2,
"x": 13,
"y": 0
},
"id": 19,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"last"
],
"fields": "",
"values": false
},
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -388,7 +515,7 @@
"refId": "A" "refId": "A"
} }
], ],
"title": "Data uploaded", "title": "Session uploaded",
"type": "stat" "type": "stat"
}, },
{ {
@ -431,9 +558,10 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"textMode": "auto" "textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -487,6 +615,8 @@
}, },
"id": 16, "id": 16,
"options": { "options": {
"minVizHeight": 75,
"minVizWidth": 75,
"orientation": "auto", "orientation": "auto",
"reduceOptions": { "reduceOptions": {
"calcs": [ "calcs": [
@ -498,7 +628,7 @@
"showThresholdLabels": false, "showThresholdLabels": false,
"showThresholdMarkers": true "showThresholdMarkers": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"expr": "rate(qbittorrent_dl_info_data_total[2m])", "expr": "rate(qbittorrent_dl_info_data_total[2m])",
@ -547,6 +677,8 @@
}, },
"id": 17, "id": 17,
"options": { "options": {
"minVizHeight": 75,
"minVizWidth": 75,
"orientation": "auto", "orientation": "auto",
"reduceOptions": { "reduceOptions": {
"calcs": [ "calcs": [
@ -558,7 +690,7 @@
"showThresholdLabels": false, "showThresholdLabels": false,
"showThresholdMarkers": true "showThresholdMarkers": true
}, },
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"targets": [ "targets": [
{ {
"expr": "rate(qbittorrent_up_info_data_total[2m])", "expr": "rate(qbittorrent_up_info_data_total[2m])",
@ -607,7 +739,7 @@
"alertThreshold": true "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@ -697,7 +829,7 @@
"alertThreshold": true "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "9.4.3", "pluginVersion": "10.2.2",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@ -807,7 +939,6 @@
"refresh": "10s", "refresh": "10s",
"revision": 1, "revision": 1,
"schemaVersion": 38, "schemaVersion": 38,
"style": "dark",
"tags": [], "tags": [],
"templating": { "templating": {
"list": [ "list": [
@ -844,9 +975,9 @@
}, },
{ {
"current": { "current": {
"selected": true, "selected": false,
"text": "Prometheus", "text": "Prometheus",
"value": "Prometheus" "value": "d4352f38-27bf-4c16-9fae-00e9ced664a1"
}, },
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
@ -869,8 +1000,8 @@
}, },
"timepicker": {}, "timepicker": {},
"timezone": "", "timezone": "",
"title": "Qbittorrent", "title": "Qb",
"uid": "eKyTETFMk", "uid": "eKyTETFMj",
"version": 1, "version": 1,
"weekStart": "" "weekStart": ""
} }

View File

@ -85,20 +85,22 @@ class QbittorrentMetricsCollector:
""" """
Returns metrics about the state of the qbittorrent server. Returns metrics about the state of the qbittorrent server.
""" """
response: dict[str, Any] = {} maindata: dict[str, Any] = {}
version: str = "" version: str = ""
# Fetch data from API # Fetch data from API
try: try:
response = self.client.transfer.info maindata = self.client.sync_maindata()
version = self.client.app.version version = self.client.app.version
except Exception as e: except Exception as e:
logger.error(f"Couldn't get server info: {e}") logger.error(f"Couldn't get server info: {e}")
server_state = maindata.get('server_state', {})
return [ return [
Metric( Metric(
name=f"{self.config['metrics_prefix']}_up", name=f"{self.config['metrics_prefix']}_up",
value=bool(response), value=bool(server_state),
labels={"version": version}, labels={"version": version},
help_text=( help_text=(
"Whether the qBittorrent server is answering requests from this" "Whether the qBittorrent server is answering requests from this"
@ -107,7 +109,7 @@ class QbittorrentMetricsCollector:
), ),
Metric( Metric(
name=f"{self.config['metrics_prefix']}_connected", name=f"{self.config['metrics_prefix']}_connected",
value=response.get("connection_status", "") == "connected", value=server_state.get("connection_status", "") == "connected",
labels={}, # no labels in the example labels={}, # no labels in the example
help_text=( help_text=(
"Whether the qBittorrent server is connected to the Bittorrent" "Whether the qBittorrent server is connected to the Bittorrent"
@ -116,7 +118,7 @@ class QbittorrentMetricsCollector:
), ),
Metric( Metric(
name=f"{self.config['metrics_prefix']}_firewalled", name=f"{self.config['metrics_prefix']}_firewalled",
value=response.get("connection_status", "") == "firewalled", value=server_state.get("connection_status", "") == "firewalled",
labels={}, # no labels in the example labels={}, # no labels in the example
help_text=( help_text=(
"Whether the qBittorrent server is connected to the Bittorrent" "Whether the qBittorrent server is connected to the Bittorrent"
@ -125,24 +127,38 @@ class QbittorrentMetricsCollector:
), ),
Metric( Metric(
name=f"{self.config['metrics_prefix']}_dht_nodes", name=f"{self.config['metrics_prefix']}_dht_nodes",
value=response.get("dht_nodes", 0), value=server_state.get("dht_nodes", 0),
labels={}, # no labels in the example labels={}, # no labels in the example
help_text="Number of DHT nodes connected to.", help_text="Number of DHT nodes connected to.",
), ),
Metric( Metric(
name=f"{self.config['metrics_prefix']}_dl_info_data", name=f"{self.config['metrics_prefix']}_dl_info_data",
value=response.get("dl_info_data", 0), value=server_state.get("dl_info_data", 0),
labels={}, # no labels in the example labels={}, # no labels in the example
help_text="Data downloaded since the server started, in bytes.", help_text="Data downloaded since the server started, in bytes.",
metric_type=MetricType.COUNTER, metric_type=MetricType.COUNTER,
), ),
Metric( Metric(
name=f"{self.config['metrics_prefix']}_up_info_data", name=f"{self.config['metrics_prefix']}_up_info_data",
value=response.get("up_info_data", 0), value=server_state.get("up_info_data", 0),
labels={}, # no labels in the example labels={}, # no labels in the example
help_text="Data uploaded since the server started, in bytes.", help_text="Data uploaded since the server started, in bytes.",
metric_type=MetricType.COUNTER, metric_type=MetricType.COUNTER,
), ),
Metric(
name=f"{self.config['metrics_prefix']}_alltime_dl",
value=server_state.get("alltime_dl", 0),
labels={}, # no labels in the example
help_text="Total data downloaded, in bytes.",
metric_type=MetricType.COUNTER,
),
Metric(
name=f"{self.config['metrics_prefix']}_alltime_ul",
value=server_state.get("alltime_ul", 0),
labels={}, # no labels in the example
help_text="Total data uploaded, in bytes.",
metric_type=MetricType.COUNTER,
),
] ]
def _fetch_categories(self) -> dict: def _fetch_categories(self) -> dict:

View File

@ -270,6 +270,20 @@ class TestQbittorrentMetricsCollector(unittest.TestCase):
help_text="Data uploaded since the server started, in bytes.", help_text="Data uploaded since the server started, in bytes.",
metric_type=MetricType.COUNTER, metric_type=MetricType.COUNTER,
), ),
Metric(
name="qbittorrent_alltime_dl",
value=0,
labels={}, # no labels in the example
help_text="Total data downloaded, in bytes.",
metric_type=MetricType.COUNTER,
),
Metric(
name="qbittorrent_alltime_ul",
value=0,
labels={}, # no labels in the example
help_text="Total data uploaded, in bytes.",
metric_type=MetricType.COUNTER,
),
] ]
metrics = self.collector._get_qbittorrent_status_metrics() metrics = self.collector._get_qbittorrent_status_metrics()