Chromium Code Reviews| 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..380087bab3d6392e93fcc202aba78f800ee65267 100644 |
| --- a/infra/services/sysmon/system_metrics.py |
| +++ b/infra/services/sysmon/system_metrics.py |
| @@ -5,6 +5,7 @@ |
| import errno |
| import os |
| import logging |
| +import platform |
| import time |
| import psutil |
| @@ -85,6 +86,13 @@ unix_time = ts_mon.GaugeMetric('dev/unix_time', |
| description='Number of milliseconds since epoch ' |
| 'based on local machine clock.') |
| +metric_os_name = ts_mon.StringMetric('proc/os/name', |
| + description='OS name on the machine ' |
|
dsansome
2016/06/29 06:21:29
Align these lines with the ' above
chrishall
2016/07/01 04:27:59
Done.
|
| + 'metric:hostname.') |
| + |
| +metric_os_version = ts_mon.StringMetric('proc/os/version', |
| + description='OS version on the machine ' |
| + 'metric:hostname.') |
| def get_uptime(): |
| uptime.set(int(time.time() - START_TIME)) |
| @@ -165,6 +173,50 @@ def get_net_info(): |
| # exception. |
| logging.error(str(ex)) |
| +def get_os_info(): |
|
dsansome
2016/06/29 06:21:29
Please add tests for this to test/system_metrics_t
chrishall
2016/07/01 04:27:59
Done.
|
| + os_name = "" |
| + os_version = "" |
| + |
| + os_name = platform.system().lower() |
| + if "windows" in os_name: |
| + os_name = "windows" |
| + # os_release will be something like '7', 'vista', or 'xp' |
| + os_version = platform.release() |
| + |
| + elif "linux" in os_name: |
| + # will return something like ('Ubuntu', '14.04', 'trusty') |
| + dist_info = platform.dist() |
| + os_name = dist_info[0] |
| + os_version = dist_info[1] |
| + |
| + # on mac platform.system() reports 'darwin' |
| + else: |
| + # this tuple is only populated on mac systems |
| + mac_ver = platform.mac_ver() |
| + # will be '10.11.5' or similar on a valid mac |
| + # or will be '' on a non-mac |
| + os_version = mac_ver[0] |
| + if os_version: |
| + # we found a valid mac |
| + os_name = "mac" |
| + else : |
| + # not a mac |
| + # unable to find platform information |
| + # reset |
| + os_name = "" |
| + os_version = "" |
| + |
| + # normalize to lower case |
| + os_name = os_name.lower() |
| + os_version = os_version.lower() |
| + |
| + # construct metrics |
| + metric_os_name.set(os_name) |
| + metric_os_version.set(os_version) |
| + |
|
dsansome
2016/06/29 06:21:29
Need 2 blank lines between top-level functions
chrishall
2016/07/01 04:27:59
Done.
|
| +def clear_os_info(): |
| + metric_os_name.reset() |
| + metric_os_version.reset() |
| def get_proc_info(): |
| procs = psutil.pids() |