Skip to content

Comments

Add Prometheus gauge for current gRPC client connections#545

Open
czarcas7ic wants to merge 1 commit intozcash:masterfrom
czarcas7ic:adam/grpc-connection-gauge
Open

Add Prometheus gauge for current gRPC client connections#545
czarcas7ic wants to merge 1 commit intozcash:masterfrom
czarcas7ic:adam/grpc-connection-gauge

Conversation

@czarcas7ic
Copy link
Contributor

@czarcas7ic czarcas7ic commented Feb 3, 2026

A node runner mentioned having the number of connections as a Prometheus metric would be helpful for them, so added it here.

Summary

  • Adds a grpc_server_connections_current Prometheus gauge that tracks active gRPC client connections
  • Uses gRPC's stats.Handler interface (ConnBegin/ConnEnd)
  • No new dependencies; uses google.golang.org/grpc/stats (part of grpc-go) and promauto (part of existing prometheus/client_golang)

Changes

  • cmd/connstats.go — defines the gauge and a connStatsHandler implementing stats.Handler
  • cmd/root.go — wires grpc.StatsHandler(&connStatsHandler{}) into both the TLS and non-TLS grpc.NewServer() calls
  • cmd/connstats_test.go — unit tests for increment/decrement and passthrough behavior
  • go.modgo mod tidy promoted two already-present indirect deps to direct

Testing

Screenshot 2026-02-03 at 8 52 13 PM Screenshot 2026-02-03 at 8 53 55 PM

@czarcas7ic czarcas7ic marked this pull request as ready for review February 3, 2026 17:14
@czarcas7ic czarcas7ic force-pushed the adam/grpc-connection-gauge branch from f7f5dae to 20e0785 Compare February 4, 2026 04:47
@LarryRuane
Copy link
Collaborator

I can't get this to work in testing. It's probably something in my environment. http://127.0.0.1:9090/query returns "127.0.0.1 refused to connect". I think this is consistent with:

$ curl -I http://localhost:9090
curl: (7) Failed to connect to localhost port 9090 after 0 ms: Could not connect to server
$

@ValarDragon
Copy link

ValarDragon commented Feb 4, 2026

Its working on my machine too

image

@LarryRuane I think your issue is a more general setup issue, e.g. no prometheus running in the first place.

Did you install prometheus?

sudo apt update
sudo apt install prometheus

and then I ask claude to install it

Copy link
Collaborator

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you install prometheus?

No, I didn't; I'm sure that's the problem. But I don't really need to run it, I'm fine with merging this since some have asked for it, and it's easy to add. I verified that there is no noticeable difference in performance or memory usage with this PR compared to without it. I ran both tests (go test ./... and ./smoke-test.bash) and there are no failures. I did not test the actual functionality (but I'm sure it's okay).

ACK 20e0785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants