refactor(pinger): migrate to MetricsSender for metric dispatch
This commit is contained in:
1 file changed
+4
-11
+4
-11
@@ -1,13 +1,11 @@
|
|||||||
use crate::MeasurementType;
|
use crate::MeasurementType;
|
||||||
use crate::metrics::Metric;
|
use crate::metrics::{Metric, MetricsSender};
|
||||||
use crate::time::Time;
|
|
||||||
use crate::util::RwLockExt;
|
use crate::util::RwLockExt;
|
||||||
use icmp_socket2::socket::IcmpSocket;
|
use icmp_socket2::socket::IcmpSocket;
|
||||||
use icmp_socket2::{IcmpSocket4, Icmpv4Packet};
|
use icmp_socket2::{IcmpSocket4, Icmpv4Packet};
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use rustix::time::ClockId;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
use std::sync::mpsc::{Sender, SyncSender};
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::{io, thread};
|
use std::{io, thread};
|
||||||
@@ -55,13 +53,11 @@ pub trait PingListener {
|
|||||||
type_: MeasurementType,
|
type_: MeasurementType,
|
||||||
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
|
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
|
||||||
stats_tx: Sender<PingReply>,
|
stats_tx: Sender<PingReply>,
|
||||||
ping_metrics_tx: Option<SyncSender<Metric>>,
|
ping_metrics: MetricsSender,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let socket = &mut open_socket(type_)?;
|
let socket = &mut open_socket(type_)?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Capture current time at the start of each iteration for metric timestamps
|
|
||||||
let clock = Time::new(ClockId::Realtime);
|
|
||||||
let (pkt, sender) = match socket.rcv_from() {
|
let (pkt, sender) = match socket.rcv_from() {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
@@ -83,16 +79,13 @@ pub trait PingListener {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref tx) = ping_metrics_tx {
|
ping_metrics.send(Metric::Ping {
|
||||||
let _ = tx.try_send(Metric::Ping {
|
|
||||||
reflector: reply.reflector,
|
reflector: reply.reflector,
|
||||||
measurement_type: reply.measurement_type,
|
measurement_type: reply.measurement_type,
|
||||||
rtt: reply.rtt,
|
rtt: reply.rtt,
|
||||||
up_time: reply.up_time,
|
up_time: reply.up_time,
|
||||||
down_time: reply.down_time,
|
down_time: reply.down_time,
|
||||||
timestamp_ns: clock.as_nanos(),
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Type: {:4} | Reflector IP: {:>15} | Seq: {:5} | Current time: {:8} | Originate: {:8} | Received time: {:8} | Transmit time : {:8} | RTT: {:8} | UL time: {:5} | DL time: {:5}",
|
"Type: {:4} | Reflector IP: {:>15} | Seq: {:5} | Current time: {:8} | Originate: {:8} | Received time: {:8} | Transmit time : {:8} | RTT: {:8} | UL time: {:5} | DL time: {:5}",
|
||||||
|
|||||||
Reference in new issue
Block a user