frigate: clean up process cmdlines in cpu stats
The process cmdline gets read from /proc/pid/cmdline which is a memory allocation with a rounded up size. The psutil library looks for a Null-terminated string, but apparently not all cmdlines have that.
This commit is contained in:
@@ -98,6 +98,8 @@ python3Packages.buildPythonApplication rec {
|
||||
})
|
||||
# https://github.com/microsoft/onnxruntime/issues/26717
|
||||
./onnxruntime-compat.patch
|
||||
# https://github.com/blakeblackshear/frigate/pull/22089
|
||||
./proc-cmdline-strip.patch
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
Strip trailing whitespace from process commandlines. This is annoying for exact
|
||||
process matches against Prometheus labels.
|
||||
|
||||
https://github.com/blakeblackshear/frigate/pull/22089
|
||||
|
||||
diff --git a/frigate/util/services.py b/frigate/util/services.py
|
||||
index b31a7eea3..f1e8f0f5f 100644
|
||||
--- a/frigate/util/services.py
|
||||
+++ b/frigate/util/services.py
|
||||
@@ -118,7 +118,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
||||
pid = str(process.info["pid"])
|
||||
try:
|
||||
cpu_percent = process.info["cpu_percent"]
|
||||
- cmdline = process.info["cmdline"]
|
||||
+ cmdline = " ".join(process.info["cmdline"]).rstrip()
|
||||
|
||||
with open(f"/proc/{pid}/stat", "r") as f:
|
||||
stats = f.readline().split()
|
||||
@@ -152,7 +152,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
||||
"cpu": str(cpu_percent),
|
||||
"cpu_average": str(round(cpu_average_usage, 2)),
|
||||
"mem": f"{mem_pct}",
|
||||
- "cmdline": clean_camera_user_pass(" ".join(cmdline)),
|
||||
+ "cmdline": clean_camera_user_pass(cmdline),
|
||||
}
|
||||
except Exception:
|
||||
continue
|
||||
Reference in New Issue
Block a user