Track IP address as well as domain in a label

This commit is contained in:
Jeremy Wall 2021-01-05 20:37:44 -05:00
parent 41f74fd637
commit 762fdb8bd5
2 changed files with 9 additions and 9 deletions

View File

@ -68,10 +68,10 @@ pub fn start_echo_loop(
r.elapsed.as_millis(), r.elapsed.as_millis(),
); );
ping_counter ping_counter
.with(&prometheus::labels! {"result" => "ok", "domain" => domain_name}) .with(&prometheus::labels! {"result" => "ok", "domain" => domain_name, "ip" => &resolved})
.inc(); .inc();
ping_latency_guage ping_latency_guage
.with(&prometheus::labels! {"domain" => domain_name}) .with(&prometheus::labels! {"domain" => domain_name, "ip" => &resolved})
.set(r.elapsed.as_millis() as i64); .set(r.elapsed.as_millis() as i64);
} }
EkkoResponse::UnreachableResponse((_, ref _code)) => { EkkoResponse::UnreachableResponse((_, ref _code)) => {
@ -79,7 +79,7 @@ pub fn start_echo_loop(
error!("{:?}", r); error!("{:?}", r);
info!("Restarting our sender"); info!("Restarting our sender");
ping_counter ping_counter
.with(&prometheus::labels! {"result" => "unreachable", "domain" => domain_name}) .with(&prometheus::labels! {"result" => "unreachable", "domain" => domain_name, "ip" => &resolved})
.inc(); .inc();
let mut new_sender = Ekko::with_target(&resolved).unwrap(); let mut new_sender = Ekko::with_target(&resolved).unwrap();
std::mem::swap(&mut sender, &mut new_sender); std::mem::swap(&mut sender, &mut new_sender);
@ -87,21 +87,21 @@ pub fn start_echo_loop(
} }
EkkoResponse::ExceededResponse(_) => { EkkoResponse::ExceededResponse(_) => {
ping_counter ping_counter
.with(&prometheus::labels! {"result" => "timeout", "domain" => domain_name}) .with(&prometheus::labels! {"result" => "timeout", "domain" => domain_name, "ip" => &resolved})
.inc(); .inc();
} }
_ => { _ => {
ping_counter ping_counter
.with(&prometheus::labels! {"result" => "err", "domain" => domain_name}) .with(&prometheus::labels! {"result" => "err", "domain" => domain_name, "ip" => &resolved})
.inc(); .inc();
error!("{:?}", r); error!("{:?}", r);
} }
}, },
Err(e) => { Err(e) => {
ping_counter ping_counter
.with(&prometheus::labels! {"result" => "err", "domain" => domain_name}) .with(&prometheus::labels! {"result" => "err", "domain" => domain_name, "ip" => &resolved})
.inc(); .inc();
error!("Ping send to {} failed: {:?}, Trying again later", domain_name, e); error!("Ping send to domain: {} address: {} failed: {:?}, Trying again later", domain_name, &resolved, e);
} }
}; };
std::thread::sleep(Duration::from_secs(3)); std::thread::sleep(Duration::from_secs(3));

View File

@ -118,10 +118,10 @@ fn main() -> anyhow::Result<()> {
) )
.unwrap(); .unwrap();
let ping_latency_vec = let ping_latency_vec =
IntGaugeVec::new(Opts::new("ping_latency", "ICMP Ping latency"), &["domain"]).unwrap(); IntGaugeVec::new(Opts::new("ping_latency", "ICMP Ping latency"), &["domain", "ip"]).unwrap();
let ping_counter_vec = CounterVec::new( let ping_counter_vec = CounterVec::new(
Opts::new("ping_counter", "Ping Request Counter"), Opts::new("ping_counter", "Ping Request Counter"),
&["result", "domain"], &["result", "domain", "ip"],
) )
.unwrap(); .unwrap();
r.register(Box::new(stun_counter_vec.clone())) r.register(Box::new(stun_counter_vec.clone()))