(self)
Overrides the Collector.collect method
Overrides the Collector.collect method
Overrides the Collector . collect method
def collect(self):
        """
        Overrides the Collector.collect method
        """

        # Handle collection time intervals correctly
        CollectTime = int(time.time())
        time_delta = float(self.config['interval'])
        if not self.LastCollectTime:
            self.LastCollectTime = CollectTime - time_delta

        host = self.config['host']
        port = self.config['port']

        celerymon_url = "http://%s:%s/api/task/?since=%i" % (
            host, port, self.LastCollectTime)
        response = urllib2.urlopen(celerymon_url)
        body = response.read()
        celery_data = json.loads(body)

        results = dict()
        total_messages = 0
        for data in celery_data:
            name = str(data[1]['name'])
            if name not in results:
                results[name] = dict()
            state = str(data[1]['state'])
            if state not in results[name]:
                results[name][state] = 1
            else:
                results[name][state] += 1
            total_messages += 1

        # Publish Metric
        self.publish('total_messages', total_messages)
        for result in results:
            for state in results[result]:
                metric_value = results[result][state]
                metric_name = "%s.%s" % (result, state)
                self.publish(metric_name, metric_value)

        self.LastCollectTime = CollectTime
def collect ( self ) : # Handle collection time intervals correctly CollectTime = int ( time . time ( ) ) time_delta = float ( self . config [ 'interval' ] ) if not self . LastCollectTime : self . LastCollectTime = CollectTime - time_delta host = self . config [ 'host' ] port = self . config [ 'port' ] celerymon_url = "http://%s:%s/api/task/?since=%i" % ( host , port , self . LastCollectTime ) response = urllib2 . urlopen ( celerymon_url ) body = response . read ( ) celery_data = json . loads ( body ) results = dict ( ) total_messages = 0 for data in celery_data : name = str ( data [ 1 ] [ 'name' ] ) if name not in results : results [ name ] = dict ( ) state = str ( data [ 1 ] [ 'state' ] ) if state not in results [ name ] : results [ name ] [ state ] = 1 else : results [ name ] [ state ] += 1 total_messages += 1 # Publish Metric self . publish ( 'total_messages' , total_messages ) for result in results : for state in results [ result ] : metric_value = results [ result ] [ state ] metric_name = "%s.%s" % ( result , state ) self . publish ( metric_name , metric_value ) self . LastCollectTime = CollectTime