docs: add API reference for CollectorRegistry and custom collector classes#1169
Conversation
…asses Closes prometheus#1163 collector/custom.md: Collector protocol section (collect/describe), value vs labels mutual exclusivity note, full constructor and add_metric tables for GaugeMetricFamily, CounterMetricFamily, SummaryMetricFamily, HistogramMetricFamily, and InfoMetricFamily, plus a runnable real-world example. collector/_index.md: constructor parameter tables for ProcessCollector, PlatformCollector, and GCCollector, with exported metrics listed for each. registry/_index.md (new): CollectorRegistry constructor and all public methods (register, unregister, collect, restricted_registry, get_sample_value, set_target_info, get_target_info), the global REGISTRY instance, and examples for isolated registry usage and registry=None. All code examples verified by running them in Python. Signed-off-by: k1chik <107162115+k1chik@users.noreply.github.com>
- GCCollector does not support registry=None on CPython; remove that claim - Remove unused CONTENT_TYPE_LATEST import from registry example - Fix 'value vs labels' section to correctly describe Summary (count_value/sum_value) and Histogram (buckets) Signed-off-by: k1chik <107162115+k1chik@users.noreply.github.com>
|
Hey. Thanks for improving on the documentation... that really helps a lot, compared to few years ago when I had to basically fiddle out most of these things from the code :-) But one thing: Why the Shouldn't Or maybe you mean this as two independent examples? client_python/docs/content/collector/custom.md Lines 16 to 21 in 482656c There I generally don't quite understand why one would Isn't the reason for custom collectors to start every time fresh (and get rid of all stale metrics, labels, etc.)? Thanks, |
|
Shouldn't do stuff late night... Still I wonder, is there any advantage over using that in the current form rather than I mean is Python' GC smart enough that it can already clean the objects that have already been In: yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
c = CounterMetricFamily('my_counter_total', 'Help text', labels=['foo'])
c.add_metric(['bar'], 1.7)
c.add_metric(['baz'], 3.8)
yield cI could imagine that it may release the In any case it would be nice to have in the docs why generators are used (if it's memory advantages) and how to use them so that this actually works out. :-) |
|
Hi @calestyo, thanks for the read! glad to see you've found the docs useful. And yes, my bad, the code examples are missing the Your GC read is right too, yield I'll open a follow-up PR with both fixes and add a note explaining why generators are used. Thanks again for your feedback.
|
* docs: clarify collect() generator usage and API Reference snippet context Add a note to the collect() protocol section explaining that yield is idiomatic (generator iterates lazily, no state between scrapes) and a preamble to the API Reference section clarifying that code snippets belong inside a collect() method. Follows up on review feedback in #1169. Signed-off-by: k1chik <kkukdia@gmail.com> * docs: split InfoMetricFamily example into two separate blocks The single block with two yield statements looked like one collect() yielding both patterns. Split into labelled prose + code pairs to make clear they are alternatives, not sequential yields. Signed-off-by: k1chik <kkukdia@gmail.com> --------- Signed-off-by: k1chik <kkukdia@gmail.com>
Closes #1163
Follows the same pattern as #1021 and #1162.
collector/custom.md: Collector protocol section (collect/describe), value vs labels mutual exclusivity note with correct per-type parameter names, full constructor and add_metric tables for GaugeMetricFamily, CounterMetricFamily, SummaryMetricFamily, HistogramMetricFamily, and InfoMetricFamily, plus a runnable real-world example.
collector/_index.md: constructor parameter tables for ProcessCollector, PlatformCollector, and GCCollector, with exported metrics listed for each.
registry/_index.md (new page): CollectorRegistry constructor and all public methods (register, unregister, collect, restricted_registry, get_sample_value, set_target_info, get_target_info), the global REGISTRY instance, and examples for isolated registry usage and registry=None.
All code examples verified by running them in Python.
cc @csmarchbanks