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

Side by Side 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: updating system_metrics.clear_os_info to clear all added fields, fixing unit tests for clear Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « infra/services/sysmon/__main__.py ('k') | infra/services/sysmon/test/system_metrics_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import errno 5 import errno
6 import os 6 import os
7 import logging 7 import logging
8 import platform
9 import sys
8 import time 10 import time
9 11
10 import psutil 12 import psutil
11 13
12 from infra_libs import ts_mon 14 from infra_libs import ts_mon
13 15
14 16
15 cpu_count = ts_mon.GaugeMetric('dev/cpu/count', 17 cpu_count = ts_mon.GaugeMetric('dev/cpu/count',
16 description='Number of CPU cores.') 18 description='Number of CPU cores.')
17 cpu_time = ts_mon.FloatMetric('dev/cpu/time', 19 cpu_time = ts_mon.FloatMetric('dev/cpu/time',
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 'in the system run queue.') 87 'in the system run queue.')
86 88
87 # tsmon pipeline uses backend clocks when assigning timestamps to metric points. 89 # tsmon pipeline uses backend clocks when assigning timestamps to metric points.
88 # By comparing point timestamp to the point value (i.e. time by machine's local 90 # By comparing point timestamp to the point value (i.e. time by machine's local
89 # clock), we can potentially detect some anomalies (clock drift, unusually high 91 # clock), we can potentially detect some anomalies (clock drift, unusually high
90 # metrics pipeline delay, completely wrong clocks, etc). 92 # metrics pipeline delay, completely wrong clocks, etc).
91 # 93 #
92 # It is important to gather this metric right before the flush. 94 # It is important to gather this metric right before the flush.
93 unix_time = ts_mon.GaugeMetric('dev/unix_time', 95 unix_time = ts_mon.GaugeMetric('dev/unix_time',
94 description='Number of milliseconds since epoch ' 96 description='Number of milliseconds since epoch '
95 'based on local machine clock.') 97 'based on local machine clock.')
98
99 os_name = ts_mon.StringMetric('proc/os/name',
100 description='OS name on the machine ')
101
102 os_version = ts_mon.StringMetric('proc/os/version',
103 description='OS version on the machine ')
104
105 os_arch = ts_mon.StringMetric('proc/os/arch',
106 description='OS architecture on this machine')
107
108 python_arch = ts_mon.StringMetric('proc/python/arch',
109 description='python userland '
110 'architecture on this machine')
96 111
97 112
98 def get_uptime(): 113 def get_uptime():
99 uptime.set(int(time.time() - START_TIME)) 114 uptime.set(int(time.time() - START_TIME))
100 115
101 116
102 def get_cpu_info(): 117 def get_cpu_info():
103 cpu_count.set(psutil.cpu_count()) 118 cpu_count.set(psutil.cpu_count())
104 119
105 times = psutil.cpu_times_percent() 120 times = psutil.cpu_times_percent()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 for metric, counter_name in metric_counter_names: 183 for metric, counter_name in metric_counter_names:
169 try: 184 try:
170 metric.set(getattr(counters, counter_name), fields=fields) 185 metric.set(getattr(counters, counter_name), fields=fields)
171 except ts_mon.MonitoringDecreasingValueError as ex: # pragma: no cover 186 except ts_mon.MonitoringDecreasingValueError as ex: # pragma: no cover
172 # This normally shouldn't happen, but might if the network driver module 187 # This normally shouldn't happen, but might if the network driver module
173 # is reloaded, so log an error and continue instead of raising an 188 # is reloaded, so log an error and continue instead of raising an
174 # exception. 189 # exception.
175 logging.error(str(ex)) 190 logging.error(str(ex))
176 191
177 192
193 def get_os_info():
194 os_name_data = ''
195 os_version_data = ''
196
197 os_name_data = platform.system().lower()
198 if 'windows' in os_name_data:
199 os_name_data = 'windows'
200 # os_release will be something like '7', 'vista', or 'xp'
201 os_version_data = platform.release()
202
203 elif 'linux' in os_name_data:
204 # will return something like ('Ubuntu', '14.04', 'trusty')
205 dist_info_data = platform.dist()
206 os_name_data = dist_info_data[0]
207 os_version_data = dist_info_data[1]
208
209 # on mac platform.system() reports 'darwin'
210 else:
211 # this tuple is only populated on mac systems
212 mac_ver_data = platform.mac_ver()
213 # [0] will be '10.11.5' or similar on a valid mac or will be '' on a
214 # non-mac
215 os_version_data = mac_ver_data[0]
216 if os_version_data:
217 # we found a valid mac
218 os_name_data = 'mac'
219 else :
220 # not a mac, unable to find platform information, reset
221 os_name_data = ''
222 os_version_data = ''
223
224 # normalize to lower case
225 os_name_data = os_name_data.lower()
226 os_version_data = os_version_data.lower()
227
228 python_arch_data = '32'
229 if sys.maxsize > 2**32:
230 python_arch_data = '64'
231
232 # construct metrics
233 os_name.set(os_name_data)
234 os_version.set(os_version_data)
235 os_arch.set(platform.machine())
236 python_arch.set(python_arch_data)
237
238
239 def clear_os_info():
240 os_name.reset()
241 os_version.reset()
242 os_arch.reset()
243 python_arch.reset()
244
245
178 def get_proc_info(): 246 def get_proc_info():
179 procs = psutil.pids() 247 procs = psutil.pids()
180 proc_count.set(len(procs)) 248 proc_count.set(len(procs))
181 249
182 if os.name == 'posix': # pragma: no cover 250 if os.name == 'posix': # pragma: no cover
183 try: 251 try:
184 avg1, avg5, avg15 = os.getloadavg() 252 avg1, avg5, avg15 = os.getloadavg()
185 except OSError: # pragma: no cover 253 except OSError: # pragma: no cover
186 pass 254 pass
187 else: 255 else:
188 load_average.set(avg1, fields={'minutes': 1}) 256 load_average.set(avg1, fields={'minutes': 1})
189 load_average.set(avg5, fields={'minutes': 5}) 257 load_average.set(avg5, fields={'minutes': 5})
190 load_average.set(avg15, fields={'minutes': 15}) 258 load_average.set(avg15, fields={'minutes': 15})
191 259
192 260
193 def get_unix_time(): 261 def get_unix_time():
194 unix_time.set(int(time.time() * 1000)) 262 unix_time.set(int(time.time() * 1000))
OLDNEW
« no previous file with comments | « infra/services/sysmon/__main__.py ('k') | infra/services/sysmon/test/system_metrics_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698