report available blobs

This commit is contained in:
Job Evers-Meltzer 2016-10-05 14:45:17 -05:00
parent 417a8f719f
commit 8b1bb673c1
3 changed files with 20 additions and 2 deletions

View file

@ -1,2 +1,4 @@
# Constants for metrics """Constants for metrics"""
BLOB_BYTES_UPLOADED = 'blob_bytes_uploaded' BLOB_BYTES_UPLOADED = 'blob_bytes_uploaded'
BLOB_BYTES_AVAILABLE = 'blob_bytes_available'

View file

@ -33,6 +33,11 @@ class Manager(object):
event = self.events_generator.download_started(name, stream_info) event = self.events_generator.download_started(name, stream_info)
self.analytics_api.track(event) self.analytics_api.track(event)
def register_repeating_metric(self, event_name, value_generator, frequency=300):
lcall = task.LoopingCall(self._send_repeating_metric, event_name, value_generator)
self.looping_call_manager.register_looping_call(event_name, lcall)
lcall.start(frequency)
def _send_heartbeat(self): def _send_heartbeat(self):
heartbeat = self.events_generator.heartbeat() heartbeat = self.events_generator.heartbeat()
self.analytics_api.track(heartbeat) self.analytics_api.track(heartbeat)
@ -42,3 +47,9 @@ class Manager(object):
if value > 0: if value > 0:
event = self.events_generator.metric_observered(constants.BLOB_BYTES_UPLOADED, value) event = self.events_generator.metric_observered(constants.BLOB_BYTES_UPLOADED, value)
self.analytics_api.track(event) self.analytics_api.track(event)
def _send_repeating_metric(self, event_name, value_generator):
should_send, value = value_generator()
if should_send:
event = self.events_generator.metric_observered(event_name, value)
self.analytics_api.track(event)

View file

@ -185,7 +185,7 @@ class CheckRemoteVersions(object):
return defer.fail(None) return defer.fail(None)
def calculate_available_blob_sizes(blob_manager): def calculate_available_blob_size(blob_manager):
return sum(blob.length for blob in blob_manager.get_all_verified_blobs()) return sum(blob.length for blob in blob_manager.get_all_verified_blobs())
@ -1021,6 +1021,11 @@ class Daemon(jsonrpc.JSONRPC):
self.analytics_manager = analytics.Manager( self.analytics_manager = analytics.Manager(
analytics_api, events_generator, analytics.Track()) analytics_api, events_generator, analytics.Track())
self.analytics_manager.start() self.analytics_manager.start()
self.register_repeating_metric(
analytics.BLOB_BYTES_AVAILABLE,
lambda: calculate_available_blob_size(self.session.blob_manager),
frequency=300
)
def _get_session(self): def _get_session(self):
def get_default_data_rate(): def get_default_data_rate():