Monitoring With Prometheus

Reugadevi Anbarasan
4 min readApr 30, 2021

Monitoring is important in DevOps practices for any successful company. It helps companies to get better understanding of the underlying systems. Prometheus is an open source tool for monitoring and alerting. It’s multi-dimensional data model and flexible query language is the key power in a world of microservices.

Prometheus is not based on push model. It uses pull method to scrape out metrics from the target instance over http and store the data in time series database. Prometheus comes with several exporters to install on the target instance for wide range of metrics. We will use Node exporter in this tutorial for hardware and kernel related metrics. There are many exporters provided by Prometheus as well as third party exporters to suit the business needs. You can find all the supported exporters on their official documentation

How to setup Prometheus and Node Exporter

Get the latest Prometheus and Node Exporter here based on the needed platform and simply extract it. Install Prometheus only on the server machine.

tar xvf prometheus-*.tar.gzcd prometheus-*

As the next step, install Node Exporter on server where Prometheus is running if you want to monitor the server itself. If you want to monitor additional services, install the node exporters on all the machines where the services are running. In this tutorial, we will monitor only prometheus and the server where it is installed. Prometheus server will scrape the metrics from the running Node Exporters. Run the following commands on the prometheus server machine to run the node exporter:

tar xvfz node_exporter-*.*-amd64.tar.gzcd node_exporter-*.*-amd64./node_exporter

How to configure Prometheus

After installing Prometheus, we need to configure about which HTTP endpoints Prometheus should monitor. Prometheus configuration is based on YAML. When you download and extract Prometheus, you can find prometheus.yml with a simple configuration.

global:
scrape_interval: 10s
evaluation_interval: 10s
scrape_configs:
- job_name: ‘prometheus’
static_configs:
— targets: [‘localhost:9090’]
- job_name: ‘node_exporter’
static_configs:
— targets: [‘localhost:9100']

Here we have configured 2 jobs to scrape metrics from both Prometheus and the node exporter. You can start Prometheus by using the config file we created above

./prometheus --config.file=./prometheus.yml

By default, Prometheus comes with a basic UI for running queries. You can find it by visiting http://localhost:9090/

Prometheus comes with an Alert Manager which is a separate component. You can use it to integrate with third party notification systems such as Email, WebHook, Slack etc. You can also install Prometheus using Docker. Please check out their official docker image.

Prometheus role in DevOps

A monitoring solution should be simple to deploy, easy to maintain and have high-value ROI. This is what every DevOps professional expects when choosing a monitoring solution. Prometheus meets all these expectations. Prometheus integrates well with many tools to make it more reliable and effective. For example, when integrating Prometheus with Grafana (visualize the data from Prometheus database to identify issues faster), we obtain an outstanding data visualization. Both the tools accompany each other with their services and provide a robust time-series database.

You can get Grafana out of the box using docker image. Just run the following command to spin up Grafana. For detailed installation instructions, check their installation guide

docker run -d --name=grafana -p 3000:3000 grafana/grafana

By default, you can find Grafana up and running at http://localhost:3000. Choose Prometheus on Add datasource.

We have created a simple dashboard monitoring the Memory, CPU, Request and Responses. You need to add PromQL query to get the metrics.

Many companies have adopted Prometheus because of its operational ease. Prometheus is also a great monitoring for containers and microservices. Prometheus can be deployed in Kubernetes(Container orchestration) which in turn can monitor the entire Kubernetes cluster as well as the applications deployed in the cluster. This versatility of the tool allows the user to tailor it according to their requirements.

Conclusion

In this tutorial, we covered the overview of Prometheus, its installation and configuration and why it is important in DevOps practices. Prometheus is a great tool that is gaining lots of attraction among DevOps professionals mostly because of its ease of use and flexibility.

--

--