add more metrics

main
(on company time) 2022-08-01 12:22:30 -05:00
parent 77f842485f
commit c30747d954
1 changed files with 36 additions and 6 deletions

View File

@ -232,9 +232,41 @@ async fn metrics (
{
let mut s = String::with_capacity (4 * 1_024);
s.push_str ("# HELP forty_two Forty-two\n");
s.push_str ("# TYPE forty_two counter\n");
s.push_str ("forty_two 42\n");
let mut push_metric = |name, help, kind, value| {
if let Some (help) = help {
s.push_str (format! ("# HELP {} {}\n", name, help).as_str ());
}
s.push_str (format! ("# TYPE {} {}\n", name, kind).as_str ());
s.push_str (format! ("{} {}\n", name, value).as_str ());
};
let request_rendezvous_count = {
let g = state.request_rendezvous.lock ().await;
g.len ()
};
let server_status_count;
let connected_server_count;
let now = Utc::now ();
{
let g = state.server_status.lock ().await;
server_status_count = g.len ();
connected_server_count = g.iter ()
.filter (|(_, s)| now - s.last_seen < chrono::Duration::seconds (60))
.count ();
}
let response_rendezvous_count = {
let g = state.response_rendezvous.read ().await;
g.len ()
};
push_metric ("request_rendezvous_count", None, "gauge", request_rendezvous_count.to_string ());
push_metric ("server_status_count", None, "gauge", server_status_count.to_string ());
push_metric ("connected_server_count", None, "gauge", connected_server_count.to_string ());
push_metric ("response_rendezvous_count", None, "gauge", response_rendezvous_count.to_string ());
#[cfg (target_os = "linux")]
{
@ -242,9 +274,7 @@ async fn metrics (
.ok ()
.and_then (|s| get_rss_from_status (s.as_str ()))
{
s.push_str ("# HELP relay_vm_rss VmRSS of the relay process, in kB\n");
s.push_str ("# TYPE relay_vm_rss gauge\n");
s.push_str (format! ("relay_vm_rss {}\n", rss).as_str ());
push_metric ("relay_vm_rss", Some ("VmRSS of the relay process, in kB"), "gauge", rss.to_string ());
}
}