Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: infra/services/sysmon/system_metrics.py

Issue 2106953006: adding os metrics (os name and version) being collected every hour (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: adding os metrics (os name and version) being collected every hour Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: infra/services/sysmon/system_metrics.py
diff --git a/infra/services/sysmon/system_metrics.py b/infra/services/sysmon/system_metrics.py
index 9b2e4382f4275a8a3ba63b4ee85dc696825a39a0..1bdab2ace16f503d8ab31e2fb4d0b34e3ff52215 100644
--- a/infra/services/sysmon/system_metrics.py
+++ b/infra/services/sysmon/system_metrics.py
@@ -5,6 +5,8 @@
import errno
import os
import logging
+import platform
+import sys
import time
import psutil
@@ -83,7 +85,23 @@ load_average = ts_mon.FloatMetric('dev/proc/load_average',
# It is important to gather this metric right before the flush.
unix_time = ts_mon.GaugeMetric('dev/unix_time',
description='Number of milliseconds since epoch '
- 'based on local machine clock.')
+ 'based on local machine clock.')
+
+os_name = ts_mon.StringMetric('proc/os/name',
+ description='OS name on the machine '
+ 'metric:hostname.')
+
+os_version = ts_mon.StringMetric('proc/os/version',
+ description='OS version on the machine '
+ 'metric:hostname.')
+
+os_arch = ts_mon.StringMetric('proc/os/arch',
+ description='OS architecture on this '
+ 'machine')
+
+python_arch = ts_mon.StringMetric('proc/python/arch',
+ description='python userland '
+ 'architecture on this machine')
def get_uptime():
@@ -165,6 +183,56 @@ def get_net_info():
# exception.
logging.error(str(ex))
dsansome 2016/07/01 04:30:56 Add an extra \n here
chrishall 2016/07/01 04:53:56 Done.
+def get_os_info():
+ os_name_data = ""
dsansome 2016/07/01 04:30:56 We seem to use single quotes elsewhere in this fil
chrishall 2016/07/01 04:53:56 Done.
+ os_version_data = ""
+
+ os_name_data = platform.system().lower()
+ if "windows" in os_name_data:
+ os_name_data = "windows"
+ # os_release will be something like '7', 'vista', or 'xp'
+ os_version_data = platform.release()
+
+ elif "linux" in os_name_data:
+ # will return something like ('Ubuntu', '14.04', 'trusty')
+ dist_info_data = platform.dist()
+ os_name_data = dist_info_data[0]
+ os_version_data = dist_info_data[1]
+
+ # on mac platform.system() reports 'darwin'
+ else:
+ # this tuple is only populated on mac systems
+ mac_ver_data = platform.mac_ver()
+ # [0] will be '10.11.5' or similar on a valid mac or will be '' on a
+ # non-mac
+ os_version_data = mac_ver_data[0]
+ if os_version_data:
+ # we found a valid mac
+ os_name_data = "mac"
+ else :
+ # not a mac, unable to find platform information, reset
+ os_name_data = ""
+ os_version_data = ""
+
+ # normalize to lower case
+ os_name_data = os_name_data.lower()
+ os_version_data = os_version_data.lower()
+
+ python_arch_data = "32"
+ if sys.maxsize > 2**32:
+ python_arch_data = "64"
+
+ # construct metrics
+ os_name.set(os_name_data)
+ os_version.set(os_version_data)
+ os_arch(platform.machine())
+ python_arch(python_arch_data)
+
+
+def clear_os_info():
+ os_name.reset()
+ os_version.reset()
+
def get_proc_info():
procs = psutil.pids()

Powered by Google App Engine
This is Rietveld 408576698