| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Send system monitoring data to the timeseries monitoring API.""" | 6 """Send system monitoring data to the timeseries monitoring API.""" |
| 7 | 7 |
| 8 import random | 8 import random |
| 9 import time | 9 import time |
| 10 | 10 |
| 11 import psutil | 11 import psutil |
| 12 | 12 |
| 13 from infra.libs.service_utils import outer_loop | 13 from infra.libs.service_utils import outer_loop |
| 14 from infra.services.sysmon import android_device_metrics |
| 14 from infra.services.sysmon import cipd_metrics | 15 from infra.services.sysmon import cipd_metrics |
| 15 from infra.services.sysmon import puppet_metrics | 16 from infra.services.sysmon import puppet_metrics |
| 16 from infra.services.sysmon import root_setup | 17 from infra.services.sysmon import root_setup |
| 17 from infra.services.sysmon import system_metrics | 18 from infra.services.sysmon import system_metrics |
| 18 from infra_libs import ts_mon | 19 from infra_libs import ts_mon |
| 19 | 20 |
| 20 | 21 |
| 21 class SysMon(outer_loop.Application): | 22 class SysMon(outer_loop.Application): |
| 22 def add_argparse_options(self, parser): | 23 def add_argparse_options(self, parser): |
| 23 super(SysMon, self).add_argparse_options(parser) | 24 super(SysMon, self).add_argparse_options(parser) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 def task(self): | 41 def task(self): |
| 41 try: | 42 try: |
| 42 system_metrics.get_uptime() | 43 system_metrics.get_uptime() |
| 43 system_metrics.get_cpu_info() | 44 system_metrics.get_cpu_info() |
| 44 system_metrics.get_disk_info() | 45 system_metrics.get_disk_info() |
| 45 system_metrics.get_mem_info() | 46 system_metrics.get_mem_info() |
| 46 system_metrics.get_net_info() | 47 system_metrics.get_net_info() |
| 47 system_metrics.get_proc_info() | 48 system_metrics.get_proc_info() |
| 48 puppet_metrics.get_puppet_summary() | 49 puppet_metrics.get_puppet_summary() |
| 49 cipd_metrics.get_cipd_summary() | 50 cipd_metrics.get_cipd_summary() |
| 51 android_device_metrics.get_device_statuses() |
| 50 finally: | 52 finally: |
| 51 ts_mon.flush() | 53 ts_mon.flush() |
| 52 return True | 54 return True |
| 53 | 55 |
| 54 def sleep_timeout(self): | 56 def sleep_timeout(self): |
| 55 return self.opts.interval | 57 return self.opts.interval |
| 56 | 58 |
| 57 def main(self, opts): | 59 def main(self, opts): |
| 58 if opts.root_setup: | 60 if opts.root_setup: |
| 59 return root_setup.root_setup() | 61 return root_setup.root_setup() |
| 60 | 62 |
| 61 # This returns a 0 value the first time it's called. Call it now and | 63 # This returns a 0 value the first time it's called. Call it now and |
| 62 # discard the return value. | 64 # discard the return value. |
| 63 psutil.cpu_times_percent() | 65 psutil.cpu_times_percent() |
| 64 | 66 |
| 65 # Wait a random amount of time before starting the loop in case sysmon is | 67 # Wait a random amount of time before starting the loop in case sysmon is |
| 66 # started at exactly the same time on all machines. | 68 # started at exactly the same time on all machines. |
| 67 time.sleep(random.uniform(0, opts.interval)) | 69 time.sleep(random.uniform(0, opts.interval)) |
| 68 | 70 |
| 69 return super(SysMon, self).main(opts) | 71 return super(SysMon, self).main(opts) |
| 70 | 72 |
| 71 | 73 |
| 72 if __name__ == '__main__': | 74 if __name__ == '__main__': |
| 73 SysMon().run() | 75 SysMon().run() |
| OLD | NEW |