This project provides a lightweight Python-based REST server that proxies monitoring data from BetterStack and exposes it in a Grafana-friendly format. It enables Grafana to visualize website response times and availability metrics using the Infinity plugin or other JSON-compatible data sources.
- REST API endpoint to serve BetterStack uptime and SLA data
- Supports multiple regions (US, EU, AS, AU)
- Timestamp conversion to Unix milliseconds (Grafana-compatible)
- Query filtering by node hostname
- Python 3.7+
- A BetterStack API token
- Grafana with the Infinity plugin
pip install flask flask-compress requestsexport BetterStack_API_TOKEN=your_betterstack_tokenpython3 grafana_server.pyThe server will be available at http://<your_host>:5006
Returns response time data per region.
Query parameters:
nodename: hostname to match the nodeurl: monitored website URLregion: comma-separated list of regions (default:us,eu,as,au)
Sample response:
[
{
"timestamp": 1744539757000,
"region": "us",
"response_time": 0.47273
},
]Returns website availability (SLA) data.
Query parameters:
nodename: hostname to match the nodeurl: monitored website URL
Sample response:
{
"availability": 99.97
}To run the project in the background and start it on system boot:
- Copy the service file:
sudo cp grafana-betterstack.service /etc/systemd/system/grafana-betterstack.service- Reload systemd and start the service:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable grafana-betterstack
sudo systemctl start grafana-betterstack- Check status and logs:
sudo systemctl status grafana-betterstack- On service failure check the journal logs:
journalctl -u grafana-betterstack -n 50 --no-pagerEnsure that your virtual environment and script paths are correctly set in the service file.
The server uses the UPTIME_REST_API_Client class to interact with BetterStack's API:
- Fetch monitor ID by URL
- Retrieve response time history
- Retrieve SLA/availability metrics
The Flask app exposes data as Grafana-friendly JSON endpoints.