MCPcopy Index your code
hub / github.com/prometheus/client_python / Gauge

Class Gauge

prometheus_client/metrics.py:370–502  ·  view source on GitHub ↗

Gauge metric, to report instantaneous values. Examples of Gauges include: - Inprogress requests - Number of items in a queue - Free memory - Total memory - Temperature Gauges can go both up and down. from prometheus_client import Gauge

Source from the content-addressed store, hash-verified

368
369
370class Gauge(MetricWrapperBase):
371 """Gauge metric, to report instantaneous values.
372
373 Examples of Gauges include:
374 - Inprogress requests
375 - Number of items in a queue
376 - Free memory
377 - Total memory
378 - Temperature
379
380 Gauges can go both up and down.
381
382 from prometheus_client import Gauge
383
384 g = Gauge('my_inprogress_requests', 'Description of gauge')
385 g.inc() # Increment by 1
386 g.dec(10) # Decrement by given value
387 g.set(4.2) # Set to a given value
388
389 There are utilities for common use cases:
390
391 g.set_to_current_time() # Set to current unixtime
392
393 # Increment when entered, decrement when exited.
394 @g.track_inprogress()
395 def f():
396 pass
397
398 with g.track_inprogress():
399 pass
400
401 A Gauge can also take its value from a callback:
402
403 d = Gauge('data_objects', 'Number of objects')
404 my_dict = {}
405 d.set_function(lambda: len(my_dict))
406 """
407 _type = 'gauge'
408 _MULTIPROC_MODES = frozenset(('all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum', 'mostrecent', 'livemostrecent'))
409 _MOST_RECENT_MODES = frozenset(('mostrecent', 'livemostrecent'))
410
411 def __init__(self,
412 name: str,
413 documentation: str,
414 labelnames: Iterable[str] = (),
415 namespace: str = '',
416 subsystem: str = '',
417 unit: str = '',
418 registry: Optional[CollectorRegistry] = REGISTRY,
419 _labelvalues: Optional[Sequence[str]] = None,
420 multiprocess_mode: Literal['all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum', 'mostrecent', 'livemostrecent'] = 'all',
421 ):
422 self._multiprocess_mode = multiprocess_mode
423 if multiprocess_mode not in self._MULTIPROC_MODES:
424 raise ValueError('Invalid multiprocess mode: ' + multiprocess_mode)
425 super().__init__(
426 name=name,
427 documentation=documentation,

Callers 15

test_nolabelsMethod · 0.90
test_labelsMethod · 0.90
test_labels_tagsMethod · 0.90
test_prefixMethod · 0.90
test_prefix_tagsMethod · 0.90
test_sanitizingMethod · 0.90
test_sanitizing_tagsMethod · 0.90
test_gaugeMethod · 0.90
test_unicodeMethod · 0.90
test_escapingMethod · 0.90
setUpMethod · 0.90
test_gaugeMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_nolabelsMethod · 0.72
test_labelsMethod · 0.72
test_labels_tagsMethod · 0.72
test_prefixMethod · 0.72
test_prefix_tagsMethod · 0.72
test_sanitizingMethod · 0.72
test_sanitizing_tagsMethod · 0.72
test_gaugeMethod · 0.72
test_unicodeMethod · 0.72
test_escapingMethod · 0.72
setUpMethod · 0.72
test_gaugeMethod · 0.72