Prometheus is a powerful monitoring system that collects and processes numerical data (metrics) from applications. It helps you track key indicators such as:
\
\ By using Prometheus, you can answer critical questions like:
"Is my service running efficiently?"
"What are the performance bottlenecks?"
"Do we need to scale up our infrastructure?"
\
And how does Prometheus Collect Metrics?
There are two primary ways Prometheus gathers data:
\ Let’s break them down.
Pull ModelIn the pull model, Prometheus actively fetches metrics from your application via HTTP (e.g., http://your-service:8080/metrics).
This is the default and most commonly used method.
Setting up Prometheus with Golang (Pull Model)\
\
\
\ Now, Prometheus will automatically query http://localhost:8080/metrics every few seconds to collect data.
Why is the Pull Model Preferred?\
Push Model (Pushgateway Approach)\ In the push model, a service sends its metrics to an intermediary service called Pushgateway, which stores them until Prometheus fetches them.
How it Works (Push Model)\
\ Which Model Should You Use?
| Method | Best for… | Pros | Cons | |----|----|----|----| | Pull (Recommended) | Web services, APIs, long-running applications | Simple setup, fewer dependencies, automatic cleanup | Not suitable for very short-lived tasks | | Push (Pushgateway) | Batch jobs, tasks without stable network access | Allows pushing data from short-lived jobs | Stale data, extra complexity, risk of bottlenecks |
Why Push Model is Not Ideal?Although Pushgateway solves some problems (e.g., short-lived processes that terminate before Prometheus scrapes them), it introduces several new issues:
\
If a service dies, its old metrics remain in Pushgateway.
Prometheus has no way of knowing if the service is still running.
You must manually delete outdated metrics using push.Delete(...) or configure expiry policies.
\
Instead of a direct Service → Prometheus link, you now have Service → Pushgateway → Prometheus.
Pushgateway is an extra dependency, increasing maintenance overhead.
\
If many services push metrics frequently, Pushgateway can become overwhelmed.
Unlike direct Prometheus scrapes (which distribute the load), all requests hit a single Pushgateway instance.
\
\
ConclusionPrometheus is a powerful and reliable tool for monitoring services. For most applications, the pull model is the best choice—it's simple, efficient, and ensures fresh data without additional complexity. However, if you're working with short-lived processes like Lambda functions or batch jobs, the push model via Pushgateway can be useful to capture metrics before the process exits.
\ Choosing the right approach ensures better observability and maintainability of your system.
\ Take care!
All Rights Reserved. Copyright 2025, Central Coast Communications, Inc.