1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
56// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
1718//! Metering primitives and globals
1920use prometheus::{
21 core::{AtomicU64, GenericCounter, GenericGauge},
22 Error as PrometheusError, Registry,
23};
24use std::sync::LazyLock;
2526use prometheus::{
27 core::{GenericCounterVec, GenericGaugeVec},
28 Opts,
29};
3031pub static TOKIO_THREADS_TOTAL: LazyLock<GenericCounter<AtomicU64>> = LazyLock::new(|| {
32 GenericCounter::new("substrate_tokio_threads_total", "Total number of threads created")
33 .expect("Creating of statics doesn't fail. qed")
34});
3536pub static TOKIO_THREADS_ALIVE: LazyLock<GenericGauge<AtomicU64>> = LazyLock::new(|| {
37 GenericGauge::new("substrate_tokio_threads_alive", "Number of threads alive right now")
38 .expect("Creating of statics doesn't fail. qed")
39});
4041pub static UNBOUNDED_CHANNELS_COUNTER: LazyLock<GenericCounterVec<AtomicU64>> =
42 LazyLock::new(|| {
43 GenericCounterVec::new(
44 Opts::new(
45"substrate_unbounded_channel_len",
46"Items sent/received/dropped on each mpsc::unbounded instance",
47 ),
48&["entity", "action"], // name of channel, send|received|dropped
49)
50 .expect("Creating of statics doesn't fail. qed")
51 });
5253pub static UNBOUNDED_CHANNELS_SIZE: LazyLock<GenericGaugeVec<AtomicU64>> = LazyLock::new(|| {
54 GenericGaugeVec::new(
55 Opts::new(
56"substrate_unbounded_channel_size",
57"Size (number of messages to be processed) of each mpsc::unbounded instance",
58 ),
59&["entity"], // name of channel
60)
61 .expect("Creating of statics doesn't fail. qed")
62});
6364pub static SENT_LABEL: &'static str = "send";
65pub static RECEIVED_LABEL: &'static str = "received";
66pub static DROPPED_LABEL: &'static str = "dropped";
6768/// Register the statics to report to registry
69pub fn register_globals(registry: &Registry) -> Result<(), PrometheusError> {
70 registry.register(Box::new(TOKIO_THREADS_ALIVE.clone()))?;
71 registry.register(Box::new(TOKIO_THREADS_TOTAL.clone()))?;
72 registry.register(Box::new(UNBOUNDED_CHANNELS_COUNTER.clone()))?;
73 registry.register(Box::new(UNBOUNDED_CHANNELS_SIZE.clone()))?;
7475Ok(())
76}