| 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.status = None | |
| 18 self.thread_pool = threadpool.ThreadPool(1, 1) | |
| 19 self.loop = task.LoopingCall(self._flush) | |
| 20 | |
| 21 def startService(self): | |
| 22 StatusReceiverMultiService.startService(self) | |
| 23 self.status = self.parent.getStatus() | |
| 24 self.status.subscribe(self) | |
| 25 | |
| 26 self.thread_pool.start() | |
| 27 self.loop.start(60, now=False) | |
| 28 | |
| 29 def stopService(self): | |
| 30 self.loop.stop() | |
| 31 self.thread_pool.stop() | |
| 32 return StatusReceiverMultiService.stopService(self) | |
| 33 | |
| 34 def _flush(self): | |
| 35 self.thread_pool.callInThread(self._flush_and_log_exceptions) | |
| 36 | |
| 37 def _flush_and_log_exceptions(self): | |
| 38 try: | |
| 39 ts_mon.flush() | |
| 40 except Exception: | |
| 41 log.err(None, 'Automatic monitoring flush failed.') | |
| OLD | NEW |