Introduction , Architecture and Installation of Prometheus Server

Introduction , Architecture and Installation of Prometheus Server

📍 Introduction:

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open-source project and is maintained independently of any company.

Prometheus collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.

Prometheus components are written in Go.

Uses a 'multi-dimensional' data model with 'time series data' identified by 'metric name' and 'key/value pairs'.

🔹Features of Prometheus

  • PromQL is a 'read-only and flexible query language that allows aggregation across any of the labels stored in its time series.

  • No reliance on distributed storage; single server nodes are autonomous.

  • Default libraries and servers are available for Prometheus - Windows, Linux, machine, MySQL etc.

  • To monitor custom services, you can add instrumentation to your code via Prometheus client libraries like Go, Java or Scala, Python, Ruby and many more.

  • Full-fledged monitoring system with its alert manager.

📍 Architecture :

🔹Prometheus Server

The server is the brain of any web or mobile application. The Prometheus server does the same for Prometheus services or clusters. It collects multi-dimensional data in time series and then analyzes and aggregates the collected data. The process of collecting metrics is called scraping.

🔹Prometheus Gateway

The Prometheus server alone would not scrape all kinds of metrics; some require extra mechanics. Prometheus Gateway is the intermediary source used for metrics from those jobs which can not be scraped by usual methods. There are certain drawbacks to using Prometheus Gateway blindly:

🔹Alert Manager

Alertmanager is responsible for managing the alerts sent by the clients. It checks for supplication, groups the signals, and routes them to the correct application like email, Pagerduty, Opsgenie, etc. It also checks for when it should keep alerts off and when not.

You can do various things with Alerts received from a client (Prometheus Server) to the Alertmanager. You can group similar types of notifications that prevent you from seeing similar notifications repetitively. You can mute notifications as well.

🔹Prometheus Targets

Prometheus targets represent how Prometheus extracts metrics from a different resource. In many cases, the metrics are exposed by the services themselves, such as Kubernetes. In this case, Prometheus collects metrics directly. But in some instances, like in unexposed services, Prometheus has to use exporters. Exporters are some programs that extract data from a service and then convert them into Prometheus formats

🔹Prometheus Exporters

Prometheus needs to scrape metrics. Exporters are third-party tools that help scrape metrics when it is not feasible to extract metrics directly. Some exporters are official, while others are not officially declared in the Prometheus Github organization.

Prometheus exporters can go into various categories such as database exporters, hardware-related, issue trackers, storage, HTTP, APIs, logging, miscellaneous alert managers, and other official Prometheus exporters. Database exporters include Aerospike, Cickhouse, Couchbase, CouchDB, Druid, Elastic Search, etc. Hardware-related exporters include Accuse, Big-IP, Collins, Dell Hardware, etc. Other than that, various third-party software like Ansible Tower, Caddy, CRG, Doorman, Etcd, Kubernetes, Midonet-Kubernetes, Xandikos, etc.

🔹Service Discovery

In the Prometheus Targets section, we discussed using static-config files to configure the dependencies manually. This process is ok when you have simple uses with the config file, but what if you have to do this in a large amount? Especially when some instances are added or removed every single minute?

This is where service discovery comes into play. Service discovery helps in providing Prometheus the information of what to escape in whichever database you want. Prometheus’ common service discovery resources are Consul, Amazon’s EC2, and Kubernetes out of the box.

🔹Prometheus Data Visualization

Prometheus collects measurements and stores them locally in a time series database. A user can pick and aggregate existing time-series data in real time using the Prometheus Query Language (PromQL). Prometheus Expression Browser can display the result as graphs or tabular data, or the data can feed an external visualization integration via an HTTP API. Grafana is the external integration of choice for Prometheus visualization.

A time series can be identified by a data model by its name and by an unordered set of key-value pairs known as labels. The PromQL query language supports aggregation across any of these labels, allowing you to look at data not just by process, but also by data center, service, and any other labels you've set up.

🔹Prometheus Gateway

Pushgateway in Prometheus is a gateway that allows ephemeral and batch jobs to push their metrics to Prometheus. Normally, Prometheus scrapes metrics from targets, but in some cases, the target itself is short-lived and cannot be scraped. In these cases, the Pushgateway can be used to collect metrics from the job and expose them to Prometheus.

Pushgateway provides an HTTP endpoint where jobs can push their metrics using the Prometheus data model. The endpoint accepts POST requests with the metrics data encoded in a text format or in Protocol Buffers format. The metrics are then stored in an internal database and made available to Prometheus for scraping.

📍 Installation :

To install the Prometheus server on a server, you need to follow these general steps:

  • Download the latest version of Prometheus from the official website: prometheus.io/download

  • Extract the downloaded file to a directory of your choice, such as /opt/prometheus:

  •       tar xvfz prometheus-*.tar.gz
          mv prometheus-* /opt/prometheus
    
  • Create a Prometheus configuration file, usually named prometheus.yml, in the /opt/prometheus directory. You can use the default configuration file as a starting point and modify it to suit your needs:

  •       cd /opt/prometheus
          vi prometheus.yml
    
  • Start the Prometheus server by running the Prometheus executable:

  •       ./prometheus
    
  • Verify that Prometheus is running by accessing its web interface at localhost:9090. You should see the Prometheus expression browser, which allows you to query and visualize the metrics that Prometheus is collecting.

  • Configure Prometheus to scrape metrics from your applications or services. This involves adding scraping targets to the prometheus.yml configuration file. You can find more information about this in the official Prometheus documentation: prometheus.io/docs/prometheus/latest/gettin..

  • Install and configure a dashboard or visualization tool, such as Grafana, to display and analyze the metrics collected by Prometheus.