Documentation
¶
Overview ¶
Package labelcache reuses the label pairs of const metrics between scrapes.
prometheus.NewConstMetric builds and sorts the label pairs of a series on every call. For series whose value changes on every scrape, such as process counters, internal/metriccache can't reuse the metric, but the labels stay the same as long as the series exists. A Scrape hands out metrics that share the label pairs built for the same series in an earlier scrape. Series that a scrape doesn't report are dropped when it commits.
Label pairs are interned: all series with the same label name and value, such as the process and process_id labels of the series of one process, share one pair, so the cache keeps little more than one slice per series.
A collector lists its caches in ScrapeCaches (see internal/scrapecache). The collection resets them around Build and Close and begins and ends a scrape around each Collect call, which gets it from Cache.Scrape.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds the label pairs of the series of the latest scrapes. The zero value is ready to use.
func (*Cache) Begin ¶
Begin starts a scrape. Call Commit when it is done.
Collectors don't call Begin: the collection begins and ends their scrapes through BeginScrape and EndScrape, and Collect gets its scrape from Cache.Scrape.
func (*Cache) BeginScrape ¶
func (c *Cache) BeginScrape()
BeginScrape begins a scrape. The collection calls it before Collect.
func (*Cache) EndScrape ¶
EndScrape ends the scrape begun by BeginScrape. The collection calls it once Collect returned err.
A scrape that Collect never asked for leaves the cache unchanged. Otherwise the scrape is committed, unless Collect failed before it created a metric: then the series of the previous scrapes stay.
func (*Cache) Reset ¶
func (c *Cache) Reset()
Reset drops all cached label pairs, for example when the collector closes.
func (*Cache) Scrape ¶
Scrape returns the scrape of the running Collect call, which it creates on the first call. It is nil outside of a scrape begun by the collection, for example when Collect is called directly; a nil Scrape creates metrics without the cache.
Only Collect and the workers it waits for may call Scrape: after Collect returned, it returns nil or the scrape of a later Collect call.
type Scrape ¶
type Scrape struct {
// contains filtered or unexported fields
}
Scrape creates the metrics of one scrape.
func (*Scrape) Commit ¶
func (s *Scrape) Commit()
Commit drops the series that neither this scrape nor a newer one reported, and the label pairs only they used.
func (*Scrape) MustNewConstMetric ¶
func (s *Scrape) MustNewConstMetric(desc *prometheus.Desc, valueType prometheus.ValueType, value float64, labelValues ...string) prometheus.Metric
MustNewConstMetric is prometheus.MustNewConstMetric, but it reuses the label pairs of the series from an earlier scrape. A nil Scrape creates the metric without the cache.