Skip to main content

resource_tracker/metrics/
host.rs

1use serde::{Deserialize, Serialize};
2
3/// Machine-level host properties collected once at startup.
4/// All fields are optional; collection failure is silently swallowed.
5/// Used in the Sentinel API registration payload (Section 9.1).
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct HostInfo {
8    /// AWS: `/sys/class/dmi/id/board_asset_tag`; fallback: `/etc/machine-id`.
9    pub host_id: Option<String>,
10    /// Hostname from `gethostname(3)`.
11    #[serde(rename = "host_hostname")]
12    pub host_name: Option<String>,
13    /// First non-loopback IPv4 address from `getifaddrs(3)`.
14    pub host_ip: Option<String>,
15    /// `"dedicated"` or `"shared"`. Heuristic TBD; currently always `None`.
16    #[serde(rename = "host_server_allocation")]
17    pub host_allocation: Option<String>,
18    /// Count of logical CPUs from `/proc/cpuinfo` processor entries.
19    pub host_vcpus: Option<u32>,
20    /// CPU model string from `/proc/cpuinfo`.
21    pub host_cpu_model: Option<String>,
22    /// Total physical RAM: `MemTotal / 1024` from `/proc/meminfo`.
23    pub host_memory_mib: Option<u64>,
24    /// Name of the first detected GPU/NPU/TPU.
25    pub host_gpu_model: Option<String>,
26    /// Count of detected GPUs.
27    pub host_gpu_count: Option<u32>,
28    /// Sum of `vram_total_bytes / 1_048_576` across all GPUs.
29    /// Serialized as `host_gpu_memory_mib` to match the Sentinel API field name.
30    #[serde(rename = "host_gpu_memory_mib")]
31    pub host_gpu_vram_mib: Option<u64>,
32    /// Sum of block device capacities in GB (non-loop, non-ram devices).
33    pub host_storage_gb: Option<f64>,
34}
35
36/// Cloud instance metadata collected via IMDS probes at startup.
37/// All fields are `None` on non-cloud hosts or when the IMDS probe times out.
38/// Used in the Sentinel API registration payload (Section 9.1).
39#[derive(Debug, Clone, Default, Serialize, Deserialize)]
40pub struct CloudInfo {
41    /// Cloud provider identifier.
42    pub cloud_vendor_id: Option<String>,
43    /// Cloud account ID (usually not available from metadata service).
44    pub cloud_account_id: Option<String>,
45    /// Cloud region or location string for the active provider (e.g. AWS region, GCP
46    /// region derived from zone, Azure `location`, Hetzner `region`, UpCloud `region`).
47    pub cloud_region_id: Option<String>,
48    /// Cloud availability zone.
49    pub cloud_zone_id: Option<String>,
50    /// Instance type / size / flavor (machine type on GCP, `vmSize` on Azure).
51    /// UpCloud metadata does not expose a type; this field stays `None` there.
52    pub cloud_instance_type: Option<String>,
53}