def process_metrics(self):
metrics = []
# Compute frequency of measurements
if 'packet_time' in self.metrics and self.metrics['packet_time'] is not None:
self.metrics.setdefault('packet_starttime', self.metrics.packet_time)
# Convert nanos to seconds
packet_duration = (self.metrics.packet_time - self.metrics.packet_starttime) / 1000.0 / 1000.0 / 1000.0
packet_duration = packet_duration or self.metrics.starttime
if packet_duration != 0:
packet_frequency = self.metrics.tx_count / float(packet_duration)
else:
packet_frequency = 0.0
metrics.append('measurements: %.02f Hz' % packet_frequency)
# Reset for next round
self.metrics.packet_starttime = self.metrics.packet_time
# Compute frequency of transactions
now = time.time()
transaction_duration = now - self.metrics.starttime
if transaction_duration != 0:
transaction_frequency = self.metrics.tx_count / float(transaction_duration)
else:
transaction_frequency = 0.0
metrics.append('transactions: %.02f tps' % transaction_frequency)
# Reset for next round
self.metrics.tx_count = 0
self.metrics.starttime = now
# Add information from the Twisted reactor
pending_calls = reactor.getDelayedCalls()
pending_count = len(pending_calls)
#metrics.append('pending: %d' % pending_count)
metrics_info = ', '.join(metrics)
log.info('[{realm:12s}] {metrics_info}', realm=self.channel.realm, metrics_info=metrics_info)
评论列表
文章目录