Setting Up A Comprehensive Monitoring System With Prometheus

What is Prometheus?

│ └── meta.json
│ ├── chunks
│ │ └── 000001
│ ├── tombstones
│ ├── index
│ └── meta.json
│ └── meta.json
├── 01BKGV7JC0RY8A864HCE24HD09
│ ├── chunks
│ │ └── 000001
│ ├── tombstones
│ ├── index
│ └── meta.json
└── wal
├── 00000002
└── checkpoint.000001

Different metrics in Prometheus

  • Counter - A cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart
  • Gauge - A metric that represents a single numerical value that can arbitrarily go up and down.
  • Histogram - A histogram samples observations (usually things like request duration or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.
  • Summary - This metric samples observations (usually things like request duration and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.

Steps to Integrate your application with Prometheus.

<! — Actuator dependency →
<! — Prometheus dependency →
include : health,prometheus
base-path: /monitor
enabled-by-default: true
Prometheus default metrics created for your application
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: ‘your_service’
scrape_interval: ‘10s’
metrics_path: ‘/monitor/prometheus’
— targets: [‘localhost:8090’]
Your service connectivity with Prometheus
Your service availability metric in Prometheus

Custom Metrics for your application

  • First you need to create a metrics manager to your application. All your custom metrics will be implemented inside this class.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;

public class MetricsManager {

private static final String METRIC_TAG = "filter";

private MeterRegistry meterRegistry;

public MetricsManager(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;

public void initMetricsCounter(String filterTag) {
Counter counter;
counter= this.meterRegistry.counter("api.request.", METRIC_TAG, filterTag );
  • Now you can use your metrics manager to instantiate and generate values for your metrics.
public class RequestProcessor {

MetricsManager metricsManager;

public void process(Exchange exchange) throws Exception {
Your custom metric in Prometheus server
Your custom metric in Prometheus dashboard



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store