using System;
using Newtonsoft.Json;
namespace PSProxmoxVE.Core.Models.Nodes;
///
/// Represents detailed status information for a single Proxmox VE node,
/// as returned by the /nodes/{node}/status endpoint.
///
public class PveNodeStatus
{
///
/// The name of the node.
///
[JsonProperty("node")]
public string Node { get; set; } = string.Empty;
///
/// The current status of the node (e.g., "online" or "offline").
///
[JsonProperty("status")]
public string Status { get; set; } = string.Empty;
///
/// The total number of CPU cores available on the node.
///
[JsonProperty("maxcpu")]
public int? CpuCount { get; set; }
///
/// Total memory in bytes available on the node.
///
[JsonProperty("maxmem")]
public long? MemoryTotal { get; set; }
///
/// Memory currently in use on the node, in bytes.
///
[JsonProperty("mem")]
public long? MemoryUsed { get; set; }
///
/// Node uptime in seconds.
///
[JsonProperty("uptime")]
public long? Uptime { get; set; }
///
/// The version of Proxmox VE running on the node.
///
[JsonProperty("pveversion")]
public string? PveVersion { get; set; }
///
/// The Linux kernel version running on the node.
///
[JsonProperty("kversion")]
public string? KernelVersion { get; set; }
///
/// The 1-minute, 5-minute, and 15-minute load averages for the node.
///
[JsonProperty("loadavg")]
public double[]? LoadAverage { get; set; }
///
/// Total root filesystem size in bytes.
///
[JsonProperty("rootfs.total")]
public long? DiskTotal { get; set; }
///
/// Used root filesystem space in bytes.
///
[JsonProperty("rootfs.used")]
public long? DiskUsed { get; set; }
///
/// Current CPU utilization as a fraction between 0.0 and 1.0.
///
[JsonProperty("cpu")]
public double? CpuUsage { get; set; }
///
/// Memory utilization as a percentage (0–100), computed from MemoryUsed / MemoryTotal.
///
[Newtonsoft.Json.JsonIgnore]
public double? MemoryUsage =>
MemoryTotal.HasValue && MemoryTotal.Value > 0 && MemoryUsed.HasValue
? (double)MemoryUsed.Value / MemoryTotal.Value * 100.0
: null;
///
/// Total swap space in bytes.
///
[JsonProperty("swap.total")]
public long? SwapTotal { get; set; }
///
/// Used swap space in bytes.
///
[JsonProperty("swap.used")]
public long? SwapUsed { get; set; }
///
/// Total bytes received over the network since boot.
///
[JsonProperty("netin")]
public long? NetworkIn { get; set; }
///
/// Total bytes transmitted over the network since boot.
///
[JsonProperty("netout")]
public long? NetworkOut { get; set; }
///
public override string ToString()
{
var memUsedMb = MemoryUsed.HasValue ? $"{MemoryUsed.Value / 1024 / 1024} MB" : "N/A";
var memTotalMb = MemoryTotal.HasValue ? $"{MemoryTotal.Value / 1024 / 1024} MB" : "N/A";
var cpuPct = CpuUsage.HasValue ? $"{CpuUsage.Value * 100:F1}%" : "N/A";
var diskUsedGb = DiskUsed.HasValue ? $"{DiskUsed.Value / 1024 / 1024 / 1024} GB" : "N/A";
var diskTotalGb = DiskTotal.HasValue ? $"{DiskTotal.Value / 1024 / 1024 / 1024} GB" : "N/A";
var uptimeStr = Uptime.HasValue ? TimeSpan.FromSeconds(Uptime.Value).ToString(@"d\.hh\:mm\:ss") : "N/A";
return $"Node: {Node} | Status: {Status} | CPU: {cpuPct} | "
+ $"Mem: {memUsedMb}/{memTotalMb} ({MemoryUsage:F1}%) | "
+ $"Disk: {diskUsedGb}/{diskTotalGb} | Uptime: {uptimeStr}";
}
}