extend network of incomming TCP metrics and failed handshake metric

This commit is contained in:
Marcel Märtens 2021-03-27 16:27:59 +01:00
parent 88b191dbbb
commit 6a95fb6b74
2 changed files with 33 additions and 3 deletions

View File

@ -9,6 +9,8 @@ use std::error::Error;
pub struct NetworkMetrics {
pub listen_requests_total: IntCounterVec,
pub connect_requests_total: IntCounterVec,
pub incoming_connections_total: IntCounterVec,
pub failed_handshakes_total: IntCounter,
pub participants_connected_total: IntCounter,
pub participants_disconnected_total: IntCounter,
// channel id's, seperated by PARTICIPANT, max 5
@ -44,6 +46,17 @@ impl NetworkMetrics {
),
&["protocol"],
)?;
let incoming_connections_total = IntCounterVec::new(
Opts::new(
"incoming_connections_total",
"Shows the number of external requests to the scheduler",
),
&["protocol"],
)?;
let failed_handshakes_total = IntCounter::with_opts(Opts::new(
"failed_handshakes_total",
"Shows the number of failed handshakes",
))?;
let participants_connected_total = IntCounter::with_opts(Opts::new(
"participants_connected_total",
"Shows the number of participants connected to the network",
@ -110,6 +123,8 @@ impl NetworkMetrics {
Ok(Self {
listen_requests_total,
connect_requests_total,
incoming_connections_total,
failed_handshakes_total,
participants_connected_total,
participants_disconnected_total,
participants_channel_ids,
@ -125,6 +140,8 @@ impl NetworkMetrics {
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.incoming_connections_total.clone()))?;
registry.register(Box::new(self.failed_handshakes_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.participants_channel_ids.clone()))?;
@ -137,6 +154,11 @@ impl NetworkMetrics {
Ok(())
}
pub(crate) fn connect_requests_cache(&self, protocol: &ProtocolAddr) -> prometheus::IntCounter {
self.incoming_connections_total
.with_label_values(&[protocol_name(protocol)])
}
pub(crate) fn channels_connected(&self, remote_p: &str, no: usize, cid: Cid) {
self.channels_connected_total
.with_label_values(&[remote_p])

View File

@ -384,6 +384,8 @@ impl Scheduler {
s2a_listen_result_s: oneshot::Sender<io::Result<()>>,
) {
trace!(?addr, "Start up channel creator");
#[cfg(feature = "metrics")]
let mcache = self.metrics.connect_requests_cache(&addr);
match addr {
ProtocolAddr::Tcp(addr) => {
let listener = match net::TcpListener::bind(addr).await {
@ -395,7 +397,7 @@ impl Scheduler {
info!(
?addr,
?e,
"Tcp bind error durin listener startup"
"Tcp bind error during listener startup"
);
s2a_listen_result_s.send(Err(e)).unwrap();
return;
@ -414,8 +416,10 @@ impl Scheduler {
continue;
},
};
info!("Accepting Tcp from: {}", remote_addr);
#[cfg(feature = "metrics")]
mcache.inc();
let cid = self.channel_ids.fetch_add(1, Ordering::Relaxed);
info!(?remote_addr, ?cid, "Accepting Tcp from");
self.init_protocol(Protocols::new_tcp(stream, cid, Arc::clone(&self.protocol_metrics)), cid, None, true)
.await;
}
@ -433,8 +437,10 @@ impl Scheduler {
} {
let (remote_to_local_s, remote_to_local_r) = mpsc::channel(Self::MPSC_CHANNEL_BOUND);
local_remote_to_local_s.send(remote_to_local_s).unwrap();
info!(?addr, "Accepting Mpsc from");
#[cfg(feature = "metrics")]
mcache.inc();
let cid = self.channel_ids.fetch_add(1, Ordering::Relaxed);
info!(?addr, ?cid, "Accepting Mpsc from");
self.init_protocol(Protocols::new_mpsc(local_to_remote_s, remote_to_local_r, cid, Arc::clone(&self.protocol_metrics)), cid, None, true)
.await;
}
@ -650,6 +656,8 @@ impl Scheduler {
},
Err(e) => {
debug!(?cid, ?e, "Handshake from a new connection failed");
#[cfg(feature = "metrics")]
metrics.failed_handshakes_total.inc();
if let Some(pid_oneshot) = s2a_return_pid_s {
// someone is waiting with `connect`, so give them their Error
trace!(?cid, "returning the Err to api who requested the connect");