Chromium Code Reviews| Index: infra/services/sysmon/__main__.py |
| diff --git a/infra/services/sysmon/__main__.py b/infra/services/sysmon/__main__.py |
| index 806104407ed2c07342999648251b3482d13aa1e5..fe550e8b5f0a75a9cf193789a068747334af0823 100644 |
| --- a/infra/services/sysmon/__main__.py |
| +++ b/infra/services/sysmon/__main__.py |
| @@ -20,6 +20,27 @@ from infra_libs import ts_mon |
| class SysMon(outer_loop.Application): |
| + def __init__(self): |
| + # make sure we call our super's init |
| + super(SysMon, self).__init__() |
| + |
| + # SysMon.task is called every minute we want to collect some metrics |
| + # (e.g. os_info) only once per hour, so here we count the minutes within |
| + # the hour |
| + self._minute_count = 0 |
| + |
| + # should be called at the end of each call to self.task |
|
dsansome
2016/07/01 04:30:56
Make this a docstring?
chrishall
2016/07/01 04:53:56
Done.
|
| + def count_minute(self): |
| + # mark that we were called |
| + self._minute_count += 1 |
| + |
| + # roll over each day-ish, 60 minutes * 24 hours |
| + self._minute_count %= 60 * 24 |
| + |
| + # check if this call is on the hour |
| + def is_hour(self): |
| + return self._minute_count % 60 == 0 |
| + |
| def add_argparse_options(self, parser): |
| super(SysMon, self).add_argparse_options(parser) |
| @@ -46,12 +67,20 @@ class SysMon(outer_loop.Application): |
| system_metrics.get_mem_info() |
| system_metrics.get_net_info() |
| system_metrics.get_proc_info() |
| + if self.is_hour(): |
| + # collect once per hour |
| + system_metrics.get_os_info() |
| + else: |
| + # clear on all other minutes |
| + system_metrics.clear_os_info() |
| puppet_metrics.get_puppet_summary() |
| cipd_metrics.get_cipd_summary() |
| android_device_metrics.get_device_statuses() |
| system_metrics.get_unix_time() # must be the last in the list |
| + |
| finally: |
| ts_mon.flush() |
| + self.count_minute() |
| return True |
| def sleep_timeout(self): |