Skip to content

Commit

Permalink
fix: Skip IO counter metric on permission denied
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzWeber0 committed Feb 13, 2025
1 parent 76d3a8c commit ddec459
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions remote/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def collect(self) -> t.Iterable[prometheus_client.Metric]:
[process.name()], process.memory_info().rss
)

io_counters = process.io_counters()
try:
io_counters = process.io_counters()
except psutil.AccessDenied:
io_counters = None

if io_counters:
process_io_counters_metric.add_metric(
[process.name(), "read"], io_counters.read_bytes
Expand All @@ -129,9 +133,12 @@ def collect(self) -> t.Iterable[prometheus_client.Metric]:
)

if hasattr(process, "num_fds"):
process_open_fds_metric.add_metric(
[process.name()], process.num_fds()
)
try:
process_open_fds_metric.add_metric(
[process.name()], process.num_fds()
)
except psutil.AccessDenied:
pass

yield process_cpu_percent_metric
yield process_memory_usage_metric
Expand Down

0 comments on commit ddec459

Please sign in to comment.