Skip to content

Metrics

go-zero automatically records key metrics for HTTP and gRPC services and exposes them via a Prometheus scrape endpoint.

etc/app.yaml
Prometheus:
Host: 0.0.0.0
Port: 9101
Path: /metrics

HTTP service:

MetricDescription
http_server_requests_totalTotal requests by route and status
http_server_duration_msRequest duration histogram
http_server_active_requestsIn-flight requests gauge

gRPC service:

MetricDescription
rpc_server_requests_totalTotal RPC calls by method and code
rpc_server_duration_msRPC duration histogram
import "github.com/zeromicro/go-zero/core/metric"
// Counter
ordersTotal := metric.NewCounterVec(&metric.CounterVecOpts{
Namespace: "order",
Subsystem: "service",
Name: "created_total",
Help: "Total orders created",
Labels: []string{"status"},
})
ordersTotal.Inc("success")
// Histogram
latency := metric.NewHistogramVec(&metric.HistogramVecOpts{
Namespace: "order",
Name: "payment_duration_ms",
Help: "Payment processing latency",
Labels: []string{"provider"},
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
})
latency.Observe(float64(elapsed.Milliseconds()), "stripe")

go-zero provides community dashboards on Grafana’s marketplace — search for “go-zero”.