Skip to content

Conversation

@Patrick-Ehimen
Copy link

Summary

  • Adds two new counter metrics to track stream lifecycle events:
    • libp2p_protocol_streams_opened_total - incremented when a stream is opened
    • libp2p_protocol_streams_closed_total - incremented when a stream is closed
  • Uses the same label format as the existing gauge: {direction} {protocol}
  • Preserves the existing libp2p_protocol_streams_total gauge for backward compatibility

Motivation

The existing gauge metric only shows current state. These counters enable:

  • Calculating stream open/close rates using Prometheus rate() or increase()
  • Analyzing stream throughput patterns over time
  • Deriving current streams as opened_total - closed_total

Test plan

  • All existing connection tests pass (20/20)
  • All existing connection-manager tests pass (18/18)
  • Build succeeds

Fixes #3262

Adds two new counter metrics to complement the existing gauge:
- libp2p_protocol_streams_opened_total
- libp2p_protocol_streams_closed_total

These counters enable calculating stream open/close rates and total
throughput over time, addressing the limitations of the existing
gauge metric which only shows current state.

Fixes libp2p#3262
@Patrick-Ehimen Patrick-Ehimen requested a review from a team as a code owner January 26, 2026 15:58
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.

Track protocol stream open/close count in metrics

1 participant