Debian Codegraph @

docs/content/instrumenting/counter.md

raw symbols SCIP
1 ---
2 title: Counter
3 weight: 1
4 ---
5
6 Counters go up, and reset when the process restarts.
7
8
9 ```python
10 from prometheus_client import Counter
11 c = Counter('my_failures', 'Description of counter')
12 c.inc() # Increment by 1
13 c.inc(1.6) # Increment by given value
14 ```
15
16 If there is a suffix of `_total` on the metric name, it will be removed. When
17 exposing the time series for counter, a `_total` suffix will be added. This is
18 for compatibility between OpenMetrics and the Prometheus text format, as OpenMetrics
19 requires the `_total` suffix.
20
21 There are utilities to count exceptions raised:
22
23 ```python
24 @c.count_exceptions()
25 def f():
26 pass
27
28 with c.count_exceptions():
29 pass
30
31 # Count only one type of exception
32 with c.count_exceptions(ValueError):
33 pass
34 ```