@@ -183,6 +183,23 @@ def collect():
183
183
184
184
@_MetricWrapper
185
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
+ '''
186
203
_type = 'counter'
187
204
_reserved_labelnames = []
188
205
@@ -346,6 +363,28 @@ def _samples(self):
346
363
347
364
@_MetricWrapper
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
+ from prometheus_client import Summary
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
@_MetricWrapper
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
+ - Response latency
452
+ - Request size
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
+ from prometheus_client import Histogram
463
+ REQUEST_TIME = Histogram('response_latency_seconds', 'Response latency (seconds)')
464
+
465
+ @REQUEST_TIME.time()
466
+ def create_response(request):
467
+ """A dummy function"""
468
+ time.sleep(1)
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
0 commit comments