2020-04-24 10:56:04 +00:00
|
|
|
use prometheus::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry};
|
|
|
|
use std::error::Error;
|
2020-02-19 17:08:57 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
//TODO: switch over to Counter for frames_count, message_count, bytes_send,
|
|
|
|
// frames_message_count 1 NetworkMetrics per Network
|
|
|
|
#[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-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,
|
|
|
|
// Frames, seperated by CHANNEL (and PARTICIPANT) AND FRAME TYPE,
|
2020-04-24 10:56:04 +00:00
|
|
|
pub frames_out_total: IntCounterVec,
|
|
|
|
pub frames_in_total: IntCounterVec,
|
2020-04-08 14:26:42 +00:00
|
|
|
pub frames_count: IntGaugeVec,
|
|
|
|
// send Messages, seperated by STREAM (and PARTICIPANT, CHANNEL),
|
|
|
|
pub message_count: IntGaugeVec,
|
|
|
|
// send Messages bytes, seperated by STREAM (and PARTICIPANT, CHANNEL),
|
|
|
|
pub bytes_send: IntGaugeVec,
|
|
|
|
// Frames, seperated by MESSAGE (and PARTICIPANT, CHANNEL, STREAM),
|
|
|
|
pub frames_message_count: IntGaugeVec,
|
|
|
|
// TODO: queued Messages, seperated by STREAM (add PART, CHANNEL),
|
|
|
|
// queued Messages, seperated by PARTICIPANT
|
|
|
|
pub queued_count: IntGaugeVec,
|
|
|
|
// TODO: queued Messages bytes, seperated by STREAM (add PART, CHANNEL),
|
|
|
|
// queued Messages bytes, seperated by PARTICIPANT
|
|
|
|
pub queued_bytes: IntGaugeVec,
|
|
|
|
// ping calculated based on last msg seperated by PARTICIPANT
|
|
|
|
pub participants_ping: IntGaugeVec,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NetworkMetrics {
|
|
|
|
#[allow(dead_code)]
|
2020-04-24 10:56:04 +00:00
|
|
|
pub fn new() -> Result<Self, Box<dyn Error>> {
|
|
|
|
let listen_requests_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"listen_requests_total",
|
|
|
|
"shows the number of listen requests to the scheduler",
|
|
|
|
),
|
|
|
|
&["protocol"],
|
|
|
|
)?;
|
|
|
|
let connect_requests_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"connect_requests_total",
|
|
|
|
"shows the number of connect requests to the scheduler",
|
|
|
|
),
|
|
|
|
&["protocol"],
|
|
|
|
)?;
|
|
|
|
let participants_connected_total = IntCounter::with_opts(Opts::new(
|
|
|
|
"participants_connected_total",
|
2020-04-08 14:26:42 +00:00
|
|
|
"shows the number of participants connected to the network",
|
|
|
|
))?;
|
2020-04-24 10:56:04 +00:00
|
|
|
let participants_disconnected_total = IntCounter::with_opts(Opts::new(
|
|
|
|
"participants_disconnected_total",
|
|
|
|
"shows the number of participants disconnected to the network",
|
2020-04-08 14:26:42 +00:00
|
|
|
))?;
|
2020-04-24 10:56:04 +00:00
|
|
|
let channels_connected_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"channels_connected_total",
|
|
|
|
"number of all channels currently connected on the network",
|
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let channels_disconnected_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"channels_disconnected_total",
|
|
|
|
"number of all channels currently disconnected on the network",
|
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let streams_opened_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"streams_opened_total",
|
|
|
|
"number of all streams currently open on the network",
|
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
|
|
|
let streams_closed_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"streams_closed_total",
|
|
|
|
"number of all streams currently open on the network",
|
|
|
|
),
|
|
|
|
&["participant"],
|
|
|
|
)?;
|
2020-04-08 14:26:42 +00:00
|
|
|
let opts = Opts::new("network_info", "Static Network information").const_label(
|
|
|
|
"version",
|
|
|
|
&format!(
|
|
|
|
"{}.{}.{}",
|
|
|
|
&crate::types::VELOREN_NETWORK_VERSION[0],
|
|
|
|
&crate::types::VELOREN_NETWORK_VERSION[1],
|
|
|
|
&crate::types::VELOREN_NETWORK_VERSION[2]
|
|
|
|
),
|
|
|
|
);
|
|
|
|
let network_info = IntGauge::with_opts(opts)?;
|
2020-04-24 10:56:04 +00:00
|
|
|
let frames_out_total = IntCounterVec::new(
|
|
|
|
Opts::new("frames_out_total", "number of all frames send per channel"),
|
|
|
|
&["participant", "channel", "frametype"],
|
|
|
|
)?;
|
|
|
|
let frames_in_total = IntCounterVec::new(
|
|
|
|
Opts::new(
|
|
|
|
"frames_in_total",
|
|
|
|
"number of all frames received per channel",
|
|
|
|
),
|
|
|
|
&["participant", "channel", "frametype"],
|
|
|
|
)?;
|
2020-04-08 14:26:42 +00:00
|
|
|
|
2020-04-24 10:56:04 +00:00
|
|
|
let frames_count = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"frames_count",
|
|
|
|
"number of all frames send by streams on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let message_count = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"message_count",
|
|
|
|
"number of messages send by streams on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let bytes_send = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new("bytes_send", "bytes send by streams on the network"),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let frames_message_count = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"frames_message_count",
|
|
|
|
"bytes sends per message on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let queued_count = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"queued_count",
|
|
|
|
"queued number of messages by participant on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let queued_bytes = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"queued_bytes",
|
|
|
|
"queued bytes of messages by participant on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
|
|
|
let participants_ping = IntGaugeVec::new(
|
2020-04-08 14:26:42 +00:00
|
|
|
Opts::new(
|
|
|
|
"participants_ping",
|
|
|
|
"ping time to participants on the network",
|
|
|
|
),
|
|
|
|
&["channel"],
|
2020-04-24 10:56:04 +00:00
|
|
|
)?;
|
2020-04-08 14:26:42 +00:00
|
|
|
|
|
|
|
Ok(Self {
|
2020-04-24 10:56:04 +00:00
|
|
|
listen_requests_total,
|
|
|
|
connect_requests_total,
|
|
|
|
participants_connected_total,
|
|
|
|
participants_disconnected_total,
|
|
|
|
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
|
|
|
frames_out_total,
|
|
|
|
frames_in_total,
|
2020-04-08 14:26:42 +00:00
|
|
|
frames_count,
|
|
|
|
message_count,
|
|
|
|
bytes_send,
|
|
|
|
frames_message_count,
|
|
|
|
queued_count,
|
|
|
|
queued_bytes,
|
|
|
|
participants_ping,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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()))?;
|
|
|
|
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()))?;
|
|
|
|
registry.register(Box::new(self.network_info.clone()))?;
|
|
|
|
registry.register(Box::new(self.frames_out_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.frames_in_total.clone()))?;
|
|
|
|
registry.register(Box::new(self.frames_count.clone()))?;
|
|
|
|
registry.register(Box::new(self.message_count.clone()))?;
|
|
|
|
registry.register(Box::new(self.bytes_send.clone()))?;
|
|
|
|
registry.register(Box::new(self.frames_message_count.clone()))?;
|
|
|
|
registry.register(Box::new(self.queued_count.clone()))?;
|
|
|
|
registry.register(Box::new(self.queued_bytes.clone()))?;
|
|
|
|
registry.register(Box::new(self.participants_ping.clone()))?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
//pub fn _is_100th_tick(&self) -> bool {
|
|
|
|
// self.tick.load(Ordering::Relaxed).rem_euclid(100) == 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|