Metrics → Prometheus→ Grafana

Shehan Akalanka Perera
3 min readMar 16, 2018

--

We use Metrics to get an idea runtime behavior of our products. This is very important for make customer happy and also give a fight for competitors. But if we get just a metrics its lots of numbers, many people will not get any idea from this. So we can make a Dashboards for visualizing metrics. We can use Grafana Dashboard for this. Its make a quality image of metrics and we can write quires to get important information from metrics that everyone can understand. This is a simple example that can get an idea about how to use Metrics and visualize them in Grafana dashboard.

Step 1 Get Metrics for Netty-echo-server

  • Download Netty-echo-server with metrics
git clone https://github.com/ShehanPerera/Metrics-Prometheus-Grafana.git
  • Install the package
mvn clean install
  • Go to target and run netty-echo-server
java -jar netty-echo-server-1.0-SNAPSHOT.jar
  • Send a request and get output
curl -v -d {“Request”} http://localhost:9091

Step 2 Use Prometheus

  • We can download Prometheus and extract it.
tar xvfz Prometheus-*.tar.gz
  • Go to the directory
cd prometheus-*
  • Start Prometheus
./prometheus — config.file=prometheus.yml

(we have to change this file to use)

  • We can see details in the browser
http://localhost:9090/graph
  • We can get default metrics in the browser
http://localhost:9090/metrics

Step 3 Use Grafana

  • Download Grafana and we can extract it.
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.0.linux-x64.tar.gztar -zxvf grafana-5.0.0.linux-x64.tar.gz
  • Go to the directory
cd grafana-5.0.0/bin/
  • Run Grafana
./grafana-server web
  • We can see dashboards on the following link
http://localhost:3000 (use admin/admin for username/password)

Step 4 Export metrics to Prometheus and Grafana

In MetricsServer we have Prometheus reporter. From this, we can get metrics using http://localhost:9092/metrics as follows

To get this from Grafana we have to config Grafana and Prometheus

Config Prometheus

Open prometheus.yml file in Prometheus directory and change its Job as follows and run Prometheus.

scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: ‘netty-echo-server’# metrics_path defaults to ‘/metrics’# scheme defaults to ‘http’.static_configs:- targets: [‘localhost:9092’]

Config Grafana

In Grafana first, we need to add the data source.

Configuration → Data Sources → Add data source

In this set data source as follows.

Name: Prometheus

Type: Prometheus

URL: http://localhost:9090

Access: proxy

Scrape interval:10s(your wish)

After that, we can save data source.

Step 5. Visualize metrics in Grafana Dashboard

Let’s create a new graph for our Time_To_Response metrics.

  • Use ‘+’ and go to graph tab
  • Click panel title and go to the edit
  • In the query area type Time_To_Response and enter
  • By clicking ‘eye’ icon we can get the Timer that we use in our Netty-echo-server.
  • We can change panel name using ‘General’ tab

After that we can get Metrics dashboard as follows we can do this for Request_Size by getting duplicate of panel

Time_To_Response
Request_Size

Import dashboards to Grafana

  • Download Netty-echo-server-Metrics dashboard from Grafana/dashboards
  • Click ‘+’ mark and goto import and upload netty-echo-server-metrics_rev1.json and Give Prometheus data base and click Import.
  • Then you can get dashboards as follows.
Netty-echo-server-Metrics

--

--