Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /opt/prometheus-monitoring-scripts/lib/python3.10/site-packages/custom_exporters/mailq/ |
Upload File : |
from ..base import BaseExporter from ..utils import get_podman_names, get_podman_disk_target from pathlib import Path POSTFIX_QUEUES = ["active", "bounce", "deferred", "incoming", "maildrop"] class CustomExporter(BaseExporter): def metric_config(self): return { "postfix_queue_size": {"type": "Gauge", "labels": ["machine", "queue"]}, "postfix_queue_errors": {"type": "Gauge", "labels": ["machine"]}, } def generate(self): pod_filter = None if len(self.args) >= 1: pod_filter = self.args[0] postfix_queue_size = self.metrics.get('postfix_queue_size') postfix_queue_errors = self.metrics.get('postfix_queue_errors') pod_names = get_podman_names(pod_filter) for pod in pod_names: try: target = get_podman_disk_target(pod, 'root') except Exception: postfix_queue_errors.labels(pod).inc() continue for queue in POSTFIX_QUEUES: path = Path("%s/%s/%s" % (target, "/var/spool/postfix/", queue)) if path.exists(): count = len([f for f in path.rglob("*") if f.is_file()]) postfix_queue_size.labels(pod, queue).set(count) else: postfix_queue_errors.labels(pod).inc()