Skip to content

Commit

Permalink
metrics-pusher allow partial metric updates on permission denied
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-oleynik committed Aug 20, 2024
1 parent cc36479 commit 2eab8f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion metrics-pusher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions metrics-pusher/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2eab8f4

Please sign in to comment.