Grafana: Connect Grafana to Prometheus
Grafana shows nothing until it knows where the numbers live. This lesson connects Grafana to Prometheus as its data source.
The data source settings
Name it clearly and point it at the Prometheus server address.
Name: Prometheus
Type: Prometheus
URL: http://127.0.0.1:9090Test the connection
Save and test asks Prometheus a test question and reports the result.
Click: Save & test
Result: Successfully queried the Prometheus API.First query in Grafana
A new panel with the query up draws one line per target, all at 1.
upExample
curl -s -u admin:admin http://127.0.0.1:13101/api/datasources/uid/eg40xsep4od1ca/healthKey points
- A data source is a connection from Grafana to a place that holds numbers.
- Prometheus is the data source for this course, and Grafana asks it questions in PromQL.
- Add a data source in Grafana under Connections, then Data sources, then Add data source.
- Choose Prometheus as the type and enter the Prometheus address as the URL.
- The Save and test button asks Prometheus a test question and reports success or failure.
- Once the test passes, any panel can query Prometheus and draw the answer.
In this example, Grafana checks the Prometheus data source through its own API, the same check the Save and test button runs. The status is OK and the message says it successfully queried the Prometheus API. A query for up run through Grafana then returned real series for all three targets, so the two halves of the stack are joined. The long id in the address is the data source id Grafana assigned in this lab, so the id on your machine will be a different one.
Note
One Grafana can hold many data sources, but this course needs only one.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does the Save and test button check when you add a Prometheus data source?