Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from buildbot.status.base import StatusReceiverMultiService | |
| 6 from twisted.internet import task | |
| 7 from twisted.python import log, threadpool | |
| 8 | |
| 9 from infra_libs import ts_mon | |
| 10 | |
| 11 | |
| 12 class MonitoringStatusReceiver(StatusReceiverMultiService): | |
| 13 """Flushes ts_mon metrics once per minute.""" | |
| 14 | |
| 15 def __init__(self): | |
| 16 StatusReceiverMultiService.__init__(self) | |
| 17 self.thread_pool = threadpool.ThreadPool(1, 1) | |
| 18 self.loop = task.LoopingCall(self._flush) | |
| 19 | |
| 20 def startService(self): | |
| 21 StatusReceiverMultiService.startService(self) | |
| 22 self.status = self.parent.getStatus() | |
| 23 self.status.subscribe(self) | |
| 24 | |
| 25 self.thread_pool.start() | |
| 26 self.loop.start(60, now=False) | |
|
agable
2016/06/29 20:17:59
Nice, I like this a lot better than using a change
| |
| 27 | |
| 28 def stopService(self): | |
| 29 self.loop.stop() | |
| 30 self.thread_pool.stop() | |
| 31 return StatusReceiverMultiService.stopService(self) | |
| 32 | |
| 33 def _flush(self): | |
| 34 self.thread_pool.callInThread(self._flush_and_log_exceptions) | |
| 35 | |
| 36 def _flush_and_log_exceptions(self): | |
| 37 try: | |
| 38 ts_mon.flush() | |
| 39 except Exception: | |
| 40 log.err(None, 'Automatic monitoring flush failed.') | |
| OLD | NEW |