laminar
laminar copied to clipboard
Implement support for laminar metrics.
Task Description
Laminar currently does not provide much internal information to the outside. To solve this we need to have metrics, and a way to integrate this easily.
Task TODO
- [ ] Think of metrics we can collect
- [ ] Are there crates that can help us with this
- [ ] Think of design to move metrics into our current API without too many changes.
My idea to implement this is the following:
- We can make
SocketEventhave an entry forMetrics:
pub enum SocketEvent {
/// A packet has been received from a client.
Packet(Packet),
/// A new client connects. Clients are uniquely identified by the ip:port combination at this layer.
Connect(SocketAddr),
/// A client disconnects. This is generated from the server-side intentionally disconnecting a client,
/// or it could be from the client disconnecting.
Disconnect(SocketAddr),
/// This is generated if the server has not seen traffic from a client after a configurable amount of time.
Timeout(SocketAddr),
/// Metrics of lamianar
Metrics(Metrics)
}
- Example of metrics we can gather: source
pub struct Metrics {
counters: [u64; DataPoint::Length as usize],
packet_loss: f32,
sent_bandwidth_kbps: f32,
received_bandwidth_kbps: f32,
acked_bandwidth_kbps: f32,
// Config values to tweak the calculated fields
bandwidth_smoothing_factor: f32,
}
-
Send metrics back to the user Because we created a Metrics entry for the
SocketEventwe can send it on the EventChannel -
Add a config entry
- Metrics Enabled; whether we should calculate metrics or not.
- Metrics send interval; send on event channel.
It seems like this could potentially be combined with:
- Expose active connections (https://github.com/amethyst/laminar/issues/271)
- Expose RTT information (https://github.com/amethyst/laminar/issues/268)
I might try and roll all of those into a single interface and PR.
Should metrics be on an event, or on an on-demand poll?
Thats a good question. I tended to see them as an event like my comment above shows.