Sobes.tech
Senior

Prometheus — what is it, how is it used, how does it work, how does it collect metrics, what are the main types of metrics?

sobes.tech AI

Answer from AI

Prometheus is an open-source monitoring and alerting system focused on collecting and storing metrics in a time-series format.

How it works:

  • Prometheus periodically scrapes HTTP endpoints that expose metrics in a specific format.
  • Metrics are collected as key-value pairs with timestamps.
  • Data is stored in a local time-series database with scalability options.

How it collects metrics:

  • Applications or services expose metrics via HTTP in Prometheus exposition format.
  • Prometheus makes scheduled HTTP requests to these endpoints and collects data.

Main types of metrics:

  • Counter — a monotonically increasing counter (e.g., number of requests).
  • Gauge — a value that can go up or down (e.g., current CPU load).
  • Histogram — distribution of values over intervals (e.g., response time).
  • Summary — similar to Histogram but with quantiles.

Example in C#:

using Prometheus;

var counter = Metrics.CreateCounter("myapp_requests_total", "Total number of requests.");

// In request handler
counter.Inc();

Then Prometheus will collect the myapp_requests_total metric from your application.

In commercial projects, Prometheus is often used for monitoring performance, service availability, and user behavior analysis.

Prometheus — what is it, how is it used, how does it… - sobes.tech