mirror of
https://github.com/NohamR/prometheus-qbittorrent-exporter.git
synced 2026-01-10 16:18:38 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
940b5c6242 | ||
|
|
f47ebe94d0 | ||
|
|
e1ed34147c | ||
|
|
bc8676ed30 | ||
|
|
fb12d50373 | ||
|
|
bb3695ece6 | ||
|
|
a9a3e5d1e6 |
22
.github/workflows/docker.yml
vendored
22
.github/workflows/docker.yml
vendored
@@ -36,9 +36,27 @@ jobs:
|
|||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push docker
|
- name: Build and push docker to DockerHub
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64,linux/386
|
platforms: linux/amd64,linux/arm64,linux/386
|
||||||
tags: ${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:latest,${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }}
|
tags: |
|
||||||
|
${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:latest
|
||||||
|
${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Login to Github Container Registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.GHCR_PERSONAL_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push docker to Github Container Registry
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/386
|
||||||
|
tags: |
|
||||||
|
ghcr.io/${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:latest
|
||||||
|
ghcr.io/${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }}
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ qbittorrent-exporter
|
|||||||
Another option is run it in a docker container.
|
Another option is run it in a docker container.
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run -e QBITTORRENT_PORT=8080 -e QBITTORRENT_HOST=myserver.local -p 8000:8000 esanchezm/prometheus-qbittorrent-exporter
|
docker run \
|
||||||
|
-e QBITTORRENT_PORT=8080 \
|
||||||
|
-e QBITTORRENT_HOST=myserver.local \
|
||||||
|
-p 8000:8000 \
|
||||||
|
ghcr.io/esanchezm/prometheus-qbittorrent-exporter
|
||||||
```
|
```
|
||||||
Add this to your prometheus.yml
|
Add this to your prometheus.yml
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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}"
|
||||||
@@ -211,7 +199,7 @@ def main():
|
|||||||
logger.error("No host specified, please set QBITTORRENT_HOST environment variable")
|
logger.error("No host specified, please set QBITTORRENT_HOST environment variable")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not config["port"]:
|
if not config["port"]:
|
||||||
logger.error("No post specified, please set QBITTORRENT_PORT environment variable")
|
logger.error("No port specified, please set QBITTORRENT_PORT environment variable")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Register our custom collector
|
# Register our custom collector
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -17,7 +17,7 @@ setup(
|
|||||||
keywords=['prometheus', 'qbittorrent'],
|
keywords=['prometheus', 'qbittorrent'],
|
||||||
classifiers=[],
|
classifiers=[],
|
||||||
python_requires='>=3',
|
python_requires='>=3',
|
||||||
install_requires=['attrdict==2.0.1', 'qbittorrent-api==2021.3.18', 'prometheus_client==0.8.0', 'python-json-logger==0.1.5'],
|
install_requires=['attrdict==2.0.1', 'qbittorrent-api==2022.1.27', 'prometheus_client==0.12.0 ', 'python-json-logger==2.0.2'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'qbittorrent-exporter=qbittorrent_exporter.exporter:main',
|
'qbittorrent-exporter=qbittorrent_exporter.exporter:main',
|
||||||
|
|||||||
Reference in New Issue
Block a user