Prometheus Collector Registry (original) (raw)

Last Updated : 30 Apr, 2026

Prometheus has emerged as a cornerstone in monitoring and alerting for modern cloud-native applications and is the preferred choice for developers and operations teams due to its capabilities and ecosystem.

Features of Prometheus

**1. Time Series Database

time_series_database

Time Series Database

2. The Pull Model

**Mechanism: Prometheus uses the pull model by scraping metrics from endpoints exposed through the monitored targets. Each target has a metrics endpoint (e.g., /metrics) that is queried by Prometheus at periods specified.

**Advantages:

**Target Configuration: Prometheus configuration file specifies targets under scrape_configs section. Each target has parameters like job_name, scrape_interval and static_configs or service_discovery_configs.

prometheus

Prometheus target configuration

3. PromQL

**Purpose: Use of PromQL to request and analyze time series data stored in Prometheus enabling selection and aggregation.

**Features:

**Examples:

prometheus_query_language_promql_

Prom QL

Prometheus Client Libraries

**Role: Client libraries allow applications to serve internal metrics in a way that can be scraped by Prometheus.

**Features:

**Example (Go):

package main

import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "net/http" )

var ( requestsTotal = prometheus.NewCounter(prometheus.CounterOpts{ Name: "http_requests_total", Help: "Total number of HTTP requests.", }) requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "http_request_duration_seconds", Help: "Duration of HTTP requests in seconds.", Buckets: prometheus.DefBuckets, }) )

func init() { prometheus.MustRegister(requestsTotal) prometheus.MustRegister(requestDuration) }

func handler(w http.ResponseWriter, r *http.Request) { timer := prometheus.NewTimer(requestDuration) defer timer.ObserveDuration()

requestsTotal.Inc()
w.Write([]byte("Hello, World!"))

}

func main() { http.Handle("/metrics", promhttp.Handler()) http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }

Collector Registry

**Definition: The collector registry is the central location of all collectors and metrics in an application.

**Usage:

**Example (Go):

var customRegistry = prometheus.NewRegistry() customRegistry.MustRegister(customMetric) http.Handle("/metrics", promhttp.HandlerFor(customRegistry, promhttp.HandlerOpts{}))

Collectors and Metric Types

collectors_and_metric_types

Collectors and Metrics Types

1. Counters:

**Example (Go):

var errors = prometheus.NewCounter(prometheus.CounterOpts{ Name: "errors_total", Help: "Total number of errors.", })

**2. Gauges:

**Example (Go):

var temperature = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "current_temperature", Help: "Current temperature in Celsius.", }) temperature.Set(25.5)

3. Histograms:

**Example (Go):

var requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "http_request_duration_seconds", Help: "Request duration in seconds.", Buckets: prometheus.DefBuckets, })

4. Summaries:

**Example (Go):

var requestLatencies = prometheus.NewSummary(prometheus.SummaryOpts{ Name: "request_latencies_seconds", Help: "Request latency in seconds.", Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, })

Prometheus Collector Registry Demo

Step 1: Setting Up Prometheus

Screenshot of Prometheus Download Page

Prometheus

**Extract Prometheus

**Note: All these commands are being run on Powershell. Users can also go for GitBash, Command Line Terminal.

tar -xvf prometheus-2.31.1.windows-amd64.tar.gz

After running the above command, extracted files

Prometheus

Navigate to the Extracted Directory

cd $HOME\Downloads\prometheus-2.31.1.windows-amd64

Run Prometheus with default settings

.\prometheus.exe --config.file=prometheus.yml

Access Prometheus Web Interface

Open your web browser and go to http://localhost:9090.

Prometheus Interface

Prometheus

Prometheus will start running on http://localhost:9090\.

Step 2: Installation Guide: Node Exporter

Node Exporter download page, download the Node Exporter binary.

Node Exporter Download Page

Prometheus

To collect system metrics, extract and run the Node Exporter.

tar -xvf node_exporter-*.tar.gz

cd node_exporter-*

**Running Node Exporter

./node_exporter

Node Exporter will run on http://localhost:9100/metrics.

Best Practices

1. Maintain Uniform Naming

**Standard: Adopt snake_case concerning metric denominations and labels. This augments readability and uniformity among various metrics.

**Illustrations:

2. Exploit Labels

**Example (Go):

http_requests_total{method="GET", status_code="200"}

3. Monitor Performance

**Commence: Undertake regular supervision of the Prometheus server's operational performance and the consumption of resources.

**Metrics to Observe:

**Alert Mechanisms: Implement alert systems for essential performance metrics to facilitate prompt reactions to emergent issues.

4. Constrain Metric Volume

5. Utilize Aggregations:

**Objective: The reduction of stored metrics volume is facilitated by the aggregation of data, which aids in concentrating on elevated insights.

**Example (promql):

Examples and Use Cases

1. Infrastructure Monitoring

**Metrics:

2. Application Monitoring

**Metrics:

3. Alerting

**Example Configuration (yaml file):

groups:

4. Capacity Planning