Prometheus + Grafana Setup To Visualize Your Servers — 2020

Setting up Prometheus, Node Exporter and Grafana to get graphical visualization of server metrics.

Vinesh
Vinesh
Sep 18, 2020 · 5 min read
Image for post
Image for post

Prometheus Introduction

There are many client libraries available to allow easy instrumentation of services, custom libraries can also be created with ease. Each server is independent for reliability, relying only on local storage. Written in Golang programming language, all binaries are statically linked and easy to deploy.

Prometheus implements the pull policy and not push policy i.e., the prometheus scrapes data from its exporters at definite time intervals rather than them pushing to prometheus, this implementation has its own pros and cons but let’s not get into those details.

Grafana Introduction

Grafana also provides alerting, define thresholds visually, and get notified via Slack, PagerDuty and other platforms. Grafana also provides a wide variety of options to view our data, from heat-maps to histograms and graphs to geo-maps. Grafana has a plethora of visualization options to help you understand your data, beautifully. I am using Ubuntu 18.04 and will be showing the entire setup with respect to that itself.

Prometheus Setup

Image for post
Image for post
Prometheus Installation
wget https://github.com/prometheus/prometheus/releases/download/v2.21.0/prometheus-2.21.0.linux-amd64.tar.gztar -xzf prometheus-2.21.0.linux-amd64.tar.gzcd prometheus-2.21.0.linux-amd64/./prometheus

The installation is pretty straight-forward, running these commands would result in Prometheus server running in port 9090. The dashboard of prometheus on port 9090 would look something like this:

Image for post
Image for post
Prometheus dashboard

The metrics scraped from prometheus happens at constant time periods as mentioned before, so they can be viewed in path /metrics

Image for post
Image for post
Prometheus scraped metrics
Image for post
Image for post
Graph visualization of query in prometheus dashboard

These metrics are used to form complex expressions with various aggregate functions to visualize in the form we desire, this is basically possible with the help of promql. The graph visualization in prometheus is very primitive and doesn’t give much customization so we’ll be using Grafana.

Node Exporter Setup

Image for post
Image for post
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gztar -xzf node_exporter-1.0.1.linux-amd64.tar.gzcd node_exporter-1.0.1.linux-amd64/./node_exporter

The above commands will install the node exporter and runs on port 9100, and the metrics can be scraped from/metrics extension.

I have created 3 virtual machines and installed node exporters in all of them to give better visualization. So after installation, we have to tell prometheus from where to scrape the metrics, which can be done by editing the prometheus.yml file. We just add a new job in the scrape_configs specifying the IP address and port in targets. Once we add the targets in the prometheus.yml file and restart the prometheus server, we can see the new targets and their status in the dashboard as well in the /targets path.

Image for post
Image for post
prometheus.yml
Image for post
Image for post
Prometheus targets

Make sure all the targets are UP, if not check if the 9100 port is exposed for that VM instance. You can also view how much time prometheus took to scrape from each exporter and when it was last scraped.

Grafana Setup

Image for post
Image for post
wget https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gztar -xzf grafana-7.1.5.linux-amd64.tar.gzcd grafana-7.1.5.linux-amd64/./bin/grafana-server

The installation will be done by running the above commands and grafana is hosted on port 3000. The default username and password both are “admin”.

Once we enter the dashboard, we have to add a data source which is Prometheus in our case. We just have to give the prometheus URL and hit the Save & Test button. If we get a success toaster saying data source is working then we are good to go.

Image for post
Image for post
Add Prometheus data source

We can create our own dashboards and panels with customized queries, but it is a tedious task. So to make our work simple there are already dashboards created by other users. We can use the same and tweak the expressions based on our desire. I am using 1860 and 405, these are the unique ids we give to import the dashboards.

Image for post
Image for post
Image for post
Image for post
Import Grafana Dashboard

Once the import is complete, we see the graphs based on their expressions and time frame. You can drill down by reducing the time frame to 5 mins.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Grafana also allows us to view a consolidated form of combining multiple exporters placed side-by-side which gives a better picture for comparison purposes.

Image for post
Image for post
Image for post
Image for post
Consolidated view of multiple exporters

So in the above images we can see that data is being visualized from all three node exporters.

This sums up the basic setup of Prometheus and Grafana to visualize your node metrics. If you find it helpful, please drop some claps and feel free to share it. This is Vinesh signing-off. Byeee 😋

Javarevisited

Medium’s largest Java publication, followed by 8500+ programmers. Follow to join our community.

Vinesh

Written by

Vinesh

Coder 👨‍💻, Gamer🎮 and a dog person🐶. That says a lot about me, I guess😛.

Javarevisited

A humble place to learn Java and Programming better.

Vinesh

Written by

Vinesh

Coder 👨‍💻, Gamer🎮 and a dog person🐶. That says a lot about me, I guess😛.

Javarevisited

A humble place to learn Java and Programming better.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store