Skip to content

feat(metrics): add Prometheus counters for empty blocks and SR set changes#6601

Closed
ToXMon wants to merge 5 commits intotronprotocol:developfrom
ToXMon:feature/prometheus-infra-metrics
Closed

feat(metrics): add Prometheus counters for empty blocks and SR set changes#6601
ToXMon wants to merge 5 commits intotronprotocol:developfrom
ToXMon:feature/prometheus-infra-metrics

Conversation

@ToXMon
Copy link
Copy Markdown

@ToXMon ToXMon commented Mar 25, 2026

Summary

Implements Issue #6590 — adds two new Prometheus counters for blockchain monitoring:

  • tron:block_empty_total — increments when a block with zero transactions is applied
  • tron:sr_set_change_total — tracks SR set changes with added/removed labels

Changes

New Metrics

Metric Type Labels Description
tron:block_empty_total Counter type Tracks empty blocks
tron:sr_set_change_total Counter witness, change_type Tracks SR set changes

Files Modified

  1. common/src/main/java/org/tron/common/prometheus/MetricKeys.java — counter constants
  2. common/src/main/java/org/tron/common/prometheus/MetricLabels.java — label values
  3. common/src/main/java/org/tron/common/prometheus/MetricsCounter.java — counter registration
  4. framework/src/main/java/org/tron/core/metrics/blockchain/BlockChainMetricManager.java — detection logic
  5. framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java — unit tests

Testing

  • testEmptyBlockMetric() — PASSED
  • testSrSetChangeMetric() — PASSED
  • ./gradlew test — BUILD SUCCESSFUL

Backward Compatibility

Fully backward compatible. Zero protocol changes, zero API changes, zero config changes.

Closes #6590

…monitoring

Replace the dedicated tron:block_empty_total counter with a more comprehensive
tron:block_transaction_count histogram that tracks the distribution of
transaction counts per block.

Changes:
- Add overloaded init() method in MetricsHistogram to support custom buckets
- Add BLOCK_TRANSACTION_COUNT histogram with buckets [0, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
- Record transaction count for all blocks (including empty blocks with txCount=0)
- Empty blocks can be queried via bucket le=0.0
- Remove unused BLOCK_EMPTY counter
- Keep SR_SET_CHANGE counter for SR set change monitoring

This provides richer insights for network analysis while still supporting
empty block monitoring via histogram bucket queries.

Closes tronprotocol#6590
@ToXMon ToXMon closed this Mar 25, 2026
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.

[Feature] Add Prometheus metrics for empty blocks and SR set changes

2 participants