2021-01-22 16:09:20 +00:00
|
|
|
use network_protocol::Pid;
|
|
|
|
use prometheus::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry};
|
2020-04-24 10:56:04 +00:00
|
|
|
use std::error::Error;
|
2020-02-19 17:08:57 +00:00
|
|
|
|
2020-08-26 23:55:13 +00:00
|
|
|
/// 1:1 relation between NetworkMetrics and Network
|
|
|
|
/// use 2NF here and avoid redundant data like CHANNEL AND PARTICIPANT encoding.
|
|
|
|
/// as this will cause a matrix that is full of 0 but needs alot of bandwith and
|
|
|
|
/// storage
|
2020-04-08 14:26:42 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
pub struct NetworkMetrics {
|
2020-04-24 10:56:04 +00:00
|
|
|
pub listen_requests_total: IntCounterVec,
|
|
|
|
pub connect_requests_total: IntCounterVec,
|
|
|
|
pub participants_connected_total: IntCounter,
|
|
|
|
pub participants_disconnected_total: IntCounter,
|
2020-08-26 23:55:13 +00:00
|
|
|
// channel id's, seperated by PARTICIPANT, max 5
|
|
|
|
pub participants_channel_ids: IntGaugeVec,
|
2020-04-08 14:26:42 +00:00
|
|
|
// opened Channels, seperated by PARTICIPANT
|
2020-04-24 10:56:04 +00:00
|
|
|
pub channels_connected_total: IntCounterVec,
|
|
|
|
pub channels_disconnected_total: IntCounterVec,
|
2020-04-08 14:26:42 +00:00
|
|
|
// opened streams, seperated by PARTICIPANT
|
2020-04-24 10:56:04 +00:00
|
|
|
pub streams_opened_total: IntCounterVec,
|
|
|
|
pub streams_closed_total: IntCounterVec,
|
2020-04-08 14:26:42 +00:00
|
|
|
pub network_info: IntGauge,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NetworkMetrics {
|
|
|
|
#[allow(dead_code)]
|
2020-05-04 13:27:58 +00:00
|
|
|
pub fn new(local_pid: &Pid) -> Result<Self, Box<dyn Error>> {
|
2020-04-24 10:56:04 +00:00
|
|
|
let listen_requests_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"listen_requests_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Shows the number of listen requests to the scheduler",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["protocol"],
|
|
|
|
)?;
|
|
|
|
let connect_requests_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"connect_requests_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Shows the number of connect requests to the scheduler",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["protocol"],
|
|
|
|
)?;
|
|
|
|
let participants_connected_total = IntCounter::with_opts(Opts::new(
|
|
|
|
"participants_connected_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Shows the number of participants connected to the network",
|
2020-04-08 14:26:42 +00:00
|
|
|
))?;
|
2020-04-24 10:56:04 +00:00
|
|
|
let participants_disconnected_total = IntCounter::with_opts(Opts::new(
|
|
|
|
"participants_disconnected_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Shows the number of participants disconnected to the network",
|
2020-04-08 14:26:42 +00:00
|
|
|
))?;
|
2020-08-26 23:55:13 +00:00
|
|
|
let participants_channel_ids = IntGaugeVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"participants_channel_ids",
|
|
|
|
"Channel numbers belonging to a Participant in the network",
|
|
|
|
),
|
|
|
|
&["participant", "no"],
|
|
|
|
)?;
|
2020-04-24 10:56:04 +00:00
|
|
|
let channels_connected_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"channels_connected_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Number of all channels currently connected on the network",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let channels_disconnected_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"channels_disconnected_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Number of all channels currently disconnected on the network",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let streams_opened_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"streams_opened_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Number of all streams currently open on the network",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let streams_closed_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"streams_closed_total",
|
2020-07-05 22:13:53 +00:00
|
|
|
"Number of all streams currently open on the network",
|
2020-04-24 10:56:04 +00:00
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
2020-05-04 13:27:58 +00:00
|
|
|
let opts = Opts::new("network_info", "Static Network information")
|
|
|
|
.const_label(
|
|
|
|
"version",
|
|
|
|
&format!(
|
|
|
|
"{}.{}.{}",
|
2021-01-22 16:09:20 +00:00
|
|
|
&network_protocol::VELOREN_NETWORK_VERSION[0],
|
|
|
|
&network_protocol::VELOREN_NETWORK_VERSION[1],
|
|
|
|
&network_protocol::VELOREN_NETWORK_VERSION[2]
|
2020-05-04 13:27:58 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.const_label("local_pid", &format!("{}", &local_pid));
|
2020-04-08 14:26:42 +00:00
|
|
|
let network_info = IntGauge::with_opts(opts)?;
|
|
|
|
|
|
|
|
Ok(Self {
|
2020-04-24 10:56:04 +00:00
|
|
|
listen_requests_total,
|
|
|
|
connect_requests_total,
|
|
|
|
participants_connected_total,
|
|
|
|
participants_disconnected_total,
|
2020-08-26 23:55:13 +00:00
|
|
|
participants_channel_ids,
|
2020-04-24 10:56:04 +00:00
|
|
|
channels_connected_total,
|
|
|
|
channels_disconnected_total,
|
|
|
|
streams_opened_total,
|
|
|
|
streams_closed_total,
|
2020-04-08 14:26:42 +00:00
|
|
|
network_info,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-24 10:56:04 +00:00
|
|
|
pub fn register(&self, registry: &Registry) -> Result<(), Box<dyn Error>> {
|
|
|
|
registry.register(Box::new(self.listen_requests_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.connect_requests_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.participants_connected_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.participants_disconnected_total.clone()))?;
|
2020-08-26 23:55:13 +00:00
|
|
|
registry.register(Box::new(self.participants_channel_ids.clone()))?;
|
2020-04-24 10:56:04 +00:00
|
|
|
registry.register(Box::new(self.channels_connected_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.channels_disconnected_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.streams_opened_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.streams_closed_total.clone()))?;
|
2020-05-27 15:58:57 +00:00
|
|
|
registry.register(Box::new(self.network_info.clone()))?;
|
2020-04-24 10:56:04 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Debug for NetworkMetrics {
|
|
|
|
#[inline]
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "NetworkMetrics()")
|
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|