report-basic: cpu, memory, pressure, and disk metrics
Extend the io.systemd.Basic metric families with host-level runtime metrics: cumulative per-state CPU seconds, memory in use (MemTotal minus MemAvailable), swap in use, the kernel's 10s pressure stall averages (cpu/memory/io x some/full). Partitions and stacked devices are excluded from the disk counters, since their traffic is already accounted for in the parent device. Also extend the TEST-74 report subtest with checks for the new metrics. Network metrics are not added, because the service runs with PrivateNetwork=yes, and it doesn't make sense to report stats for 'lo'. After some back-and-forth, I settled on "CPUUsage". We use this scheme of capitalization in other metric family names: "IPv4Public", "IPv6Public", IPv4AddressState", "IPv6AddressState", "OSRelease" "SMBIOS" "BootID", "CPUsOnline", "MachineID", "MachineInfo", "OSRelease", "SMBIOS.SystemManufacturer", "TPM2.Manufacturer", "TPM2.VendorString", "IOReadBytes", "IOReadOperations", "CGroup". The exception is "io.systemd.cgroup.CpuUsage". I think we should treat that one as a mistake and consider changing it to conform.
This commit is contained in:
+15
-12
@@ -127,18 +127,8 @@ static uint64_t calc_gcd64(uint64_t a, uint64_t b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
int procfs_cpu_get_usage(nsec_t *ret) {
|
||||
ProcfsCpuTicks ticks;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
r = procfs_cpu_get_ticks(&ticks);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
nsec_t procfs_ticks_to_nsec(uint64_t ticks) {
|
||||
uint64_t ticks_per_second = sysconf_clock_ticks_cached(),
|
||||
sum = ticks.user + ticks.nice + ticks.system + ticks.irq + ticks.softirq,
|
||||
gcd = calc_gcd64(NSEC_PER_SEC, ticks_per_second);
|
||||
|
||||
/* Reduce NSEC_PER_SEC/ticks_per_second first to avoid overflow of ticks * NSEC_PER_SEC, and split
|
||||
@@ -148,7 +138,20 @@ int procfs_cpu_get_usage(nsec_t *ret) {
|
||||
uint64_t a = NSEC_PER_SEC / gcd,
|
||||
b = ticks_per_second / gcd;
|
||||
|
||||
*ret = (nsec_t) (sum / b * a + DIV_ROUND_UP(sum % b * a, b));
|
||||
return ticks / b * a + DIV_ROUND_UP(ticks % b * a, b);
|
||||
}
|
||||
|
||||
int procfs_cpu_get_usage(nsec_t *ret) {
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
ProcfsCpuTicks ticks;
|
||||
r = procfs_cpu_get_ticks(&ticks);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = procfs_ticks_to_nsec(ticks.user + ticks.nice + ticks.system + ticks.irq + ticks.softirq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ int procfs_get_threads_max(uint64_t *ret);
|
||||
int procfs_tasks_set_limit(uint64_t limit);
|
||||
int procfs_tasks_get_current(uint64_t *ret);
|
||||
|
||||
nsec_t procfs_ticks_to_nsec(uint64_t ticks);
|
||||
int procfs_cpu_get_usage(nsec_t *ret);
|
||||
|
||||
typedef struct ProcfsCpuTicks {
|
||||
|
||||
Reference in New Issue
Block a user