import os from ..base import BaseExporter POSTFIX_QUEUES = ["active", "bounce", "deferred", "incoming", "maildrop"] class CustomExporter(BaseExporter): def metric_config(self): return { "postfix_queue_size": {"type": "Gauge", "labels": ["queue"]}, } def generate(self): postfix_queue_size = self.metrics.get('postfix_queue_size') for queue in POSTFIX_QUEUES: path = os.path.join("/var/spool/postfix", queue) count = sum(len(files) for _, _, files in os.walk(path)) postfix_queue_size.labels(queue).set(count)