A Python-based chatbot that connects to Grafana for searching graphs and KPIs, with customizable time ranges.
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure Grafana Connection:
- Open
.env
file - Set your Grafana server URL (default: http://localhost:3000)
- Add your Grafana API key
To generate a Grafana API key:
- Log into your Grafana instance
- Go to Configuration > API Keys
- Create a new API key with "Admin" role
- Copy the generated key to
.env
file
- Open
-
Start the server:
python main.py
GET /
: Health check endpointPOST /search
: Search for graphs and KPIs- Parameters:
query
: Search termtime_from
: Start time (optional, default: now-6h)time_to
: End time (optional, default: now)
- Parameters:
GET /render/{dashboard_uid}/{panel_id}
: Render panel image- Parameters:
dashboard_uid
: Dashboard UIDpanel_id
: Panel IDtime_from
: Start time (optional)time_to
: End time (optional)
- Parameters:
Supported time range formats:
- Relative:
now-6h
,now-1d
,now-1w
- Absolute:
2023-01-01
,2023-01-01 13:00:00
-
Search for CPU metrics:
curl -X POST "http://localhost:8000/search" \ -F "query=CPU" \ -F "time_from=now-1h" \ -F "time_to=now"
-
Render a specific panel:
curl "http://localhost:8000/render/{dashboard_uid}/{panel_id}?time_from=now-1h&time_to=now"