From 2eab8f436a0f757a05be155b3e91ce7c25ffd705 Mon Sep 17 00:00:00 2001 From: Robert Oleynik Date: Tue, 20 Aug 2024 10:52:27 +0200 Subject: [PATCH] metrics-pusher allow partial metric updates on permission denied --- metrics-pusher/README.md | 4 +++- metrics-pusher/monitor.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/metrics-pusher/README.md b/metrics-pusher/README.md index 352bf77..a514c58 100644 --- a/metrics-pusher/README.md +++ b/metrics-pusher/README.md @@ -5,7 +5,7 @@ Run using docker: ```sh -docker run --cap-add "CAP_SYS_PTRACE" \ +docker run \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /proc:/host/proc:ro \ -e INSTANCE_NAME="foo" \ @@ -18,6 +18,8 @@ docker run --cap-add "CAP_SYS_PTRACE" \ scalableminds/metrics-pusher ``` +> *Note:* If the monitor fails with permission denied and disk read and write is 0, then add `--cap-add CAP_SYS_PTRACE` to enable necessary capabilities. + This will scrape all specified endpoints and containers using the internal [Container Exporter](#container-exporter). ## Configuration diff --git a/metrics-pusher/monitor.py b/metrics-pusher/monitor.py index caa9ad5..8c2bdea 100644 --- a/metrics-pusher/monitor.py +++ b/metrics-pusher/monitor.py @@ -86,16 +86,17 @@ def scrape(proc_path): stats = [int(s) for s in f.read().split(")")[1][3:].split(" ")] f.close() + _used_mem += stats[rss] + _cpu_user += stats[utime] + stats[cutime] + _cpu_kernel += stats[stime] + stats[cstime] + _number_threads += stats[num_threads] + # https://www.kernel.org/doc/html/latest/filesystems/proc.html#proc-pid-io-display-the-io-accounting-fields f = open(f"{proc_path}/{pid}/io", "r") rchar = int(f.readline().split(" ")[1]) wchar = int(f.readline().split(" ")[1]) f.close() - _used_mem += stats[rss] - _cpu_user += stats[utime] + stats[cutime] - _cpu_kernel += stats[stime] + stats[cstime] - _number_threads += stats[num_threads] _disk_read += rchar _disk_write += wchar except Exception as e: