mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 19:07:57 +00:00
client/network/src/protocol: Refactor Prometheus metric logic (#5266)
* client/network/src/protocol: Start Prometheus metric help with capital * client/network/src/protocol: Differentiate metric status as label Prometheus query language is powerful through its multi-dimensional data model. Metric names are hirarchical whereas labels enable data to become multi-dimensional. Exposing the justification of finality-proof status as a label allows for more powerful queries. * client/network/src/protocol: Remove 'Total' from non counter metric help The word 'total' is reserved for accumulating counters. Counters have to be monotonically increasing. `obsolete_requests` can decrease, thereby it is defined as a `Gauge` and not a `Counter`. For more details on metric naming see https://prometheus.io/docs/practices/naming/
This commit is contained in:
@@ -38,7 +38,7 @@ use sp_arithmetic::traits::SaturatedConversion;
|
||||
use message::{BlockAnnounce, BlockAttributes, Direction, FromBlock, Message, RequestId};
|
||||
use message::generic::Message as GenericMessage;
|
||||
use light_dispatch::{LightDispatch, LightDispatchNetwork, RequestData};
|
||||
use prometheus_endpoint::{Registry, Gauge, register, PrometheusError, U64};
|
||||
use prometheus_endpoint::{Registry, Gauge, GaugeVec, PrometheusError, Opts, register, U64};
|
||||
use sync::{ChainSync, SyncState};
|
||||
use crate::service::{TransactionPool, ExHashT};
|
||||
use crate::config::{BoxFinalityProofRequestBuilder, Roles};
|
||||
@@ -142,92 +142,50 @@ struct Metrics {
|
||||
peers: Gauge<U64>,
|
||||
queued_blocks: Gauge<U64>,
|
||||
fork_targets: Gauge<U64>,
|
||||
finality_proofs_pending: Gauge<U64>,
|
||||
finality_proofs_active: Gauge<U64>,
|
||||
finality_proofs_failed: Gauge<U64>,
|
||||
finality_proofs_importing: Gauge<U64>,
|
||||
justifications_pending: Gauge<U64>,
|
||||
justifications_active: Gauge<U64>,
|
||||
justifications_failed: Gauge<U64>,
|
||||
justifications_importing: Gauge<U64>
|
||||
finality_proofs: GaugeVec<U64>,
|
||||
justifications: GaugeVec<U64>,
|
||||
}
|
||||
|
||||
impl Metrics {
|
||||
fn register(r: &Registry) -> Result<Self, PrometheusError> {
|
||||
Ok(Metrics {
|
||||
handshaking_peers: {
|
||||
let g = Gauge::new("sync_handshaking_peers", "number of newly connected peers")?;
|
||||
let g = Gauge::new("sync_handshaking_peers", "Number of newly connected peers")?;
|
||||
register(g, r)?
|
||||
},
|
||||
obsolete_requests: {
|
||||
let g = Gauge::new("sync_obsolete_requests", "total number of obsolete requests")?;
|
||||
let g = Gauge::new("sync_obsolete_requests", "Number of obsolete requests")?;
|
||||
register(g, r)?
|
||||
},
|
||||
peers: {
|
||||
let g = Gauge::new("sync_peers", "number of peers we sync with")?;
|
||||
let g = Gauge::new("sync_peers", "Number of peers we sync with")?;
|
||||
register(g, r)?
|
||||
},
|
||||
queued_blocks: {
|
||||
let g = Gauge::new("sync_queued_blocks", "number of blocks in import queue")?;
|
||||
let g = Gauge::new("sync_queued_blocks", "Number of blocks in import queue")?;
|
||||
register(g, r)?
|
||||
},
|
||||
fork_targets: {
|
||||
let g = Gauge::new("sync_fork_targets", "fork sync targets")?;
|
||||
let g = Gauge::new("sync_fork_targets", "Number of fork sync targets")?;
|
||||
register(g, r)?
|
||||
},
|
||||
justifications_pending: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_justifications_pending",
|
||||
"number of pending extra justifications requests"
|
||||
justifications: {
|
||||
let g = GaugeVec::new(
|
||||
Opts::new(
|
||||
"sync_extra_justifications",
|
||||
"Number of extra justifications requests"
|
||||
),
|
||||
&["status"],
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
justifications_active: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_justifications_active",
|
||||
"number of active extra justifications requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
justifications_failed: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_justifications_failed",
|
||||
"number of failed extra justifications requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
justifications_importing: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_justifications_importing",
|
||||
"number of importing extra justifications requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
finality_proofs_pending: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_finality_proofs_pending",
|
||||
"number of pending extra finality proof requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
finality_proofs_active: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_finality_proofs_active",
|
||||
"number of active extra finality proof requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
finality_proofs_failed: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_finality_proofs_failed",
|
||||
"number of failed extra finality proof requests"
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
finality_proofs_importing: {
|
||||
let g = Gauge::new(
|
||||
"sync_extra_finality_proofs_importing",
|
||||
"number of importing extra finality proof requests"
|
||||
finality_proofs: {
|
||||
let g = GaugeVec::new(
|
||||
Opts::new(
|
||||
"sync_extra_finality_proofs",
|
||||
"Number of extra finality proof requests",
|
||||
),
|
||||
&["status"],
|
||||
)?;
|
||||
register(g, r)?
|
||||
},
|
||||
@@ -1917,15 +1875,23 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
metrics.fork_targets.set(m.fork_targets.into());
|
||||
metrics.queued_blocks.set(m.queued_blocks.into());
|
||||
|
||||
metrics.justifications_pending.set(m.justifications.pending_requests.into());
|
||||
metrics.justifications_active.set(m.justifications.active_requests.into());
|
||||
metrics.justifications_failed.set(m.justifications.failed_requests.into());
|
||||
metrics.justifications_importing.set(m.justifications.importing_requests.into());
|
||||
metrics.justifications.with_label_values(&["pending"])
|
||||
.set(m.justifications.pending_requests.into());
|
||||
metrics.justifications.with_label_values(&["active"])
|
||||
.set(m.justifications.active_requests.into());
|
||||
metrics.justifications.with_label_values(&["failed"])
|
||||
.set(m.justifications.failed_requests.into());
|
||||
metrics.justifications.with_label_values(&["importing"])
|
||||
.set(m.justifications.importing_requests.into());
|
||||
|
||||
metrics.finality_proofs_pending.set(m.finality_proofs.pending_requests.into());
|
||||
metrics.finality_proofs_active.set(m.finality_proofs.active_requests.into());
|
||||
metrics.finality_proofs_failed.set(m.finality_proofs.failed_requests.into());
|
||||
metrics.finality_proofs_importing.set(m.finality_proofs.importing_requests.into());
|
||||
metrics.finality_proofs.with_label_values(&["pending"])
|
||||
.set(m.finality_proofs.pending_requests.into());
|
||||
metrics.finality_proofs.with_label_values(&["active"])
|
||||
.set(m.finality_proofs.active_requests.into());
|
||||
metrics.finality_proofs.with_label_values(&["failed"])
|
||||
.set(m.finality_proofs.failed_requests.into());
|
||||
metrics.finality_proofs.with_label_values(&["importing"])
|
||||
.set(m.finality_proofs.importing_requests.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user