diff --git a/agent/grpc/stats.go b/agent/grpc/stats.go index 16961e7f0a..add3195f16 100644 --- a/agent/grpc/stats.go +++ b/agent/grpc/stats.go @@ -36,7 +36,7 @@ func (c *statsHandler) HandleRPC(_ context.Context, s stats.RPCStats) { } switch s.(type) { case *stats.InHeader: - c.metrics.IncrCounter([]string{"grpc", label, "request"}, 1) + c.metrics.IncrCounter([]string{"grpc", label, "request", "count"}, 1) } } @@ -56,11 +56,12 @@ func (c *statsHandler) HandleConn(_ context.Context, s stats.ConnStats) { switch s.(type) { case *stats.ConnBegin: count = atomic.AddUint64(&c.activeConns, 1) + c.metrics.IncrCounter([]string{"grpc", label, "connection", "count"}, 1) case *stats.ConnEnd: // Decrement! count = atomic.AddUint64(&c.activeConns, ^uint64(0)) } - c.metrics.SetGauge([]string{"grpc", label, "active_conns"}, float32(count)) + c.metrics.SetGauge([]string{"grpc", label, "connections"}, float32(count)) } type activeStreamCounter struct { @@ -79,10 +80,11 @@ func (i *activeStreamCounter) Intercept( handler grpc.StreamHandler, ) error { count := atomic.AddUint64(&i.count, 1) - i.metrics.SetGauge([]string{"grpc", "server", "active_streams"}, float32(count)) + i.metrics.SetGauge([]string{"grpc", "server", "streams"}, float32(count)) + i.metrics.IncrCounter([]string{"grpc", "server", "stream", "count"}, 1) defer func() { count := atomic.AddUint64(&i.count, ^uint64(0)) - i.metrics.SetGauge([]string{"grpc", "server", "active_streams"}, float32(count)) + i.metrics.SetGauge([]string{"grpc", "server", "streams"}, float32(count)) }() return handler(srv, ss) diff --git a/agent/grpc/stats_test.go b/agent/grpc/stats_test.go index ea4cb70b24..de83e2e20e 100644 --- a/agent/grpc/stats_test.go +++ b/agent/grpc/stats_test.go @@ -80,15 +80,17 @@ func TestHandler_EmitsStats(t *testing.T) { cmpMetricCalls := cmp.AllowUnexported(metricCall{}) expectedGauge := []metricCall{ - {key: []string{"testing", "grpc", "server", "active_conns"}, val: 1}, - {key: []string{"testing", "grpc", "server", "active_streams"}, val: 1}, - {key: []string{"testing", "grpc", "server", "active_conns"}, val: 0}, - {key: []string{"testing", "grpc", "server", "active_streams"}, val: 0}, + {key: []string{"testing", "grpc", "server", "connections"}, val: 1}, + {key: []string{"testing", "grpc", "server", "streams"}, val: 1}, + {key: []string{"testing", "grpc", "server", "connections"}, val: 0}, + {key: []string{"testing", "grpc", "server", "streams"}, val: 0}, } assertDeepEqual(t, expectedGauge, sink.gaugeCalls, cmpMetricCalls) expectedCounter := []metricCall{ - {key: []string{"testing", "grpc", "server", "request"}, val: 1}, + {key: []string{"testing", "grpc", "server", "connection", "count"}, val: 1}, + {key: []string{"testing", "grpc", "server", "request", "count"}, val: 1}, + {key: []string{"testing", "grpc", "server", "stream", "count"}, val: 1}, } assertDeepEqual(t, expectedCounter, sink.incrCounterCalls, cmpMetricCalls) } diff --git a/website/pages/docs/agent/telemetry.mdx b/website/pages/docs/agent/telemetry.mdx index c5d842519b..46c1d92692 100644 --- a/website/pages/docs/agent/telemetry.mdx +++ b/website/pages/docs/agent/telemetry.mdx @@ -263,6 +263,14 @@ These metrics are used to monitor the health of the Consul servers. | `consul.session_ttl.invalidate` | This measures the time spent invalidating an expired session. | ms | timer | | `consul.txn.apply` | This measures the time spent applying a transaction operation. | ms | timer | | `consul.txn.read` | This measures the time spent returning a read transaction. | ms | timer | +| `consul.grpc.client.request.count` | This metric counts the number of gRPC requests made by the client agent to a Consul server. | requests | counter | +| `consul.grpc.client.connect.count` | This metric counts the number of new gRPC connections opened by the client agent to a Consul server. | connections | counter | +| `consul.grpc.client.connections` | This metric measures the number of active gRPC connections open from the client agent to any Consul servers. | connections | gauge | +| `consul.grpc.server.request.count` | This metric counts the number of gRPC requests received by the server. | requests | counter | +| `consul.grpc.server.connect.count` | This metric counts the number of new gRPC connections received by the server. | connections | counter | +| `consul.grpc.server.connections` | This metric measures the number of active gRPC connections open on the server. | connections | gauge | +| `consul.grpc.server.stream.count` | This metric counts the number of new gRPC streams received by the server. | streams | counter | +| `consul.grpc.server.streams` | This metric measures the number of active gRPC streams handled by the server. | streams | guage | ## Cluster Health