go-template
go-template copied to clipboard
Implement basic metrics
📝 Summary
Implement basic prometheus metrics endpoint.
⛱ Motivation and Context
Most of the time we will want to be able to observe the internal state of the app with prometheus.
TL;DR
go run github.com/flashbots/go-template/cmd/httpserver --metrics-addr 127.0.0.1:6061
curl -isS 127.0.0.1:8080/api
HTTP/1.1 200 OK
Date: Thu, 23 Nov 2023 15:02:34 GMT
Content-Length: 0
curl -sS 127.0.0.1:6061/metrics | grep -v -e "^#.*$" | sort
otel_scope_info{otel_scope_name="github.com/flashbots/go-template",otel_scope_version=""} 1
otel_scope_info{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 1
process_runtime_go_cgo_calls{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 1
process_runtime_go_gc_count_total{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 0
process_runtime_go_gc_pause_total_ns_total{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 0
process_runtime_go_goroutines{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 8
process_runtime_go_mem_heap_alloc_bytes{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 1.531376e+06
process_runtime_go_mem_heap_idle_bytes{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 1.261568e+06
process_runtime_go_mem_heap_inuse_bytes{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 2.473984e+06
process_runtime_go_mem_heap_objects{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 3228
process_runtime_go_mem_heap_released_bytes{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 1.261568e+06
process_runtime_go_mem_heap_sys_bytes{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 3.735552e+06
process_runtime_go_mem_live_objects{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 3228
process_runtime_go_mem_lookups_total{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 0
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="+Inf"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.01"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.025"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.05"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.1"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.25"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="0.5"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="1"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="10"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="2.5"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="30"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="5"} 1
request_duration_api_microseconds_bucket{otel_scope_name="github.com/flashbots/go-template",otel_scope_version="",le="60"} 1
request_duration_api_microseconds_count{otel_scope_name="github.com/flashbots/go-template",otel_scope_version=""} 1
request_duration_api_microseconds_sum{otel_scope_name="github.com/flashbots/go-template",otel_scope_version=""} 0
runtime_uptime_milliseconds_total{otel_scope_name="go.opentelemetry.io/contrib/instrumentation/runtime",otel_scope_version="0.46.1"} 93413
target_info{service_name="unknown_service:httpserver",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="1.21.0"} 1
✅ I have run these commands
- [x]
make lint
- [x]
make test
- [x]
go mod tidy