Skip to content

coryodaniel/metrics-mock

Repository files navigation

metricsbin

A simple prometheus metrics mock service.

This service exposes a /metrics endpoint and has two additional endpoints for generating prometheus metrics:

  • /status/{statusCode} for incrementing a request counter partitioned by: route pattern, method, and code
  • /latency/{sleepMs} for creating histogram metrics partitioned by: route pattern, method, and code

Note: The latency endpoint does not actually sleep, it just fakes the observation in the prometheus middleware.

Usage

Start the server:

metricsbin -listen-address=:8080

Generating metrics

Metrics are generated by requests to either of the two endpoints. There is also a landing page with a few shortcuts to create metrics @ http://localhost:8080/.

Generate some 200 OK metrics:

curl http://localhost:8083/status/200
curl -XPOST http://localhost:8083/status/200

Generate 500 error metrics:

curl http://localhost:8083/status/500
curl -XPOST http://localhost:8083/status/500

Generate latency metrics:

# 1ms GET response 
curl http://localhost:8083/latency/1

# 1000ms POST response
curl -XPOST http://localhost:8083/latency/1000

Metrics can be viewed at the /metrics endpoint.

# HELP http_request_duration_milliseconds How long it took to process the request, partitioned by status code, method and HTTP path.
# TYPE http_request_duration_milliseconds histogram
http_request_duration_milliseconds_bucket{code="200",method="get",path="/",le="1"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/",le="10"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/",le="100"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/",le="1000"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/",le="+Inf"} 1
http_request_duration_milliseconds_sum{code="200",method="get",path="/"} 0.016795
http_request_duration_milliseconds_count{code="200",method="get",path="/"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/latency/{sleepMs}",le="1"} 7
http_request_duration_milliseconds_bucket{code="200",method="get",path="/latency/{sleepMs}",le="10"} 7
http_request_duration_milliseconds_bucket{code="200",method="get",path="/latency/{sleepMs}",le="100"} 8
http_request_duration_milliseconds_bucket{code="200",method="get",path="/latency/{sleepMs}",le="1000"} 8
http_request_duration_milliseconds_bucket{code="200",method="get",path="/latency/{sleepMs}",le="+Inf"} 8
http_request_duration_milliseconds_sum{code="200",method="get",path="/latency/{sleepMs}"} 105.219413
http_request_duration_milliseconds_count{code="200",method="get",path="/latency/{sleepMs}"} 8
http_request_duration_milliseconds_bucket{code="200",method="get",path="/metrics",le="1"} 0
http_request_duration_milliseconds_bucket{code="200",method="get",path="/metrics",le="10"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/metrics",le="100"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/metrics",le="1000"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/metrics",le="+Inf"} 1
http_request_duration_milliseconds_sum{code="200",method="get",path="/metrics"} 1.052521
http_request_duration_milliseconds_count{code="200",method="get",path="/metrics"} 1
http_request_duration_milliseconds_bucket{code="200",method="get",path="/status/{statusCode}",le="1"} 5
http_request_duration_milliseconds_bucket{code="200",method="get",path="/status/{statusCode}",le="10"} 5
http_request_duration_milliseconds_bucket{code="200",method="get",path="/status/{statusCode}",le="100"} 5
http_request_duration_milliseconds_bucket{code="200",method="get",path="/status/{statusCode}",le="1000"} 5
http_request_duration_milliseconds_bucket{code="200",method="get",path="/status/{statusCode}",le="+Inf"} 5
http_request_duration_milliseconds_sum{code="200",method="get",path="/status/{statusCode}"} 0.37340700000000004
http_request_duration_milliseconds_count{code="200",method="get",path="/status/{statusCode}"} 5
# HELP http_requests_total How many HTTP requests processed, partitioned by status code, method and HTTP path.
# TYPE http_requests_total counter
http_requests_total{code="200",method="get",path="/"} 1
http_requests_total{code="200",method="get",path="/latency/{sleepMs}"} 8
http_requests_total{code="200",method="get",path="/metrics"} 1
http_requests_total{code="200",method="get",path="/status/{statusCode}"} 5