[sysmon] Fix autoserv process counting
1. Fix oversight of shebang scripts keeping their command name.
2. Don’t count forked autoserv process
3. The venv is using a different version of psutil with different API.
BUG=chromium:659308
TEST=Run sysmon on test drone
Change-Id: I892a981868246b3ea2564aa147b5613c1c17885d
Reviewed-on: https://chromium-review.googlesource.com/405775
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/scripts/sysmon/system_metrics.py b/scripts/sysmon/system_metrics.py
index d657ecf..3d1778f 100644
--- a/scripts/sysmon/system_metrics.py
+++ b/scripts/sysmon/system_metrics.py
@@ -307,7 +307,7 @@
autoserv_count = 0
total = 0
for proc in psutil.process_iter():
- if _is_autoserv_proc(proc):
+ if _is_parent_autoserv(proc):
autoserv_count += 1
total += 1
logging.debug('autoserv_count: %s', autoserv_count)
@@ -315,10 +315,17 @@
_proc_count_metric.set(total)
-def _is_autoserv_proc(proc):
- return (
- proc.name == 'python'
- and '/usr/local/autotest/server/autoserv' in proc.cmdline)
+def _is_parent_autoserv(proc):
+ """Return whether proc is a parent (not forked) autoserv process."""
+ return _is_autoserv(proc) and not _is_autoserv(proc.parent())
+
+
+def _is_autoserv(proc):
+ """Return whether proc is an autoserv process."""
+ # This relies on the autoserv script being run directly. The script should
+ # be named autoserv exactly and start with a shebang that is /usr/bin/python,
+ # NOT /bin/env
+ return proc.name() == 'autoserv'
def get_load_avg():