Debian Codegraph @

docs/content/instrumenting/gauge.md

raw symbols SCIP
1 ---
2 title: Gauge
3 weight: 2
4 ---
5
6 Gauges can go up and down.
7
8 ```python
9 from prometheus_client import Gauge
10 g = Gauge('my_inprogress_requests', 'Description of gauge')
11 g.inc() # Increment by 1
12 g.dec(10) # Decrement by given value
13 g.set(4.2) # Set to a given value
14 ```
15
16 There are utilities for common use cases:
17
18 ```python
19 g.set_to_current_time() # Set to current unixtime
20
21 # Increment when entered, decrement when exited.
22 @g.track_inprogress()
23 def f():
24 pass
25
26 with g.track_inprogress():
27 pass
28 ```
29
30 A Gauge can also take its value from a callback:
31
32 ```python
33 d = Gauge('data_objects', 'Number of objects')
34 my_dict = {}
35 d.set_function(lambda: len(my_dict))
36 ```