➕ add more metrics
parent
77f842485f
commit
c30747d954
|
@ -232,9 +232,41 @@ async fn metrics (
|
||||||
{
|
{
|
||||||
let mut s = String::with_capacity (4 * 1_024);
|
let mut s = String::with_capacity (4 * 1_024);
|
||||||
|
|
||||||
s.push_str ("# HELP forty_two Forty-two\n");
|
let mut push_metric = |name, help, kind, value| {
|
||||||
s.push_str ("# TYPE forty_two counter\n");
|
if let Some (help) = help {
|
||||||
s.push_str ("forty_two 42\n");
|
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")]
|
#[cfg (target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
@ -242,9 +274,7 @@ async fn metrics (
|
||||||
.ok ()
|
.ok ()
|
||||||
.and_then (|s| get_rss_from_status (s.as_str ()))
|
.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");
|
push_metric ("relay_vm_rss", Some ("VmRSS of the relay process, in kB"), "gauge", rss.to_string ());
|
||||||
s.push_str ("# TYPE relay_vm_rss gauge\n");
|
|
||||||
s.push_str (format! ("relay_vm_rss {}\n", rss).as_str ());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue