예제 #1
0
파일: graphite.py 프로젝트: DroneD/droned
    def produce_all(self, host, port, protocol, timeout=5.0):
        """Produce ALL metrics to the endpoint

           Note: this method is wrapped in a deferred on class instantiation

           @param host (string)
           @param port (int)
           @param protocol (class) - twisted.internet.protocol.Protocol
           @param timeout (int|float) - timeout parameter for the protocol

           @callback (int) - how many metrics were sent
           @errback (twisted.python.failure.Failure())

           @return defer.Deferred()
        """
        result = 0
        if self.pending:
            metrics = set()
            for stamp, value in self.dataPoints.iteritems():
                metrics.add((self.metricID, (stamp, value)))
            proto_args = (list(metrics),)
            proto_kwargs = {'timeout': timeout}
            try:
                d = connect(host, port, protocol, *proto_args, **proto_kwargs)
                wfd = defer.waitForDeferred(d)
                yield wfd
                wfd.getResult()
                result += 1
                self.dataPoints = {} #reset storage
            except:
                result = Failure()
        yield result
예제 #2
0
파일: graphite.py 프로젝트: c0ns0le/droned
    def produce_all(self, host, port, protocol, timeout=5.0):
        """Produce ALL metrics to the endpoint

           Note: this method is wrapped in a deferred on class instantiation

           @param host (string)
           @param port (int)
           @param protocol (class) - twisted.internet.protocol.Protocol
           @param timeout (int|float) - timeout parameter for the protocol

           @callback (int) - how many metrics were sent
           @errback (twisted.python.failure.Failure())

           @return defer.Deferred()
        """
        result = 0
        if self.pending:
            metrics = set()
            for stamp, value in self.dataPoints.iteritems():
                metrics.add((self.metricID, (value, stamp)))
            proto_args = (list(metrics), )
            proto_kwargs = {'timeout': timeout}
            try:
                d = connect(host, port, protocol, *proto_args, **proto_kwargs)
                wfd = defer.waitForDeferred(d)
                yield wfd
                wfd.getResult()
                result += 1
                self.dataPoints = {}  #reset storage
            except:
                result = Failure()
        yield result
예제 #3
0
파일: graphite.py 프로젝트: DroneD/droned
    def produce(self, host, port, protocol, timeout=5.0):
        """Produce metrics to the endpoint, sends the oldest metric and returns

           Note: this method is wrapped in a deferred on class instantiation

           @param host (string)
           @param port (int)
           @param protocol (class) - twisted.internet.protocol.Protocol
           @param timeout (int|float) - timeout parameter for the protocol

           @callback (int) - how many metrics were sent
           @errback (twisted.python.failure.Failure())

           @return defer.Deferred()
        """
        result = 0
        if self.pending:
            stamp = sorted(self.dataPoints.keys())[0] #send oldest first
            value = self.dataPoints[stamp]
            proto_args = ([(self.metricID, (stamp, value))],)
            proto_kwargs = {'timeout': timeout}
            try:
                d = connect(host, port, protocol, *proto_args, **proto_kwargs)
                wfd = defer.waitForDeferred(d)
                yield wfd
                wfd.getResult()
                result += 1
                del self.dataPoints[stamp] #remove the metric
            except:
                result = Failure()
        yield result
예제 #4
0
파일: graphite.py 프로젝트: c0ns0le/droned
    def produce(self, host, port, protocol, timeout=5.0):
        """Produce metrics to the endpoint, sends the oldest metric and returns

           Note: this method is wrapped in a deferred on class instantiation

           @param host (string)
           @param port (int)
           @param protocol (class) - twisted.internet.protocol.Protocol
           @param timeout (int|float) - timeout parameter for the protocol

           @callback (int) - how many metrics were sent
           @errback (twisted.python.failure.Failure())

           @return defer.Deferred()
        """
        result = 0
        if self.pending:
            stamp = sorted(self.dataPoints.keys())[0]  #send oldest first
            value = self.dataPoints[stamp]
            proto_args = ([(self.metricID, (stamp, value))], )
            proto_kwargs = {'timeout': timeout}
            try:
                d = connect(host, port, protocol, *proto_args, **proto_kwargs)
                wfd = defer.waitForDeferred(d)
                yield wfd
                wfd.getResult()
                result += 1
                del self.dataPoints[stamp]  #remove the metric
            except:
                result = Failure()
        yield result