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..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() |