Skip to content

[draft] feat(monitoring): add per-channel and per-client byte metrics#285

Open
gimballock wants to merge 1 commit intostratum-mining:mainfrom
fossatmara:feat/bytes-metrics
Open

[draft] feat(monitoring): add per-channel and per-client byte metrics#285
gimballock wants to merge 1 commit intostratum-mining:mainfrom
fossatmara:feat/bytes-metrics

Conversation

@gimballock
Copy link

Add bytes_received/bytes_sent tracking across all three components (pool, jd-client, translator) for SV2 channels and SV1 clients.

SV2 byte tracking:

  • Per-channel (bytes_received, bytes_sent) counters in pool, jd-client, and translator, keyed by channel_id in bytes_by_channel maps
  • Shared mining_message_channel_id() helper in protocol_message_type.rs to extract channel_id from parsed Mining messages
  • Raw frame payload guard (len >= 4) for channel_id extraction from unparsed upstream frames in jd-client and translator
  • Cleanup in all CloseChannel handlers and ChannelManagerData::reset()
  • JDC record_upstream_sent_bytes() eliminates double-lock on sends

SV1 byte tracking (translator only):

  • Arc counters in ConnectionSV1, shared with DownstreamData
  • Reader counts line.len()+1 (newline stripped by LinesCodec)
  • Writer counts serialized JSON bytes before write_all

Prometheus metrics:

  • sv2_server_channel_bytes_{received,sent}_total
  • sv2_client_channel_bytes_{received,sent}_total
  • sv1_client_bytes_{received,sent}_total
  • All use gauge-with-reset pattern for stale label cleanup

Also updates README with new metric names and design notes on capacity planning, anomaly detection, cost attribution, and reflection attack detection use cases.

Add bytes_received/bytes_sent tracking across all three components
(pool, jd-client, translator) for SV2 channels and SV1 clients.

SV2 byte tracking:
- Per-channel (bytes_received, bytes_sent) counters in pool, jd-client,
  and translator, keyed by channel_id in bytes_by_channel maps
- Shared mining_message_channel_id() helper in protocol_message_type.rs
  to extract channel_id from parsed Mining messages
- Raw frame payload guard (len >= 4) for channel_id extraction from
  unparsed upstream frames in jd-client and translator
- Cleanup in all CloseChannel handlers and ChannelManagerData::reset()
- JDC record_upstream_sent_bytes() eliminates double-lock on sends

SV1 byte tracking (translator only):
- Arc<AtomicU64> counters in ConnectionSV1, shared with DownstreamData
- Reader counts line.len()+1 (newline stripped by LinesCodec)
- Writer counts serialized JSON bytes before write_all

Prometheus metrics:
- sv2_server_channel_bytes_{received,sent}_total
- sv2_client_channel_bytes_{received,sent}_total
- sv1_client_bytes_{received,sent}_total
- All use gauge-with-reset pattern for stale label cleanup

Also updates README with new metric names and design notes on
capacity planning, anomaly detection, cost attribution, and
reflection attack detection use cases.
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.

1 participant