This is a Prometheus exporter for dmarc-srg that fetches data from the apps' database and exposes the message counters via prometheus metrics.
The only metric this exporter purposefully creates is dmarc_srg_reports_total
. The prometheus-client library exports some other useful data such as memory usage. The *_created
metrics are timestamps of when the counter with the specific labelset was created, they cannot be turned off (but you may exclude them from scrapes via your scrape config) - see client_python issue #438
# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 428.0
[...]
# HELP dmarc_srg_reports_total Number of messages reported to dmarc-srg
# TYPE dmarc_srg_reports_total counter
dmarc_srg_reports_total{domain_fqdn="your.domain",record_dkim_align="2",record_spf_align="2",report_org="google.com"} 101.0
dmarc_srg_reports_total{domain_fqdn="your.other.domain",record_dkim_align="2",record_spf_align="2",report_org="google.com"} 86.0
[...]
# HELP dmarc_srg_reports_created Number of messages reported to dmarc-srg
# TYPE dmarc_srg_reports_created gauge
dmarc_srg_reports_created{domain_fqdn="your.domain",record_dkim_align="2",record_spf_align="2",report_org="google.com"} 1.7053995771044967e+09
dmarc_srg_reports_created{domain_fqdn="your.other.domain",record_dkim_align="2",record_spf_align="2",report_org="google.com"} 1.7053995771045454e+09
dmarc_srg_reports_total
is a counter value that restarts at 0 when the exporter is restarted, which avoids having to read the entire dmarc-srg database at startup. Use promql functions that ignore counter resets, such as increase
to query the values. For example to query for the number of messages failing SPF per day:
sum(increase(dmarc_srg_reports_total{record_spf_align="0"}[24h])) by (domain_fqdn)
- job_name: dmarc-srg
static_configs:
- targets:
- 127.0.0.1:10012
scheme: http
metrics_path: /
scrape_interval: 5m
docker run --rm --name dmarc_srg_exporter -p 10012:10012 \
ghcr.io/h3po/dmarc-srg-exporter:latest \
your_db_host your_db_user your_db_password your_db_database
- Python 3.x
- prometheus-client library
- PyMySQL library
-
Clone the repository:
git clone https://github.com/h3po/prometheus-dmarc_srg_exporter.git cd prometheus-dmarc_srg_exporter
-
Install dependencies in a virtualenv:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
Run the exporter script with the required database parameters:
python dmarc_srg_exporter.py your_db_host your_db_user your_db_password your_db_database
Optional arguments:
--update-interval
: Set the sleep interval between updates in seconds (default: 15).--port
: Set the listening port for Prometheus metrics endpoint (default: 10012).
If you find any issues or have suggestions, please feel free to open an issue or submit a pull request.