This Python script collects data from a Sendy installation and exposes it as metrics in a format compatible with Prometheus. The metrics provide insights into the total and active subscriber counts for all mailing lists configured in the Sendy system.
- Dynamically fetches all mailing lists from Sendy.
- Exposes metrics for total subscriber count per list.
- Integrates with Prometheus for monitoring and alerting.
The following metrics are exposed:
sendy_total_subscribers: Total number of subscribers for each mailing list.- Labels:
list_id,list_name
- Labels:
- Python 3.7+
- Sendy API credentials.
- Prometheus installed and configured.
-
Clone the repository:
git clone https://github.com/dakoller/sendy-prometheus-metrics.git cd sendy-prometheus-metrics -
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the project root with the following content:SENDY_API_URL=https://your_sendy_installation/api SENDY_API_KEY=your_sendy_api_key EXPORTER_PORT=8000 # Optional, default is 8000
-
Run the script:
python run_exporter.py
-
The metrics will be exposed at
http://<host>:<METRICS_PORT>/metrics.
-
Add the metrics endpoint to your Prometheus configuration:
scrape_configs: - job_name: 'sendy' static_configs: - targets: ['<host>:<METRICS_PORT>']
-
Reload your Prometheus configuration to apply the changes.
Example metrics exposed by the script:
# HELP sendy_total_subscribers Total subscribers count
# TYPE sendy_total_subscribers gauge
sendy_total_subscribers{list_id="1",list_name="Newsletter"} 150
sendy_total_subscribers{list_id="2",list_name="Updates"} 200
## Notes
- Ensure that the Sendy API key has the necessary permissions to access all lists.
- Use proper security measures to protect your API credentials and metrics endpoint.
## Troubleshooting
1. If the metrics are not appearing:
- Check the `.env` file for correct values.
- Verify that the Sendy API is reachable.
2. For connection issues:
- Ensure the host running the script is accessible by Prometheus.
- Check for firewall or network restrictions.
## License
This project is licensed under the MIT License. See the LICENSE file for details.