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

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: adding comment explaining minute guarantee Created 4 years, 5 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 '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!
102
103 os_version = ts_mon.StringMetric('proc/os/version',
104 description='OS version on the machine '
105 'metric:hostname.')
106
107 os_arch = ts_mon.StringMetric('proc/os/arch',
108 description='OS architecture on this '
109 'machine')
110
111 python_arch = ts_mon.StringMetric('proc/python/arch',
112 description='python userland '
113 'architecture on this machine')
96 114
97 115
98 def get_uptime(): 116 def get_uptime():
99 uptime.set(int(time.time() - START_TIME)) 117 uptime.set(int(time.time() - START_TIME))
100 118
101 119
102 def get_cpu_info(): 120 def get_cpu_info():
103 cpu_count.set(psutil.cpu_count()) 121 cpu_count.set(psutil.cpu_count())
104 122
105 times = psutil.cpu_times_percent() 123 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: 186 for metric, counter_name in metric_counter_names:
169 try: 187 try:
170 metric.set(getattr(counters, counter_name), fields=fields) 188 metric.set(getattr(counters, counter_name), fields=fields)
171 except ts_mon.MonitoringDecreasingValueError as ex: # pragma: no cover 189 except ts_mon.MonitoringDecreasingValueError as ex: # pragma: no cover
172 # This normally shouldn't happen, but might if the network driver module 190 # 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 191 # is reloaded, so log an error and continue instead of raising an
174 # exception. 192 # exception.
175 logging.error(str(ex)) 193 logging.error(str(ex))
176 194
177 195
196 def get_os_info():
197 os_name_data = ''
198 os_version_data = ''
199
200 os_name_data = platform.system().lower()
201 if 'windows' in os_name_data:
202 os_name_data = 'windows'
203 # os_release will be something like '7', 'vista', or 'xp'
204 os_version_data = platform.release()
205
206 elif 'linux' in os_name_data:
207 # will return something like ('Ubuntu', '14.04', 'trusty')
208 dist_info_data = platform.dist()
209 os_name_data = dist_info_data[0]
210 os_version_data = dist_info_data[1]
211
212 # on mac platform.system() reports 'darwin'
213 else:
214 # this tuple is only populated on mac systems
215 mac_ver_data = platform.mac_ver()
216 # [0] will be '10.11.5' or similar on a valid mac or will be '' on a
217 # non-mac
218 os_version_data = mac_ver_data[0]
219 if os_version_data:
220 # we found a valid mac
221 os_name_data = 'mac'
222 else :
223 # not a mac, unable to find platform information, reset
224 os_name_data = ''
225 os_version_data = ''
226
227 # normalize to lower case
228 os_name_data = os_name_data.lower()
229 os_version_data = os_version_data.lower()
230
231 python_arch_data = '32'
232 if sys.maxsize > 2**32:
233 python_arch_data = '64'
234
235 # construct metrics
236 os_name.set(os_name_data)
237 os_version.set(os_version_data)
238 os_arch.set(platform.machine())
239 python_arch.set(python_arch_data)
240
241
242 def clear_os_info():
243 os_name.reset()
244 os_version.reset()
245
246
178 def get_proc_info(): 247 def get_proc_info():
179 procs = psutil.pids() 248 procs = psutil.pids()
180 proc_count.set(len(procs)) 249 proc_count.set(len(procs))
181 250
182 if os.name == 'posix': # pragma: no cover 251 if os.name == 'posix': # pragma: no cover
183 try: 252 try:
184 avg1, avg5, avg15 = os.getloadavg() 253 avg1, avg5, avg15 = os.getloadavg()
185 except OSError: # pragma: no cover 254 except OSError: # pragma: no cover
186 pass 255 pass
187 else: 256 else:
188 load_average.set(avg1, fields={'minutes': 1}) 257 load_average.set(avg1, fields={'minutes': 1})
189 load_average.set(avg5, fields={'minutes': 5}) 258 load_average.set(avg5, fields={'minutes': 5})
190 load_average.set(avg15, fields={'minutes': 15}) 259 load_average.set(avg15, fields={'minutes': 15})
191 260
192 261
193 def get_unix_time(): 262 def get_unix_time():
194 unix_time.set(int(time.time() * 1000)) 263 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