mirror of
https://github.com/NohamR/prometheus-qbittorrent-exporter.git
synced 2025-05-24 00:59:28 +00:00
Return matrics on connection error
This commit is contained in:
parent
bc8676ed30
commit
e1ed34147c
@ -29,7 +29,6 @@ class QbittorrentMetricsCollector():
|
|||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.torrents = None
|
|
||||||
self.client = Client(
|
self.client = Client(
|
||||||
host=config["host"],
|
host=config["host"],
|
||||||
port=config["port"],
|
port=config["port"],
|
||||||
@ -38,12 +37,6 @@ class QbittorrentMetricsCollector():
|
|||||||
)
|
)
|
||||||
|
|
||||||
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_qbittorrent_metrics()
|
||||||
|
|
||||||
for metric in metrics:
|
for metric in metrics:
|
||||||
@ -75,11 +68,8 @@ class QbittorrentMetricsCollector():
|
|||||||
try:
|
try:
|
||||||
response = self.client.transfer.info
|
response = self.client.transfer.info
|
||||||
version = self.client.app.version
|
version = self.client.app.version
|
||||||
self.torrents = self.client.torrents.info()
|
except Exception as e:
|
||||||
except APIConnectionError as e:
|
logger.error(f"Couldn't get server info: {e}")
|
||||||
logger.error(f"Couldn't get server info: {e.error_message}")
|
|
||||||
except Exception:
|
|
||||||
logger.error(f"Couldn't get server info")
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -120,17 +110,15 @@ class QbittorrentMetricsCollector():
|
|||||||
def get_qbittorrent_torrent_tags_metrics(self):
|
def get_qbittorrent_torrent_tags_metrics(self):
|
||||||
try:
|
try:
|
||||||
categories = self.client.torrent_categories.categories
|
categories = self.client.torrent_categories.categories
|
||||||
|
torrents = self.client.torrents.info()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Couldn't fetch categories: {e}")
|
logger.error(f"Couldn't fetch torrent info: {e}")
|
||||||
return []
|
|
||||||
|
|
||||||
if not self.torrents:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
metrics = []
|
metrics = []
|
||||||
categories.Uncategorized = AttrDict({'name': 'Uncategorized', 'savePath': ''})
|
categories.Uncategorized = AttrDict({'name': 'Uncategorized', 'savePath': ''})
|
||||||
for category in categories:
|
for category in categories:
|
||||||
category_torrents = [t for t in self.torrents if t['category'] == category or (category == "Uncategorized" and t['category'] == "")]
|
category_torrents = [t for t in torrents if t['category'] == category or (category == "Uncategorized" and t['category'] == "")]
|
||||||
|
|
||||||
for status in self.TORRENT_STATUSES:
|
for status in self.TORRENT_STATUSES:
|
||||||
status_prop = f"is_{status}"
|
status_prop = f"is_{status}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user