效能優化要有數字依據。Day 10 我們用 pprof 找到 LoggingMiddleware 的熱點並改善,但那是「短時間剖析」。
實務上,我們希望能長期追蹤系統:
今天要做的:在程式裡暴露 metrics endpoint,讓 Prometheus 能定期拉取,之後在 Grafana 畫圖。
Prometheus client_golang:Go 官方的 Prometheus SDK
指標型態:
今天主要用 Counter + Histogram。
go get github.com/prometheus/client_golang/prometheus
metrics.go
.
├── go.mod
├── main.go
├── middleware.go
├── metrics.go # ← 新增
└── ...
// metrics.go
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
// 總請求數,依路徑與狀態碼區分
httpRequestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Number of HTTP requests",
},
[]string{"path", "code"},
)
// 請求延遲,依路徑區分
httpRequestDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "Request latency (seconds)",
Buckets: prometheus.DefBuckets, // 預設 buckets (0.005s ~ 10s)
},
[]string{"path"},
)
)
func init() {
// 註冊到全域 registry
prometheus.MustRegister(httpRequestsTotal, httpRequestDuration)
}
在 middleware.go 裡加:
// MetricsMiddleware 收集 QPS 與 Latency
func MetricsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
// 包裝 ResponseWriter 以攔截狀態碼
rr := &responseRecorder{ResponseWriter: w, statusCode: http.StatusOK}
next.ServeHTTP(rr, r)
duration := time.Since(start).Seconds()
path := r.URL.Path
code := fmt.Sprintf("%d", rr.statusCode)
httpRequestsTotal.WithLabelValues(path, code).Inc()
httpRequestDuration.WithLabelValues(path).Observe(duration)
})
}
// responseRecorder 用來捕捉回應狀態碼
type responseRecorder struct {
http.ResponseWriter
statusCode int
}
func (rr *responseRecorder) WriteHeader(code int) {
rr.statusCode = code
rr.ResponseWriter.WriteHeader(code)
}
/metrics
import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
cfg := LoadConfig()
mux := http.NewServeMux()
mux.HandleFunc("/healthz", healthHandler)
mux.HandleFunc("/search", searchHandler)
// 新增 metrics endpoint
mux.Handle("/metrics", promhttp.Handler())
// 中介層:metrics → logging → recovery
handler := MetricsMiddleware(LoggingMiddleware(RecoveryMiddleware(mux)))
log.Printf("Server listening on %s", cfg.Port)
if err := http.ListenAndServe(cfg.Port, handler); err != nil {
log.Fatal(err)
}
}
開第一個 terminal tab 跑服務:
go run -tags debug .
開第二個 terminal tab 打一次 search API
curl "http://localhost:8080/search?q=0925"
開瀏覽器看 http://localhost:8080/metrics
,應該能看到:*註1
# HELP http_request_duration_seconds Request latency (seconds)
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{path="/metrics",le="0.005"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.01"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.025"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.05"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.1"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.25"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="1"} 1
http_request_duration_seconds_bucket{path="/metrics",le="2.5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="10"} 1
http_request_duration_seconds_bucket{path="/metrics",le="+Inf"} 1
http_request_duration_seconds_sum{path="/metrics"} 0.004142792
http_request_duration_seconds_count{path="/metrics"} 1
http_request_duration_seconds_bucket{path="/search",le="0.005"} 1
http_request_duration_seconds_bucket{path="/search",le="0.01"} 1
http_request_duration_seconds_bucket{path="/search",le="0.025"} 1
http_request_duration_seconds_bucket{path="/search",le="0.05"} 1
http_request_duration_seconds_bucket{path="/search",le="0.1"} 1
http_request_duration_seconds_bucket{path="/search",le="0.25"} 1
http_request_duration_seconds_bucket{path="/search",le="0.5"} 1
http_request_duration_seconds_bucket{path="/search",le="1"} 1
http_request_duration_seconds_bucket{path="/search",le="2.5"} 1
http_request_duration_seconds_bucket{path="/search",le="5"} 1
http_request_duration_seconds_bucket{path="/search",le="10"} 1
http_request_duration_seconds_bucket{path="/search",le="+Inf"} 1
http_request_duration_seconds_sum{path="/search"} 0.000360875
http_request_duration_seconds_count{path="/search"} 1
# HELP http_requests_total Number of HTTP requests
# TYPE http_requests_total counter
http_requests_total{code="200",path="/metrics"} 1
http_requests_total{code="200",path="/search"} 1
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.010666
用 hey
打一下 /search
再刷新瀏覽器頁面 /metrics
,數字會上升。*註2
hey -n 1000000 -c 50 "http://localhost:8080/search?q=golang"
今天完成:
/metrics
👉 明天我們會開始建立 ES 介面層 (SearchService),雖然還沒真的連 Elasticsearch,但先定義一個抽象層,讓 /search
可以呼叫 service 而不是直接寫假資料。
*註1: 完整 log (用 hey 壓測以前)
# HELP go_gc_duration_seconds A summary of the wall-time pause (stop-the-world) duration in garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
# HELP go_gc_gogc_percent Heap size target percentage configured by the user, otherwise 100. This value is set by the GOGC environment variable, and the runtime/debug.SetGCPercent function. Sourced from /gc/gogc:percent.
# TYPE go_gc_gogc_percent gauge
go_gc_gogc_percent 100
# HELP go_gc_gomemlimit_bytes Go runtime memory limit configured by the user, otherwise math.MaxInt64. This value is set by the GOMEMLIMIT environment variable, and the runtime/debug.SetMemoryLimit function. Sourced from /gc/gomemlimit:bytes.
# TYPE go_gc_gomemlimit_bytes gauge
go_gc_gomemlimit_bytes 9.223372036854776e+18
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 7
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.24.0"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated in heap and currently in use. Equals to /memory/classes/heap/objects:bytes.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 989952
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated in heap until now, even if released already. Equals to /gc/heap/allocs:bytes.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 989952
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. Equals to /memory/classes/profiling/buckets:bytes.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.445171e+06
# HELP go_memstats_frees_total Total number of heap objects frees. Equals to /gc/heap/frees:objects + /gc/heap/tiny/allocs:objects.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 0
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata. Equals to /memory/classes/metadata/other:bytes.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 1.4966e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and currently in use, same as go_memstats_alloc_bytes. Equals to /memory/classes/heap/objects:bytes.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 989952
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used. Equals to /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 901120
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 2.801664e+06
# HELP go_memstats_heap_objects Number of currently allocated objects. Equals to /gc/heap/objects:objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 297
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS. Equals to /memory/classes/heap/released:bytes.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 901120
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes + /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 3.702784e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 0
# HELP go_memstats_mallocs_total Total number of heap objects allocated, both live and gc-ed. Semantically a counter version for go_memstats_heap_objects gauge. Equals to /gc/heap/allocs:objects + /gc/heap/tiny/allocs:objects.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 297
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures. Equals to /memory/classes/metadata/mcache/inuse:bytes.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 9664
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system. Equals to /memory/classes/metadata/mcache/inuse:bytes + /memory/classes/metadata/mcache/free:bytes.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 15704
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures. Equals to /memory/classes/metadata/mspan/inuse:bytes.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 54560
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system. Equals to /memory/classes/metadata/mspan/inuse:bytes + /memory/classes/metadata/mspan/free:bytes.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 65280
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place. Equals to /gc/heap/goal:bytes.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.194304e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations. Equals to /memory/classes/other:bytes.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.189221e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes obtained from system for stack allocator in non-CGO environments. Equals to /memory/classes/heap/stacks:bytes.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 491520
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator. Equals to /memory/classes/heap/stacks:bytes + /memory/classes/os-stacks:bytes.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 491520
# HELP go_memstats_sys_bytes Number of bytes obtained from system. Equals to /memory/classes/total:byte.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 8.40628e+06
# HELP go_sched_gomaxprocs_threads The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously. Sourced from /sched/gomaxprocs:threads.
# TYPE go_sched_gomaxprocs_threads gauge
go_sched_gomaxprocs_threads 8
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
go_threads 8
# HELP http_request_duration_seconds Request latency (seconds)
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{path="/metrics",le="0.005"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.01"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.025"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.05"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.1"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.25"} 1
http_request_duration_seconds_bucket{path="/metrics",le="0.5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="1"} 1
http_request_duration_seconds_bucket{path="/metrics",le="2.5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="5"} 1
http_request_duration_seconds_bucket{path="/metrics",le="10"} 1
http_request_duration_seconds_bucket{path="/metrics",le="+Inf"} 1
http_request_duration_seconds_sum{path="/metrics"} 0.004142792
http_request_duration_seconds_count{path="/metrics"} 1
http_request_duration_seconds_bucket{path="/search",le="0.005"} 1
http_request_duration_seconds_bucket{path="/search",le="0.01"} 1
http_request_duration_seconds_bucket{path="/search",le="0.025"} 1
http_request_duration_seconds_bucket{path="/search",le="0.05"} 1
http_request_duration_seconds_bucket{path="/search",le="0.1"} 1
http_request_duration_seconds_bucket{path="/search",le="0.25"} 1
http_request_duration_seconds_bucket{path="/search",le="0.5"} 1
http_request_duration_seconds_bucket{path="/search",le="1"} 1
http_request_duration_seconds_bucket{path="/search",le="2.5"} 1
http_request_duration_seconds_bucket{path="/search",le="5"} 1
http_request_duration_seconds_bucket{path="/search",le="10"} 1
http_request_duration_seconds_bucket{path="/search",le="+Inf"} 1
http_request_duration_seconds_sum{path="/search"} 0.000360875
http_request_duration_seconds_count{path="/search"} 1
# HELP http_requests_total Number of HTTP requests
# TYPE http_requests_total counter
http_requests_total{code="200",path="/metrics"} 1
http_requests_total{code="200",path="/search"} 1
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.010666
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 10240
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 10
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 9.453568e+06
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.758732542e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 4.19641524224e+11
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes 9.223372036854776e+18
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 1
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
*註2: 完整 log (用 hey 壓測之後)
# HELP go_gc_duration_seconds A summary of the wall-time pause (stop-the-world) duration in garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 4.0876e-05
go_gc_duration_seconds{quantile="0.25"} 0.000137501
go_gc_duration_seconds{quantile="0.5"} 0.000225334
go_gc_duration_seconds{quantile="0.75"} 0.000335124
go_gc_duration_seconds{quantile="1"} 0.005740333
go_gc_duration_seconds_sum 0.772205743
go_gc_duration_seconds_count 1805
# HELP go_gc_gogc_percent Heap size target percentage configured by the user, otherwise 100. This value is set by the GOGC environment variable, and the runtime/debug.SetGCPercent function. Sourced from /gc/gogc:percent.
# TYPE go_gc_gogc_percent gauge
go_gc_gogc_percent 100
# HELP go_gc_gomemlimit_bytes Go runtime memory limit configured by the user, otherwise math.MaxInt64. This value is set by the GOMEMLIMIT environment variable, and the runtime/debug.SetMemoryLimit function. Sourced from /gc/gomemlimit:bytes.
# TYPE go_gc_gomemlimit_bytes gauge
go_gc_gomemlimit_bytes 9.223372036854776e+18
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 7
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.24.0"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated in heap and currently in use. Equals to /memory/classes/heap/objects:bytes.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.107232e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated in heap until now, even if released already. Equals to /gc/heap/allocs:bytes.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 3.580763216e+09
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. Equals to /memory/classes/profiling/buckets:bytes.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.460051e+06
# HELP go_memstats_frees_total Total number of heap objects frees. Equals to /gc/heap/frees:objects + /gc/heap/tiny/allocs:objects.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 3.6105982e+07
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata. Equals to /memory/classes/metadata/other:bytes.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 2.723456e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and currently in use, same as go_memstats_alloc_bytes. Equals to /memory/classes/heap/objects:bytes.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 2.107232e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used. Equals to /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 6.406144e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 4.112384e+06
# HELP go_memstats_heap_objects Number of currently allocated objects. Equals to /gc/heap/objects:objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 12598
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS. Equals to /memory/classes/heap/released:bytes.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 4.890624e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes + /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 1.0518528e+07
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.758732796744881e+09
# HELP go_memstats_mallocs_total Total number of heap objects allocated, both live and gc-ed. Semantically a counter version for go_memstats_heap_objects gauge. Equals to /gc/heap/allocs:objects + /gc/heap/tiny/allocs:objects.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 3.611858e+07
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures. Equals to /memory/classes/metadata/mcache/inuse:bytes.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 9664
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system. Equals to /memory/classes/metadata/mcache/inuse:bytes + /memory/classes/metadata/mcache/free:bytes.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 15704
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures. Equals to /memory/classes/metadata/mspan/inuse:bytes.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 154240
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system. Equals to /memory/classes/metadata/mspan/inuse:bytes + /memory/classes/metadata/mspan/free:bytes.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 212160
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place. Equals to /gc/heap/goal:bytes.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.319346e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations. Equals to /memory/classes/other:bytes.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.766685e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes obtained from system for stack allocator in non-CGO environments. Equals to /memory/classes/heap/stacks:bytes.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 2.064384e+06
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator. Equals to /memory/classes/heap/stacks:bytes + /memory/classes/os-stacks:bytes.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 2.064384e+06
# HELP go_memstats_sys_bytes Number of bytes obtained from system. Equals to /memory/classes/total:byte.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 1.8760968e+07
# HELP go_sched_gomaxprocs_threads The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously. Sourced from /sched/gomaxprocs:threads.
# TYPE go_sched_gomaxprocs_threads gauge
go_sched_gomaxprocs_threads 8
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
go_threads 17
# HELP http_request_duration_seconds Request latency (seconds)
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{path="/metrics",le="0.005"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.01"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.025"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.05"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.1"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.25"} 2
http_request_duration_seconds_bucket{path="/metrics",le="0.5"} 2
http_request_duration_seconds_bucket{path="/metrics",le="1"} 2
http_request_duration_seconds_bucket{path="/metrics",le="2.5"} 2
http_request_duration_seconds_bucket{path="/metrics",le="5"} 2
http_request_duration_seconds_bucket{path="/metrics",le="10"} 2
http_request_duration_seconds_bucket{path="/metrics",le="+Inf"} 2
http_request_duration_seconds_sum{path="/metrics"} 0.005547209
http_request_duration_seconds_count{path="/metrics"} 2
http_request_duration_seconds_bucket{path="/search",le="0.005"} 999302
http_request_duration_seconds_bucket{path="/search",le="0.01"} 999796
http_request_duration_seconds_bucket{path="/search",le="0.025"} 999979
http_request_duration_seconds_bucket{path="/search",le="0.05"} 999991
http_request_duration_seconds_bucket{path="/search",le="0.1"} 999999
http_request_duration_seconds_bucket{path="/search",le="0.25"} 1e+06
http_request_duration_seconds_bucket{path="/search",le="0.5"} 1.000001e+06
http_request_duration_seconds_bucket{path="/search",le="1"} 1.000001e+06
http_request_duration_seconds_bucket{path="/search",le="2.5"} 1.000001e+06
http_request_duration_seconds_bucket{path="/search",le="5"} 1.000001e+06
http_request_duration_seconds_bucket{path="/search",le="10"} 1.000001e+06
http_request_duration_seconds_bucket{path="/search",le="+Inf"} 1.000001e+06
http_request_duration_seconds_sum{path="/search"} 19.22615195501686
http_request_duration_seconds_count{path="/search"} 1.000001e+06
# HELP http_requests_total Number of HTTP requests
# TYPE http_requests_total counter
http_requests_total{code="200",path="/metrics"} 2
http_requests_total{code="200",path="/search"} 1.000001e+06
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 22.063315
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 10240
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 10
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 9.240576e+06
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.758732542e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 4.1972793344e+11
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes 9.223372036854776e+18
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 2
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0