removed qbittorrent envs
This commit is contained in:
parent
3b2c4ae882
commit
c4af398b90
2 changed files with 31 additions and 136 deletions
|
@ -15,10 +15,6 @@ RUN pip3 install .
|
||||||
ENV IMMICH_API_TOKEN=""
|
ENV IMMICH_API_TOKEN=""
|
||||||
ENV IMMICH_HOST=""
|
ENV IMMICH_HOST=""
|
||||||
ENV IMMICH_PORT=""
|
ENV IMMICH_PORT=""
|
||||||
ENV QBITTORRENT_HOST=""
|
|
||||||
ENV QBITTORRENT_PORT=""
|
|
||||||
ENV QBITTORRENT_USER=""
|
|
||||||
ENV QBITTORRENT_PASS=""
|
|
||||||
#has to be EXPORT_PORT 8000 or else it does not work, same applies to the env file
|
#has to be EXPORT_PORT 8000 or else it does not work, same applies to the env file
|
||||||
ENV EXPORTER_PORT="8000"
|
ENV EXPORTER_PORT="8000"
|
||||||
ENV EXPORTER_LOG_LEVEL="INFO"
|
ENV EXPORTER_LOG_LEVEL="INFO"
|
||||||
|
|
|
@ -3,6 +3,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import faulthandler
|
import faulthandler
|
||||||
|
from typing import re
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from attrdict import AttrDict
|
from attrdict import AttrDict
|
||||||
|
@ -19,33 +20,13 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class QbittorrentMetricsCollector():
|
class QbittorrentMetricsCollector():
|
||||||
TORRENT_STATUSES = [
|
|
||||||
"downloading",
|
|
||||||
"uploading",
|
|
||||||
"complete",
|
|
||||||
"checking",
|
|
||||||
"errored",
|
|
||||||
"paused",
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.torrents = None
|
|
||||||
self.client = Client(
|
|
||||||
host=config["host"],
|
|
||||||
port=config["port"],
|
|
||||||
username=config["username"],
|
|
||||||
password=config["password"],
|
|
||||||
)
|
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
try:
|
|
||||||
self.torrents = self.client.torrents.info()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Couldn't get server info: {e}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
metrics = self.get_qbittorrent_metrics()
|
metrics = self.get_immich_metrics()
|
||||||
|
|
||||||
for metric in metrics:
|
for metric in metrics:
|
||||||
name = metric["name"]
|
name = metric["name"]
|
||||||
|
@ -61,12 +42,10 @@ class QbittorrentMetricsCollector():
|
||||||
prom_metric.add_metric(value=value, labels=labels.values())
|
prom_metric.add_metric(value=value, labels=labels.values())
|
||||||
yield prom_metric
|
yield prom_metric
|
||||||
|
|
||||||
def get_qbittorrent_metrics(self):
|
def get_immich_metrics(self):
|
||||||
metrics = []
|
metrics = []
|
||||||
metrics.extend(self.get_qbittorrent_status_metrics())
|
|
||||||
metrics.extend(self.get_qbittorrent_torrent_tags_metrics())
|
|
||||||
metrics.extend(self.get_immich_server_version_number())
|
metrics.extend(self.get_immich_server_version_number())
|
||||||
metrics.extend(self.get_immich_server_info())
|
# metrics.extend(self.get_immich_server_info())
|
||||||
|
|
||||||
return metrics
|
return metrics
|
||||||
|
|
||||||
|
@ -82,29 +61,34 @@ class QbittorrentMetricsCollector():
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.error(f"Couldn't get server version: {e.error_message}")
|
logger.error(f"Couldn't get server version: {e.error_message}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"name": f"{self.config['metrics_prefix']}_dht_nodes",
|
"name": f"{self.config['metrics_prefix']}_dht_nodes",
|
||||||
"value": response_server_info.json()["diskAvailable "],
|
"value": str(response_server_info.json()["diskAvailable"]),
|
||||||
"help": "DHT nodes connected to",
|
"help": "Available space on disk",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": f"{self.config['metrics_prefix']}_dl_info_data",
|
"name": f"{self.config['metrics_prefix']}_dl_info_data",
|
||||||
"value": response_server_info.json()["diskSize"],
|
"value": str(response_server_info.json()["diskSize"]),
|
||||||
"help": "Data downloaded this session (bytes)",
|
"help": "Disk size",
|
||||||
"type": "counter"
|
#"type": "counter"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
||||||
"value": response_server_info.json()["diskUse"],
|
"value": str(response_server_info.json()["diskUse"]),
|
||||||
"help": "Data uploaded this session (bytes)",
|
"help": "disk space in use",
|
||||||
"type": "counter"
|
#"type": "counter"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_immich_server_version_number(self):
|
def get_immich_server_version_number(self):
|
||||||
|
|
||||||
|
server_version_endpoint = "/api/server-info/version"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server_version_endpoint = "/api/server-info/version"
|
|
||||||
response_server_version = requests.request(
|
response_server_version = requests.request(
|
||||||
"GET",
|
"GET",
|
||||||
self.combine_url(server_version_endpoint),
|
self.combine_url(server_version_endpoint),
|
||||||
|
@ -113,18 +97,19 @@ class QbittorrentMetricsCollector():
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.error(f"Couldn't get server version: {e}")
|
logger.error(f"Couldn't get server version: {e}")
|
||||||
|
|
||||||
server_version_number = {str(response_server_version.json()["major"]) + "." +
|
server_version_number = ( str(response_server_version.json()["major"]) + "_" +
|
||||||
str(response_server_version.json()["minor"]) + "." +
|
str(response_server_version.json()["minor"]) + "_" +
|
||||||
str(response_server_version.json()["patch"]) + "."
|
str(response_server_version.json()["patch"])
|
||||||
}
|
)
|
||||||
str(server_version_number)
|
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
||||||
"value": str(server_version_number),
|
"value": server_version_number,
|
||||||
"help": "Data uploaded this session (bytes)",
|
"help": "server version number",
|
||||||
"type": "counter"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -135,88 +120,6 @@ class QbittorrentMetricsCollector():
|
||||||
|
|
||||||
return combined_url
|
return combined_url
|
||||||
|
|
||||||
def get_qbittorrent_status_metrics(self):
|
|
||||||
response = {}
|
|
||||||
version = ""
|
|
||||||
|
|
||||||
# Fetch data from API
|
|
||||||
try:
|
|
||||||
response = self.client.transfer.info
|
|
||||||
version = self.client.app.version
|
|
||||||
self.torrents = self.client.torrents.info()
|
|
||||||
except APIConnectionError as e:
|
|
||||||
logger.error(f"Couldn't get server info: {e.error_message}")
|
|
||||||
except Exception:
|
|
||||||
logger.error(f"Couldn't get server info")
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_up",
|
|
||||||
"value": bool(response),
|
|
||||||
"labels": {"version": version},
|
|
||||||
"help": "Whether if server is alive or not",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_connected",
|
|
||||||
"value": response.get("connection_status", "") == "connected",
|
|
||||||
"help": "Whether if server is connected or not",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_firewalled",
|
|
||||||
"value": response.get("connection_status", "") == "firewalled",
|
|
||||||
"help": "Whether if server is under a firewall or not",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_dht_nodes",
|
|
||||||
"value": response.get("dht_nodes", 0),
|
|
||||||
"help": "DHT nodes connected to",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_dl_info_data",
|
|
||||||
"value": response.get("dl_info_data", 0),
|
|
||||||
"help": "Data downloaded this session (bytes)",
|
|
||||||
"type": "counter"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"{self.config['metrics_prefix']}_up_info_data",
|
|
||||||
"value": response.get("up_info_data", 0),
|
|
||||||
"help": "Data uploaded this session (bytes)",
|
|
||||||
"type": "counter"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_qbittorrent_torrent_tags_metrics(self):
|
|
||||||
try:
|
|
||||||
categories = self.client.torrent_categories.categories
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Couldn't fetch categories: {e}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
if not self.torrents:
|
|
||||||
return []
|
|
||||||
|
|
||||||
metrics = []
|
|
||||||
categories.Uncategorized = AttrDict({'name': 'Uncategorized', 'savePath': ''})
|
|
||||||
for category in categories:
|
|
||||||
category_torrents = [t for t in self.torrents if
|
|
||||||
t['category'] == category or (category == "Uncategorized" and t['category'] == "")]
|
|
||||||
|
|
||||||
for status in self.TORRENT_STATUSES:
|
|
||||||
status_prop = f"is_{status}"
|
|
||||||
status_torrents = [
|
|
||||||
t for t in category_torrents if getattr(TorrentStates, status_prop).fget(TorrentStates(t['state']))
|
|
||||||
]
|
|
||||||
metrics.append({
|
|
||||||
"name": f"{self.config['metrics_prefix']}_torrents_count",
|
|
||||||
"value": len(status_torrents),
|
|
||||||
"labels": {
|
|
||||||
"status": status,
|
|
||||||
"category": category,
|
|
||||||
},
|
|
||||||
"help": f"Number of torrents in status {status} under category {category}"
|
|
||||||
})
|
|
||||||
|
|
||||||
return metrics
|
|
||||||
|
|
||||||
|
|
||||||
class SignalHandler():
|
class SignalHandler():
|
||||||
|
@ -265,10 +168,6 @@ def main():
|
||||||
"immich_host": get_config_value("IMMICH_HOST", ""),
|
"immich_host": get_config_value("IMMICH_HOST", ""),
|
||||||
"immich_port": get_config_value("IMMICH_PORT", ""),
|
"immich_port": get_config_value("IMMICH_PORT", ""),
|
||||||
"token": get_config_value("IMMICH_API_TOKEN", ""),
|
"token": get_config_value("IMMICH_API_TOKEN", ""),
|
||||||
"host": get_config_value("QBITTORRENT_HOST", ""),
|
|
||||||
"port": get_config_value("QBITTORRENT_PORT", ""),
|
|
||||||
"username": get_config_value("QBITTORRENT_USER", ""),
|
|
||||||
"password": get_config_value("QBITTORRENT_PASS", ""),
|
|
||||||
"exporter_port": int(get_config_value("EXPORTER_PORT", "8000")),
|
"exporter_port": int(get_config_value("EXPORTER_PORT", "8000")),
|
||||||
"log_level": get_config_value("EXPORTER_LOG_LEVEL", "INFO"),
|
"log_level": get_config_value("EXPORTER_LOG_LEVEL", "INFO"),
|
||||||
"metrics_prefix": get_config_value("METRICS_PREFIX", "immich"),
|
"metrics_prefix": get_config_value("METRICS_PREFIX", "immich"),
|
||||||
|
@ -279,11 +178,11 @@ def main():
|
||||||
# Register signal handler
|
# Register signal handler
|
||||||
signal_handler = SignalHandler()
|
signal_handler = SignalHandler()
|
||||||
|
|
||||||
if not config["host"]:
|
if not config["immich_host"]:
|
||||||
logger.error("No host specified, please set QBITTORRENT_HOST environment variable")
|
logger.error("No host specified, please set IMMICH_HOST environment variable")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not config["port"]:
|
if not config["token"]:
|
||||||
logger.error("No post specified, please set QBITTORRENT_PORT environment variable")
|
logger.error("No token specified, please set IMMICH_API_TOKEN environment variable")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Register our custom collector
|
# Register our custom collector
|
||||||
|
|
Loading…
Reference in a new issue