(self, metric)
Process a metric by sending it to TSDB
Process a metric by sending it to TSDB
Process a metric by sending it to TSDB
def process(self, metric):
        """
        Process a metric by sending it to TSDB
        """
        entry = {'timestamp': metric.timestamp, 'value': metric.value,
                 "tags": {}}
        entry["tags"]["hostname"] = metric.host

        if self.cleanMetrics:
            metric = MetricWrapper(metric, self.log)
            if self.skipAggregates and metric.isAggregate():
                return
            for tagKey in metric.getTags():
                entry["tags"][tagKey] = metric.getTags()[tagKey]

        entry['metric'] = (self.prefix + metric.getCollectorPath() +
                           '.' + metric.getMetricPath())

        for [key, value] in self.tags:
            entry["tags"][key] = value

        self.entrys.append(entry)

        # send data if list is long enough
        if (len(self.entrys) >= self.batch):
            # Compress data
            if self.compression >= 1:
                data = StringIO.StringIO()
                with contextlib.closing(gzip.GzipFile(fileobj=data,
                                        compresslevel=self.compression,
                                        mode="w")) as f:
                    f.write(json.dumps(self.entrys))
                self._send(data.getvalue())
            else:
                # no compression
                data = json.dumps(self.entrys)
                self._send(data)
def process ( self , metric ) : entry = { 'timestamp' : metric . timestamp , 'value' : metric . value , "tags" : { } } entry [ "tags" ] [ "hostname" ] = metric . host if self . cleanMetrics : metric = MetricWrapper ( metric , self . log ) if self . skipAggregates and metric . isAggregate ( ) : return for tagKey in metric . getTags ( ) : entry [ "tags" ] [ tagKey ] = metric . getTags ( ) [ tagKey ] entry [ 'metric' ] = ( self . prefix + metric . getCollectorPath ( ) + '.' + metric . getMetricPath ( ) ) for [ key , value ] in self . tags : entry [ "tags" ] [ key ] = value self . entrys . append ( entry ) # send data if list is long enough if ( len ( self . entrys ) >= self . batch ) : # Compress data if self . compression >= 1 : data = StringIO . StringIO ( ) with contextlib . closing ( gzip . GzipFile ( fileobj = data , compresslevel = self . compression , mode = "w" ) ) as f : f . write ( json . dumps ( self . entrys ) ) self . _send ( data . getvalue ( ) ) else : # no compression data = json . dumps ( self . entrys ) self . _send ( data )