class MonitoringIntegrationSdsSyncThread(sds_sync.StateSyncThread): def __init__(self): super(MonitoringIntegrationSdsSyncThread, self).__init__() self._complete = threading.Event() self.plugin_obj = GraphitePlugin() self.sync_interval = None def run(self): aggregate_gluster_objects = NS.monitoring.definitions.\ get_parsed_defs()["namespace.monitoring"]["graphite_data"] _sleep = 0 while not self._complete.is_set(): if self.sync_interval is None: try: config_data = json.loads(etcd_utils.read( "_NS/gluster/config/data" ).value) try: self.sync_interval = int( config_data['data']['sync_interval'] ) except ValueError as ex: logger.log( "error", NS.get("publisher_id", None), { 'message': "Unable to parse tendrl-gluster-" + "integration config 'sync_interval'" } ) raise ex except etcd.EtcdKeyNotFound as ex: # Before cluster import sync_interval is not populated time.sleep(DEFAULT_SLEEP) continue if _sleep > 5: _sleep = self.sync_interval else: _sleep += 1 try: cluster_details = self.plugin_obj.get_central_store_data( aggregate_gluster_objects ) graphite_utils.create_cluster_alias(cluster_details) metrics = graphite_utils.create_metrics( aggregate_gluster_objects, cluster_details) for metric in metrics: for key, value in metric.items(): if value: self.plugin_obj.push_metrics(key, value) # Creating or refreshing alert dashboard if _sleep > 5: SyncAlertDashboard().refresh_dashboard() time.sleep(_sleep) except (etcd.EtcdKeyNotFound, AttributeError, KeyError) as ex: logger.log("error", NS.get("publisher_id", None), {'message': str(ex)}) time.sleep(_sleep)
class MonitoringIntegrationSdsSyncThread(sds_sync.StateSyncThread): def __init__(self): super(MonitoringIntegrationSdsSyncThread, self).__init__() self._complete = gevent.event.Event() self.plugin_obj = GraphitePlugin() self.sync_interval = None def _run(self): aggregate_gluster_objects = NS.monitoring.definitions.\ get_parsed_defs()["namespace.monitoring"]["graphite_data"] while not self._complete.is_set(): if self.sync_interval is None: try: interval = etcd_utils.read( "_NS/gluster/config/data/sync_interval") try: self.sync_interval = float(interval.value) except ValueError as ex: logger.log( "error", NS.get("publisher_id", None), { 'message': "Unable to parse tendrl-gluster-" + "integration config 'sync_interval' " + "(value: %s)" % interval.value }) raise ex except etcd.EtcdKeyNotFound as ex: continue try: gevent.sleep(self.sync_interval) cluster_details = self.plugin_obj.get_central_store_data( aggregate_gluster_objects) metrics = graphite_utils.create_metrics( aggregate_gluster_objects, cluster_details) for metric in metrics: for key, value in metric.items(): if value: self.plugin_obj.push_metrics(key, value) except (etcd.EtcdKeyNotFound, AttributeError, KeyError) as ex: logger.log("error", NS.get("publisher_id", None), {'message': str(ex)}) def stop(self): super(MonitoringIntegrationSdsSyncThread, self).stop() self.plugin_obj.graphite_sock.shutdown(1) self.plugin_obj.graphite_sock.close()