Adding Prometheus as a Data Source to Grafana

Posted on Tuesday, February 2, 2021


 


I recently wrote a few article on installing Grafana and Prometheus.

http://www.whiteboardcoder.com/2021/01/installing-grafana-on-ubuntu-2004.html [1]
http://www.whiteboardcoder.com/2021/01/installing-prometheus-on-ubuntu-2004.html [2]

Now that I have it set up and I have prometheus ingesting some data I want to hook it into Promtheus and see some beautiful graphs 

Now I want to start getting some real data into it to have something to graph! 

 

 

 

Adding a Data Source

 

I have Prometheus and Grafana running on the same box.
Let me ssh into my box and also pull some ports on the way.

 

  > ssh prometheus -L 3000:localhost:3000 -L 9090:localhost:9090 -L 9100:localhost:9100

 


Now check if prometheus and grafana are running.

 

  > sudo systemctl status grafana-server

 




And Prometheus

 

  > sudo systemctl status prometheus

 

 

OK all looks good.
Now let me open up Grafana.
http://localhost:3000/login

 

 

Click on Configuration and select Data Sources.


Click Add data sources


Click on Select in the Prometheus


Set URL to http://localhost:9090

All other settings leave as is since I have no SSL or anything fancy set up in front of prometheus.

 


Click on Save & Test



Wahoo its working!



Now go back to Data Sources
Now we should see that we have Promtheus as a data source.


 

Testing data

First let me prove I have some node exporter data in prometheus.
Head over to http://localhost:9090/graph


 

 Click on Graph

 Enter node_cpu_seconds_total and click Execute.



 Yeah data

Now back to grafana

 


Click on + and select Dashboard


Click Add New Panel
Enter the query

 

(100 - 100*(avg by (node) (irate(node_cpu_seconds_total{mode="idle"}[15m]))))

 

 


 

Then hit apply



On the right scroll down to Axes and set the Y-Min to 0 and Y-Max to 100 and click Apply


As you can see nothing much is going on my CPU is not taxed
On my computer let me run htop to confirm (if you don’t have htop install it with sudo apt-get install htop

 

  > htop

 

 


Now let’s do something to get our CPU to max out or at least jump up a bit.

Let me install and run stress

 

  > sudo apt-get install stress
   > stress --cpu 2

 

 


 

Wow



 

Run just one cpu

 

 

  > stress --cpu 1

 

 



 

References

 

[1]        Installing Grafana on Ubuntu 20.04

http://www.whiteboardcoder.com/2021/01/installing-grafana-on-ubuntu-2004.html
Accessed 2/2020

[2]        Installing Prometheus on Ubuntu 20.04

http://www.whiteboardcoder.com/2021/01/installing-prometheus-on-ubuntu-2004.html
Accessed 2/2020

 

 

No comments:

Post a Comment