From ec6af68f46653f4503fa7c932364510215ad8aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=88=9A=28noham=29=C2=B2?= Date: Sun, 21 Jan 2024 21:19:01 +0100 Subject: [PATCH] new metrics --- .gitignore | 1 + docker-compose.yml | 39 +++++++++++++++++++++ qbittorrent_exporter/exporter.py | 60 ++++++++++++++++++++++++++++++-- 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 5422bd9..dbf956d 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,4 @@ config.env # Ignore ruff files .ruff_cache +.DS_Store diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..086edae --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +name: prom-qb-alltime +services: + esanchezm: + cpu_shares: 90 + command: [] + deploy: + resources: + limits: + memory: 7943M + environment: + - QBITTORRENT_HOST=192.168.1.58 + - QBITTORRENT_PASS=Cp3mMdP!# + - QBITTORRENT_PORT=8188 + - QBITTORRENT_USER=noham + image: prom-qb-alltime + labels: + icon: https://raw.githubusercontent.com/esanchezm/prometheus-qbittorrent-exporter/master/logo.png + ports: + - target: 8000 + published: "9101" + protocol: tcp + restart: unless-stopped + volumes: [] + devices: [] + cap_add: [] + network_mode: bridge + privileged: false + container_name: "" +x-casaos: + author: self + category: self + hostname: "" + icon: https://raw.githubusercontent.com/esanchezm/prometheus-qbittorrent-exporter/master/logo.png + index: /metrics + port_map: "9101" + scheme: http + store_app_id: relaxed_albert + title: + custom: prom-qb-alltime diff --git a/qbittorrent_exporter/exporter.py b/qbittorrent_exporter/exporter.py index f44b835..83af29e 100644 --- a/qbittorrent_exporter/exporter.py +++ b/qbittorrent_exporter/exporter.py @@ -1,11 +1,13 @@ import faulthandler import logging import os +from dotenv import load_dotenv +load_dotenv() import signal import sys import time from dataclasses import dataclass, field -from enum import StrEnum, auto +from enum import Enum, auto from typing import Any, Iterable from prometheus_client import start_http_server @@ -17,8 +19,7 @@ from qbittorrentapi import Client, TorrentStates faulthandler.enable() logger = logging.getLogger() - -class MetricType(StrEnum): +class MetricType(Enum): """ Represents possible metric types (used in this project). """ @@ -159,6 +160,59 @@ class QbittorrentMetricsCollector: help_text="Total data uploaded, in bytes.", metric_type=MetricType.COUNTER, ), + Metric( + name=f"{self.config['metrics_prefix']}_total_peer_connections", + value=server_state.get("total_peer_connections", 0), + labels={}, # no labels in the example + help_text="total_peer_connections.", + metric_type=MetricType.COUNTER, + ), + + + #### Disk metrics + Metric( + name=f"{self.config['metrics_prefix']}_write_cache_overload", + value=server_state.get("write_cache_overload", 0), + labels={}, # no labels in the example + help_text="write_cache_overload.", + metric_type=MetricType.COUNTER, + ), + Metric( + name=f"{self.config['metrics_prefix']}_read_cache_overload", + value=server_state.get("read_cache_overload", 0), + labels={}, # no labels in the example + help_text="read_cache_overload.", + metric_type=MetricType.COUNTER, + ), + + Metric( + name=f"{self.config['metrics_prefix']}_read_cache_hits", + value=server_state.get("read_cache_hits", 0), + labels={}, # no labels in the example + help_text="read_cache_hits.", + metric_type=MetricType.COUNTER, + ), + Metric( + name=f"{self.config['metrics_prefix']}_average_time_queue", + value=server_state.get("average_time_queue", 0), + labels={}, # no labels in the example + help_text="average_time_queue.", + metric_type=MetricType.COUNTER, + ), + Metric( + name=f"{self.config['metrics_prefix']}_free_space_on_disk", + value=server_state.get("free_space_on_disk", 0), + labels={}, # no labels in the example + help_text="free_space_on_disk.", + metric_type=MetricType.COUNTER, + ), + Metric( + name=f"{self.config['metrics_prefix']}_queued_io_jobs", + value=server_state.get("queued_io_jobs", 0), + labels={}, # no labels in the example + help_text="queued_io_jobs.", + metric_type=MetricType.COUNTER, + ), ] def _fetch_categories(self) -> dict: