콘텐츠로 이동

메트릭

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

HTTP 서비스:

Metric설명
http_server_requests_totalTotal 요청 통해 라우트과 상태
http_server_duration_msRequest duration histogram
http_server_active_requestsIn-flight 요청 gauge

gRPC 서비스:

Metric설명
rpc_server_requests_totalTotal RPC calls 통해 메서드과 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")