An NVIDIA DGX node exposes cumulative CPU counters in /proc/stat and memory values in /proc/meminfo. Given ordered Linux metric snapshots, calculate the CPU utilization and memory utilization for each interval between consecutive snapshots.
Implement collect_linux_metrics(snapshots), where snapshots is a list of dictionaries. Each dictionary contains:
timestamp: an integer or float identifying the sample time.stat: the /proc/stat text containing a line beginning with cpu followed by cumulative counters.meminfo: the /proc/meminfo text containing MemTotal and MemAvailable, both measured in kB.Return a list of dictionaries, one for every snapshot after the first. Each result must contain the later snapshot's timestamp, cpu_percent, and memory_percent. Round both percentages to two decimal places.
CPU utilization is the percentage of elapsed CPU time that was not idle. Treat both idle and iowait as idle time. Memory utilization is (MemTotal - MemAvailable) / MemTotal * 100.
def collect_linux_metrics(snapshots):