limon_core/models/monitor/measurement.rs
1use time::OffsetDateTime;
2
3use crate::collectors::monitor::errors::CollectorError;
4
5/// Represents a single measurement performed by a monitor.
6///
7/// Each `Measurement` records the timestamp of the check, the ID of the monitor,
8/// and either the collected data or an error if the measurement failed.
9#[derive(Debug)]
10pub struct Measurement {
11 /// Unique identifier of the monitor that produced this measurement.
12 pub monitor_id: i64,
13
14 /// Unix timestamp when the measurement was taken.
15 pub timestamp: OffsetDateTime,
16
17 /// Measurement data, if the operation was successful.
18 pub data: Option<Data>,
19
20 /// Error that occurred during the measurement.
21 pub error: Option<CollectorError>,
22}
23
24/// The collected data of a measurement, which can be either a ping or HTTP measurement.
25#[derive(Debug)]
26pub enum Data {
27 /// Data collected from a ping monitor.
28 Ping(PingData),
29
30 /// Data collected from an HTTP monitor.
31 Http(HttpData),
32}
33
34/// Data returned by a ping monitor.
35///
36/// Contains timing information for DNS lookup and ICMP ping.
37#[derive(Debug, Clone)]
38#[cfg_attr(test, derive(Default))]
39pub struct PingData {
40 /// Time in milliseconds spent on DNS resolution.
41 pub dns: f32,
42
43 /// Time in milliseconds spent performing the ping.
44 pub rtt: f32,
45}
46
47/// Data returned by an HTTP monitor.
48///
49/// Contains timing information for DNS resolution, TCP connection, TLS handshake,
50/// and data transfer.
51#[derive(Debug, Clone)]
52#[cfg_attr(test, derive(Default))]
53pub struct HttpData {
54 /// Time in milliseconds spent on DNS resolution.
55 pub dns: f32,
56
57 /// Time in milliseconds spent establishing the TCP connection.
58 pub tcp: f32,
59
60 /// Time in milliseconds spent performing the TLS handshake
61 pub tls: f32,
62
63 /// Time to first byte in milliseconds
64 pub ttfb: f32,
65
66 /// Time in milliseconds spent transferring the HTTP response body.
67 pub transfer: f32,
68}