mirror of
https://github.com/NohamR/prometheus-qbittorrent-exporter.git
synced 2026-01-10 16:18:38 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c885b5fa0 | ||
|
|
039f7a7ef4 | ||
|
|
8bdaa48c48 | ||
|
|
e8dd24f731 | ||
|
|
12dcad10d5 | ||
|
|
597307c230 | ||
|
|
a25005b6a0 | ||
|
|
cfe62f8115 | ||
|
|
b5d20e3fe6 |
6
.github/workflows/docker.yml
vendored
6
.github/workflows/docker.yml
vendored
@@ -13,6 +13,9 @@ jobs:
|
|||||||
- name: 'Checkout GitHub Action'
|
- name: 'Checkout GitHub Action'
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
@@ -37,4 +40,5 @@ jobs:
|
|||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: esanchezm/prometheus-qbittorrent-exporter:latest,esanchezm/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }}
|
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 }}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from pythonjsonlogger import jsonlogger
|
|||||||
|
|
||||||
# Enable dumps on stderr in case of segfault
|
# Enable dumps on stderr in case of segfault
|
||||||
faulthandler.enable()
|
faulthandler.enable()
|
||||||
logger = None
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class QbittorrentMetricsCollector():
|
class QbittorrentMetricsCollector():
|
||||||
@@ -152,45 +152,61 @@ class QbittorrentMetricsCollector():
|
|||||||
|
|
||||||
class SignalHandler():
|
class SignalHandler():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.shutdown = False
|
self.shutdownCount = 0
|
||||||
|
|
||||||
# Register signal handler
|
# Register signal handler
|
||||||
signal.signal(signal.SIGINT, self._on_signal_received)
|
signal.signal(signal.SIGINT, self._on_signal_received)
|
||||||
signal.signal(signal.SIGTERM, self._on_signal_received)
|
signal.signal(signal.SIGTERM, self._on_signal_received)
|
||||||
|
|
||||||
def is_shutting_down(self):
|
def is_shutting_down(self):
|
||||||
return self.shutdown
|
return self.shutdownCount > 0
|
||||||
|
|
||||||
def _on_signal_received(self, signal, frame):
|
def _on_signal_received(self, signal, frame):
|
||||||
|
if self.shutdownCount > 1:
|
||||||
|
logger.warn("Forcibly killing exporter")
|
||||||
|
sys.exit(1)
|
||||||
logger.info("Exporter is shutting down")
|
logger.info("Exporter is shutting down")
|
||||||
self.shutdown = True
|
self.shutdownCount += 1
|
||||||
|
|
||||||
|
def get_config_value(key, default=""):
|
||||||
|
input_path = os.environ.get("FILE__" + key, None)
|
||||||
|
if input_path is not None:
|
||||||
|
try:
|
||||||
|
with open(input_path, "r") as input_file:
|
||||||
|
return input_file.read().strip()
|
||||||
|
except IOError as e:
|
||||||
|
logger.error(f"Unable to read value for {key} from {input_path}: {str(e)}")
|
||||||
|
|
||||||
|
return os.environ.get(key, default)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = {
|
# Init logger so it can be used
|
||||||
"host": os.environ.get("QBITTORRENT_HOST", ""),
|
|
||||||
"port": os.environ.get("QBITTORRENT_PORT", ""),
|
|
||||||
"username": os.environ.get("QBITTORRENT_USER", ""),
|
|
||||||
"password": os.environ.get("QBITTORRENT_PASS", ""),
|
|
||||||
"exporter_port": int(os.environ.get("EXPORTER_PORT", "8000")),
|
|
||||||
"log_level": os.environ.get("EXPORTER_LOG_LEVEL", "INFO"),
|
|
||||||
"metrics_prefix": os.environ.get("METRICS_PREFIX", "qbittorrent"),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Register signal handler
|
|
||||||
signal_handler = SignalHandler()
|
|
||||||
|
|
||||||
# Init logger
|
|
||||||
logHandler = logging.StreamHandler()
|
logHandler = logging.StreamHandler()
|
||||||
formatter = jsonlogger.JsonFormatter(
|
formatter = jsonlogger.JsonFormatter(
|
||||||
"%(asctime) %(levelname) %(message)",
|
"%(asctime) %(levelname) %(message)",
|
||||||
datefmt="%Y-%m-%d %H:%M:%S"
|
datefmt="%Y-%m-%d %H:%M:%S"
|
||||||
)
|
)
|
||||||
logHandler.setFormatter(formatter)
|
logHandler.setFormatter(formatter)
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.addHandler(logHandler)
|
logger.addHandler(logHandler)
|
||||||
|
logger.setLevel("INFO") # default until config is loaded
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"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")),
|
||||||
|
"log_level": get_config_value("EXPORTER_LOG_LEVEL", "INFO"),
|
||||||
|
"metrics_prefix": get_config_value("METRICS_PREFIX", "qbittorrent"),
|
||||||
|
}
|
||||||
|
# set level once config has been loaded
|
||||||
logger.setLevel(config["log_level"])
|
logger.setLevel(config["log_level"])
|
||||||
|
|
||||||
|
# Register signal handler
|
||||||
|
signal_handler = SignalHandler()
|
||||||
|
|
||||||
|
|
||||||
if not config["host"]:
|
if not config["host"]:
|
||||||
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)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
|
|||||||
setup(
|
setup(
|
||||||
name='prometheus-qbittorrent-exporter',
|
name='prometheus-qbittorrent-exporter',
|
||||||
packages=['qbittorrent_exporter'],
|
packages=['qbittorrent_exporter'],
|
||||||
version='1.1.2',
|
version='1.2.0',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
description='Prometheus exporter for qbittorrent',
|
description='Prometheus exporter for qbittorrent',
|
||||||
|
|||||||
Reference in New Issue
Block a user