8000 Document metric family classes · devopstiger/client_python@2c9c27c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c9c27c

Browse files
committed
Document metric family classes
1 parent ac1c45f commit 2c9c27c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,27 @@ gb.push()
293293
# Push every 10 seconds in a daemon thread.
294294
gb.start(10.0)
295295
```
296+
297+
## Custom Collectors
298+
299+
Sometimes it is not possible to directly instrument code, as it is not
300+
in your control. This requires you to proxy metrics from other systems.
301+
302+
To do so you need to create a custom collector, for example:
303+
304+
```python
305+
from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily, REGISTRY
306+
307+
class CustomCollector(object):
308+
def collect(self):
309+
yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
310+
c = CounterMetricFamily('my_counter_total', 'Help text', labels=['foo'])
311+
c.add_metric(['bar'], 1.7)
312+
c.add_metric(['baz'], 3.8)
313+
yield c
314+
315+
REGISTRY.register(CustomCollector())
316+
```
317+
318+
`SummaryMetricFamily` and `HistogramMetricFamily` work similarly.
319+

0 commit comments

Comments
 (0)
0