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 dc2a9a18852d1a02434a9a460ce21c59174ff1e4..61ec163a5b084664cf5e04b1969aea9d4e626d5e 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 |
| @@ -92,7 +94,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.') |
|
dsansome
2016/07/21 01:55:25
You can remove 'metric:hostname' from the descript
chrishall
2016/07/27 02:45:18
oops, derp!
|
| + |
| +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(): |
| @@ -175,6 +193,57 @@ def get_net_info(): |
| logging.error(str(ex)) |
| +def get_os_info(): |
| + os_name_data = '' |
| + 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.set(platform.machine()) |
| + python_arch.set(python_arch_data) |
| + |
| + |
| +def clear_os_info(): |
| + os_name.reset() |
| + os_version.reset() |
| + |
| + |
| def get_proc_info(): |
| procs = psutil.pids() |
| proc_count.set(len(procs)) |