• Stars
    star
    135
  • Rank 268,632 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go app that exposes metrics about its HTTP handlers.

Prometheus Example App

This example app serves as an example of how one can easily instrument HTTP handlers with Prometheus metrics. It uses the Prometheus go client to create a new Prometheus registry.

Usage is simple, on any request to / the request will result in a 200 response code. This increments the counter for this response code. Similarly the /err endpoint will result in a 404 response code, therefore increments that respective counter. Duration metrics are also exposed for any request to /.

A Docker image is available at: quay.io/brancz/prometheus-example-app:v0.3.0

Deploying in a Kubernetes cluster

First, deploy one instance of this example application, which listens and exposes metrics on port 8080 using the following Deployment manifest.

Then, in order for Prometheus to be able to discover and scrape these metrics, in this repository we provide Pod Monitor custom resource as an example. For that, Prometheus Operator needs to be running in the cluster. To install it, follow this guide: quickstart.

For this example application, PodMonitor manifest describes how the metrics can be discovered and scrapped by Prometheus.

Exposed Prometheus metrics

The following metrics are exposed:

  • version - of type gauge - containing the app version - as a constant metric value 1 and label version, representing this app version
  • http_requests_total - of type counter - representing the total numbere of incoming HTTP requests
  • http_request_duration_seconds - of type histogram, representing duration of all HTTP requests
  • http_request_duration_seconds_count- total count of all incoming HTTP requeests
  • http_request_duration_seconds_sum - total duration in seconds of all incoming HTTP requests
  • http_request_duration_seconds_bucket - a histogram representation of the duration of the incoming HTTP requests

The sample output of the /metric endpoint after 5 incoming HTTP requests shown below.

Note: with no initial incoming request, only version metric is reported.

# HELP http_request_duration_seconds Duration of all HTTP requests
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.005"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.01"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.025"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.05"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.1"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.25"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="0.5"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="1"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="2.5"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="5"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="10"} 5
http_request_duration_seconds_bucket{code="200",handler="found",method="get",le="+Inf"} 5
http_request_duration_seconds_sum{code="200",handler="found",method="get"} 0.00047495999999999997
http_request_duration_seconds_count{code="200",handler="found",method="get"} 5
# HELP http_requests_total Count of all HTTP requests
# TYPE http_requests_total counter
http_requests_total{code="200",method="get"} 5
# HELP version Version information about this binary
# TYPE version gauge
version{version="v0.3.0"} 1

More Repositories

1

kube-rbac-proxy

Kubernetes RBAC authorizing HTTP proxy for a single upstream.
Go
581
star
2

kubernetes-grafana

The future of Grafana on Kubernetes with Prometheus.
Jsonnet
234
star
3

gojsontoyaml

Simple tool to convert json to yaml written in Go.
Go
78
star
4

locutus

Go
61
star
5

hlin

Hlín - Securely share secrets.
Go
11
star
6

kube-pod-exporter

Expose Kubernetes pod and container metrics in Prometheus format.
Go
9
star
7

kube-audience-proxy

A HTTP client proxy that transparently fetches and injects audience scoped Kubernetes ServiceAccount tokens.
Go
9
star
8

desktop-install

Shell script I use to install and configure my ubuntu/osx machine.
Shell
6
star
9

loki-jsonnet

Jsonnet
6
star
10

ambench

Tool to perform load tests on the Prometheus Alertmanager project.
Go
4
star
11

pastebin

Simple rails based pastebin
Ruby
4
star
12

tokenrequest

An example use of the Kubernetes TokenRequest API.
Go
4
star
13

slides

Slides and demo to my talks
HTML
4
star
14

kp

Experiments around an improved UX for kube-prometheus
Jsonnet
3
star
15

dotfiles

my dotfiles
Perl
2
star
16

base-app

Rails base app, Rspec, Devise, Dynamic Role System with CanCan and AngularJS
Ruby
2
star
17

pact_broker_pg_docker

Setup your own pact broker within seconds with docker-compose
Ruby
2
star
18

coredns-jsonnet

Jsonnet code to render Kubernetes manifests for coredns.
1
star
19

blackbox-exporter-jsonnet

Jsonnet
1
star
20

vulnweb

Demonstration of rkt's seccomp filter features
Go
1
star
21

vagrant-golang

Vagrantfile for quick golang development.
Go
1
star
22

coverageanalysis

Analyzing coverage reports with go
Go
1
star
23

elk-docker

ELK Stack for json logs
1
star
24

rpi-co2-meter

Python
1
star