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

Side by Side Diff: infra/services/devicemon/__main__.py

Issue 1993443002: Delete devicemon; moving to sysmon. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 7 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/devicemon/__init__.py ('k') | infra/services/devicemon/device_metrics.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Send android device monitoring data to the timeseries monitoring API."""
7
8 import logging
9 import os
10
11 from infra.libs.service_utils import outer_loop
12 from infra.services.devicemon import device_metrics
13 from infra_libs import ts_mon
14
15 from devil.android import device_utils
16 from devil.android.sdk import adb_wrapper
17
18
19 class DeviceMon(outer_loop.Application):
20 def __init__(self):
21 super(DeviceMon, self).__init__()
22 self.blacklist_file = None
23
24 def add_argparse_options(self, parser):
25 super(DeviceMon, self).add_argparse_options(parser)
26 parser.add_argument('adb_path', help='Path to adb binary.')
27 parser.add_argument('--blacklist-file',
28 help='Path to device blacklist file.')
29
30 def task(self):
31 if self.blacklist_file:
32 unhealthy_devices = {} # todo: fetch blacklist
33 else:
34 unhealthy_devices = {}
35
36 try:
37 devices = adb_wrapper.AdbWrapper.Devices(desired_state=None)
38 for device in devices:
39 device = device_utils.DeviceUtils(device)
40 fields = {
41 'device_id': str(device),
42 'device_type': 'type', # todo: get device type
43 'device_os': 'os', # todo: get os version
44 }
45 try:
46 device_metrics.set_cpu_temp(device, fields)
47 device_metrics.set_battery_temp(device, fields)
48 device_metrics.set_battery_charge(device, fields)
49 # Assume the blacklist is a more accurate source of truth for device
50 # health, so defer to it when determining phone status
51 if device not in unhealthy_devices:
52 if device.IsOnline():
53 device_metrics.set_device_status(device, fields, status='good')
54 else:
55 logging.warning('Unhealthy device %s not listed in blacklist.',
56 str(device))
57 unhealthy_devices[str(device)] = {'reason': device.adb.GetState()}
58 except Exception: # todo: change this to catch only device errors
59 logging.exception('Error when fetching status of %s.', str(device))
60 device_metrics.set_device_status(device, fields, status='unknown')
61
62 for device in unhealthy_devices:
63 device_metrics.set_device_status(device, fields,
64 status=device['reason'])
65
66 finally:
67 ts_mon.flush()
68
69 return True
70
71 def sleep_timeout(self):
72 return 60
73
74 def main(self, opts):
75 # Add adb to the path env var so devil can pick it up
76 adb_dir = os.path.dirname(opts.adb_path)
77 if adb_dir not in os.environ['PATH'] and os.path.isfile(opts.adb_path):
78 os.environ['PATH'] += ':' + adb_dir
79
80 self.blacklist_file = opts.blacklist_file
81
82 return super(DeviceMon, self).main(opts)
83
84
85 if __name__ == '__main__':
86 DeviceMon().run()
OLDNEW
« no previous file with comments | « infra/services/devicemon/__init__.py ('k') | infra/services/devicemon/device_metrics.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698