diff options
| author | Hazel Atkinson <yellowsink@riseup.net> | 2025-04-07 16:01:35 +0100 |
|---|---|---|
| committer | Hazel Atkinson <yellowsink@riseup.net> | 2025-04-07 16:01:35 +0100 |
| commit | beb6d6feb581b60c98b461c11b92d8a6708c91d8 (patch) | |
| tree | d5dee95ac3f74baad00efe85bcb208a83c69fd55 | |
| parent | cd5fbac13f68d2e054632570bb3520f9a3ff8e42 (diff) | |
| download | containerspy-beb6d6feb581b60c98b461c11b92d8a6708c91d8.tar.gz containerspy-beb6d6feb581b60c98b461c11b92d8a6708c91d8.tar.bz2 containerspy-beb6d6feb581b60c98b461c11b92d8a6708c91d8.zip | |
[wip] im confused by memory
| -rw-r--r-- | README.md | 12 | ||||
| -rw-r--r-- | src/stats_task.rs | 43 |
2 files changed, 53 insertions, 2 deletions
@@ -65,6 +65,13 @@ http://localhost:9090/api/v1/otlp/v1/metrics as your endpoint, swapping `localho ## Supported metrics +!!! CONTAINERSPY DOES NOT SUPPORT CGROUPS V1 !!! +*Most* RAM metrics will be unavailable on cgoups v1 and any v1-only metrics are excluded. +ContainerSpy only officially supports Windows and Linux on cgroups v2. It will, however, not break on cgroups v1 hosts +and should just have missing metrics. +Yes, I know that implementing RAM metrics for cgroups is totally possible, and in fact more data is available in many +cases, but I have no system to test on, and you really should be using v2 by now. + This is intended to be a dropin replacement for cAdvisor, which lists its supported metrics [here](https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md). @@ -112,3 +119,8 @@ The list of known omitted metrics are: | `container_hugetlb_failcnt` | Not reported by Docker Engine API | | `container_hugetlb_max_usage_bytes` | Not reported by Docker Engine API | | `container_hugetlb_usage_bytes` | Not reported by Docker Engine API | +| `container_llc_occupancy_bytes` | Not reported by Docker Engine API | +| `container_memory_bandwidth_bytes` | Not reported by Docker Engine API | +| `container_memory_bandwidth_local_bytes` | Not reported by Docker Engine API | +... +| `container_memory_max_usage_bytes` | Only reported on cgroups v1 hosts |
\ No newline at end of file diff --git a/src/stats_task.rs b/src/stats_task.rs index 8b82373..47e93e2 100644 --- a/src/stats_task.rs +++ b/src/stats_task.rs @@ -1,5 +1,5 @@ use std::mem::MaybeUninit; -use bollard::container::{BlkioStatsEntry, StatsOptions}; +use bollard::container::{BlkioStatsEntry, MemoryStatsStats, MemoryStatsStatsV1, StatsOptions}; use bollard::models::ContainerSummary; use bollard::Docker; use opentelemetry::metrics::MeterProvider; @@ -211,7 +211,46 @@ pub fn launch_stats_task( } meter_container_last_seen.record(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), shared_labels); - } else { + + // cgroups values references: + // - https://github.com/docker/cli/blob/91cbde67/cli/command/container/stats_helpers.go#L230-L231 + // - https://github.com/google/cadvisor/blob/f6e31a3c/info/v1/container.go#L389 (yes, v1, roll w it) + // - https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html + + if let Some(all_usage) = stats.memory_stats.usage { + if cfg!(windows) { + // todo + // i have no way to test cgroups v2 so only work on v1 - see readme for more info + } else if let Some(MemoryStatsStats::V2(v2stats)) = stats.memory_stats.stats { + // container_memory_cache + + + // container_memory_failcnt only on cgroups v1 + + // container_memory_failures_total + v2stats.pgfault; // label failure_type=pgfault + v2stats.pgmajfault; // label failure_type=pgmajfault + + // container_memory_mapped_file + v2stats.file; // includes tmpfs + + // container_memory_max_usage_bytes only on cgroups v1 + + // container_memory_migrate + + + // container_memory_numa_pages omitted cause its hard :< + + // container_memory_rss: may need recalcing + + // container_memory_swap: can't get + + // container_memory_usage_bytes: how? + + // container_memory_working_set_bytes: not reported + } + } + } else { // failed to get stats, log as such: // TODO: use json logging or syslog so loki can understand this lol println!( |
