open-o11y / prometheus-sample-app

A sample app that generates Prometheus metrics
10 stars 6 forks source link

prometheus-sample-app

This Prometheus sample app generates all 4 Prometheus metric types (counter, gauge, histogram, summary) and exposes them at the /metrics endpoint

A health check endpoint also exists at /

The following is a list of optional command line flags for configuration:

Steps for running locally:

$ go build .
$ ./prometheus-sample-app -listen_address=0.0.0.0:4567 -metric_count=100

Steps for running in docker:

$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080
$ curl localhost:8080/metrics

Note that the port in LISTEN_ADDRESS must match the the second port specified in the port-forward

More functioning examples:

$ docker build . -t prometheus-sample-app
$ docker run -it -p 9001:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080
$ curl localhost:9001/metrics
$ docker build . -t prometheus-sample-app
$ docker run -it -p 9001:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 -metric_count=100
$ curl localhost:9001/metrics

Running the commands above will require a config file for setting defaults. The config file is provided in this application. To modify it just change the values. To override config file defaults you can specify your arguments via command line

Usage of generate:

-is_random

    Metrics specification

-metric_count int

    Amount of metrics to create

-metric_frequency int

    Refresh interval in seconds 

-metric_type string

    Type of metric (counter, gauge, histogram, summary) 

-label_count int

    Amount of labels to create per metric

-datapoint_count int

    Number of datapoints to create per metric

Example:

$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 generate -metric_type=summary -metric_count=30 -metric_frequency=10
$ curl localhost:8080/metrics
$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 generate -metric_type=all -is_random=true
$ curl localhost:8080/metrics

Clustering:

Deploy the example deployment configuration of 5 instances of Prometheus-Sample-App along with configured OTEL Collector.

Pre-requisites:

Deployment on Minikube:

Currently, OTEL Collector is configured with Logging exporter. In this example, all replica Prometheus-Sample-App pods will produce identical metrics, and the Prometheus Exporter doesn't ingest identical metrics (same name and label) from different sources.