A gauge is an instantaneous measurement of a value
class JobGauge(metrology.instruments.Gauge):
def value(self):
return len(queue)
gauge = Metrology.gauge('pending-jobs', JobGauge())
A percent gauge is a ratio gauge where the result is normalized to a value between 0 and 100.
A ratio gauge is a simple way to create a gauge which is the ratio between two numbers
A counter is like a gauge, but you can increment or decrement its value
counter = Metrology.counter('pending-jobs')
counter.increment()
counter.decrement()
counter.count
Return the current value of the counter.
Decrement the counter. By default it will decrement by 1.
Parameters: | value – value to decrement the counter. |
---|
Increment the counter. By default it will increment by 1.
Parameters: | value – value to increment the counter. |
---|
A derive is like a meter but accepts an absolute counter as input.
derive = Metrology.derive(‘network.io’) derive.mark() derive.count
Record an event with the derive.
Parameters: | value – counter value to record |
---|
A meter measures the rate of events over time (e.g., “requests per second”). In addition to the mean rate, you can also track 1, 5 and 15 minutes moving averages
meter = Metrology.meter('requests')
meter.mark()
meter.count
Returns the total number of events that have been recorded.
Returns the fifteen-minute average rate.
Returns the five-minute average rate.
Record an event with the meter. By default it will record one event.
Parameters: | value – number of event to record |
---|
Returns the mean rate of the events since the start of the process.
Returns the one-minute average rate.
A histogram measures the statistical distribution of values in a stream of data. In addition to minimum, maximum, mean, it also measures median, 75th, 90th, 95th, 98th, 99th, and 99.9th percentiles
histogram = Metrology.histogram('response-sizes')
histogram.update(len(response.content))
Metrology provides two types of histograms: uniform and exponentially decaying.
Return number of values.
Returns the maximun value.
Returns the mean value.
Returns the minimum value.
Returns the standard deviation.
Returns variance
A exponentially decaying histogram produces quantiles which are representative of approximately the last five minutes of data. Unlike the uniform histogram, a biased histogram represents recent data, allowing you to know very quickly if the distribution of the data has changed.
A uniform histogram produces quantiles which are valid for the entirely of the histogram’s lifetime. It will return a median value, for example, which is the median of all the values the histogram has ever been updated with.
Use a uniform histogram when you’re interested in long-term measurements. Don’t use one where you’d want to know if the distribution of the underlying data stream has changed recently.
A timer measures both the rate that a particular piece of code is called and the distribution of its duration
timer = Metrology.timer('responses')
with timer:
do_something()
Returns the number of measurements that have been made.
Returns the fifteen-minute average rate.
Returns the five-minute average rate.
Returns the maximum amount of time spent in the operation.
Returns the mean time spent in the operation.
Returns the mean rate of the events since the start of the process.
Returns the minimum amount of time spent in the operation.
Returns the one-minute average rate.
Returns the standard deviation of the mean spent in the operation.
Records the duration of an operation.
A specialized timer that calculates the percentage of wall-clock time that was spent
utimer = Metrology.utilization_timer('responses')
with utimer:
do_something()
Returns the number of measurements that have been made.
Returns the fifteen-minute average rate.
Returns the fifteen-minute average utilization as a percentage.
Returns the five-minute average rate.
Returns the five-minute average utilization as a percentage.
Returns the maximum amount of time spent in the operation.
Returns the mean time spent in the operation.
Returns the mean rate of the events since the start of the process.
Returns the mean (average) utilization as a percentage since the process started.
Returns the minimum amount of time spent in the operation.
Returns the one-minute average rate.
Returns the one-minute average utilization as a percentage.
Returns the standard deviation of the mean spent in the operation.
A health check is a small self-test to verify that a specific component or responsibility is performing correctly
class DatabaseHealthCheck(metrology.healthcheck.HealthCheck):
def __init__(self, database):
self.database = database
def check(self):
if database.ping():
return True
return False
health_check = Metrology.health_check('database', DatabaseHealthCheck(database))
health_check.check()
Returns True if what is being checked is healthy
A profiler measures the distribution of the duration passed in a every part of the code
profiler = Metrology.profiler('slow-code')
with profiler:
run_slow_code()
Warning
This instrument does not yet work on Windows, and it doesn’t run on Python 3
Records the duration of a call.