Exemplo n.º 1
0
class TxMetricsHistogram(BaseMetrics):
    """
    A histogram measures the statistical distribution of values in a stream
    of data. In addition to minimum, maximum, mean, etc., it also measures
    median, 75th, 90th, 95th, 98th, 99th, and 99.9th percentiles.
    """
    def __init__(self, appname, name, redis, timeout, unique_pid):
        super(TxMetricsHistogram, self).__init__(appname, name, redis, timeout, unique_pid)
        self._list_name = "retrics:histogram:%s:%s" % (self._appname, self._name)
        self._e = Enum([])

    @defer.inlineCallbacks 
    def update(self, val):
        assert(type(val) is int or type(val) is float)
        yield self._redis.lpush(self._list_name, val)
        self._load_list()

    def percentile(self, p):
        """
        Percentile of the Histogram list
        """
        assert(type(p) is float)
        return self._e.percentile(p)
    
    def standard_deviation(self):
        """
        standard deviation of the Histogram list
        """
        return self._e.standard_deviation()

    def median(self):
        """
        Median (50% Percentile) of the Histogram list
        """
        return self._e.median()
    
    def mean(self):
        """
        Mean of the Histogram list
        """
        return self._e.mean()

    @defer.inlineCallbacks 
    def _load_list(self):
        l = yield self._redis.lrange(self._list_name, 0, -1)
        l = map(lambda x: float(x), l) #oh god why
        self._e.reload(l)
   
    @defer.inlineCallbacks 
    def reset(self):
        yield self._redis.delete(self._list_name)
        self._e = Enum([])

    @defer.inlineCallbacks 
    def clear(self):
        yield self.reset()
Exemplo n.º 2
0
 def clear(self):
     self._redis.delete(self._list_name)
     self._e = Enum([])
Exemplo n.º 3
0
 def reset(self):
     self._redis.delete(self._list_name)
     self._e = Enum(self._load_list())
Exemplo n.º 4
0
 def __init__(self, appname, name, redis, timeout):
     super(RetricsHistogram, self).__init__(appname, name, redis, timeout)
     self._list_name = "retrics:histogram:%s:%s" % (self._appname, self._name)
     self._e = Enum(self._load_list())
Exemplo n.º 5
0
 def reset(self):
     yield self._redis.delete(self._list_name)
     self._e = Enum([])
Exemplo n.º 6
0
 def __init__(self, appname, name, redis, timeout, unique_pid):
     super(TxMetricsHistogram, self).__init__(appname, name, redis, timeout, unique_pid)
     self._list_name = "retrics:histogram:%s:%s" % (self._appname, self._name)
     self._e = Enum([])