File tree 1 file changed +24
-0
lines changed 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -293,3 +293,27 @@ gb.push()
293
293
# Push every 10 seconds in a daemon thread.
294
294
gb.start(10.0 )
295
295
```
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
+
You can’t perform that action at this time.
0 commit comments