8000
We read every piece of feedback, and take your input very seriously.
2 parents 783a917 + b29fd1e commit f737c48Copy full SHA for f737c48
prometheus_client/core.py
@@ -183,6 +183,23 @@ def collect():
183
184
@_MetricWrapper
185
class Counter(object):
186
+ '''A Counter tracks counts of events or running totals.
187
+
188
+ Example use cases for Counters:
189
+ - Number of requests processed
190
+ - Number of items that were inserted into a queue
191
+ - Total amount of data that a system has processed
192
193
+ Counters can only go up (and be reset when the process restarts). If your use case can go down,
194
+ you should use a Gauge instead.
195
196
+ An example for a Counter:
197
198
+ from prometheus_client import Counter
199
+ c = Counter('my_failures_total', 'Description of counter')
200
+ c.inc() # Increment by 1
201
+ c.inc(1.6) # Increment by given value
202
+ '''
203
_type = 'counter'
204
_reserved_labelnames = []
205
@@ -346,6 +363,28 @@ def _samples(self):
346
363
347
364
348
365
class Summary(object):
366
+ '''A Summary tracks the size and number of events.
367
368
+ Example use cases for Summaries:
369
+ - Response latency
370
+ - Request size
371
372
+ Example for a Summary:
373
374
+ from prometheus_client import Summary
375
+ s = Summary('request_size_bytes', 'Request size (bytes)')
376
+ s.observe(512) # Observe 512 (bytes)
377
378
+ Example for a Summary using time:
379
380
+ REQUEST_TIME = Summary('response_latency_seconds', 'Response latency (seconds)')
381
382
+ @REQUEST_TIME.time()
383
+ def create_response(request):
384
+ """A dummy function"""
385
+ time.sleep(1)
386
387
349
388
_type = 'summary'
350
389
_reserved_labelnames = ['quantile']
351
390
@@ -404,6 +443,33 @@ def _floatToGoString(d):
404
443
405
444
406
445
class Histogram(object):
446
+ '''A Histogram tracks the size and number of events in buckets.
447
448
+ You can use Histograms for aggregatable calculation of quantiles.
449
450
+ Example use cases:
451
452
453
454
+ Example for a Histogram:
455
456
+ from prometheus_client import Histogram
457
+ h = Histogram('request_size_bytes', 'Request size (bytes)')
458
+ h.observe(512) # Observe 512 (bytes)
459
460
461
+ Example for a Histogram using time:
462
463
+ REQUEST_TIME = Histogram('response_latency_seconds', 'Response latency (seconds)')
464
465
466
467
468
469
470
+ The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds.
471
+ They can be overridden by passing `buckets` keyword argument to `Histogram`.
472
407
473
_type = 'histogram'
408
474
_reserved_labelnames = ['histogram']
409
475