Skip to content

[FEATURE] Add Prometheus metrics for empty blocks and SR set changes #6590

@warku123

Description

@warku123

Background

Currently, java-tron's Prometheus metrics provide comprehensive monitoring for transactions, blocks, P2P connections, and consensus status. However, there are two important operational aspects that lack visibility:

  1. Empty Block Detection: There is no metric to track blocks that contain no transactions. Monitoring empty blocks is crucial for identifying potential network issues, misconfigured witness nodes, or degraded transaction throughput.

  2. Super Representative (SR) Set Changes: The active witness set changes during maintenance periods when new SRs are elected or removed. Currently, there is no way to track these changes through metrics, making it difficult to monitor consensus layer dynamics and SR rotation events.

Problem Statement & Rationale

  • Node operators cannot identify which witness nodes are producing empty blocks, making it difficult to diagnose network health issues
  • There is no real-time visibility into SR set changes

What are the use cases?

  1. Identify witnesses producing excessive empty blocks
  2. Monitor SR election results and consensus transitions

Proposed Solution

Add two new Prometheus counters to track empty blocks and SR set changes:

  • tron:block_empty_total - Tracks empty blocks
  • tron:sr_set_change_total - Tracks SR set changes (add/remove)

Testing Strategy

Test Scenarios

  1. Unit Test: Add unit test about two counters.
  2. Manual Test: Build a private chain and test the case include produce empty and SR set change.

Scope of Impact

  • Other: Metrics/Monitoring system

Backward Compatibility

Fully backward compatible. Existing metrics remain unchanged. New metrics are opt-in via Prometheus scraping.

Implementation

Do you have ideas regarding the implementation?

The implementation involves:

  1. Metric Registration: Add new counter definitions in MetricKeys.java, MetricLabels.java, and MetricsCounter.java

  2. BlockChainMetricManager Modifications: In BlockChainMetricManager.java:

    • Add empty block detection logic
    • Add SR set change detection logic
  3. Testing: Extend PrometheusApiServiceTest to cover new metrics functionality

Are you willing to implement this feature?

  • Yes, I can implement this feature

Estimated Complexity

  • Medium (moderate changes)

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions