Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/content/collector/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ into a generator, which the registry iterates lazily without building an interme
list first. Each scrape calls `collect()` fresh, so no state carries over between
scrapes.

Memory is a secondary benefit. Yielding an object inline
(`yield GaugeMetricFamily(...)`) lets Python reclaim it as soon as the registry
advances past that point. A named variable keeps the object alive until the variable
is rebound. For most collectors this difference is negligible, but it can matter for
very large metric sets. Yielding inside a loop rather than accumulating into a list
keeps at most one object alive at a time:

```python
def collect(self):
for name in _QUEUE_NAMES:
m = GaugeMetricFamily('queue_depth', 'Queue depth', labels=['queue'])
m.add_metric([name], fetch_depth(name))
yield m
```

### `describe()`

Returns an iterable of metric family objects used only to determine the metric
Expand Down