Skip to content

ManiAm/grafana-betterstack-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BetterStack REST Proxy for Grafana

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.


Features

  • 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

Getting Started

Prerequisites

Install Dependencies

pip install flask flask-compress requests

Set Environment Variable

export BetterStack_API_TOKEN=your_betterstack_token

Run the Server

python3 grafana_server.py

The server will be available at http://<your_host>:5006


Available Endpoints

GET /response_time

Returns response time data per region.

Query parameters:

  • nodename: hostname to match the node
  • url: monitored website URL
  • region: comma-separated list of regions (default: us,eu,as,au)

Sample response:

[
  {
    "timestamp": 1744539757000,
    "region": "us",
    "response_time": 0.47273
  },
]

GET /sla

Returns website availability (SLA) data.

Query parameters:

  • nodename: hostname to match the node
  • url: monitored website URL

Sample response:

{
  "availability": 99.97
}

Run as a systemd Service

To run the project in the background and start it on system boot:

  1. Copy the service file:
sudo cp grafana-betterstack.service /etc/systemd/system/grafana-betterstack.service
  1. Reload systemd and start the service:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable grafana-betterstack
sudo systemctl start grafana-betterstack
  1. Check status and logs:
sudo systemctl status grafana-betterstack
  1. On service failure check the journal logs:
journalctl -u grafana-betterstack -n 50 --no-pager

Ensure that your virtual environment and script paths are correctly set in the service file.


Architecture

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.

About

A lightweight REST API proxy that connects BetterStack monitoring data to Grafana using JSON endpoints compatible with the Infinity plugin.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages