type Collector … // DescribeByCollect is a helper to implement the Describe method of a custom // Collector. It collects the metrics from the provided Collector and sends // their descriptors to the provided channel. // // If a Collector collects the same metrics throughout its lifetime, its // Describe method can simply be implemented as: // // func (c customCollector) Describe(ch chan<- *Desc) { // DescribeByCollect(c, ch) // } // // However, this will not work if the metrics collected change dynamically over // the lifetime of the Collector in a way that their combined set of descriptors // changes as well. The shortcut implementation will then violate the contract // of the Describe method. If a Collector sometimes collects no metrics at all // (for example vectors like CounterVec, GaugeVec, etc., which only collect // metrics after a metric with a fully specified label set has been accessed), // it might even get registered as an unchecked Collector (cf. the Register // method of the Registerer interface). Hence, only use this shortcut // implementation of Describe if you are certain to fulfill the contract. // // The Collector example demonstrates a use of DescribeByCollect. func DescribeByCollect(c Collector, descs chan<- *Desc) { … } type selfCollector … // init provides the selfCollector with a reference to the metric it is supposed // to collect. It is usually called within the factory function to create a // metric. See example. func (c *selfCollector) init(self Metric) { … } // Describe implements Collector. func (c *selfCollector) Describe(ch chan<- *Desc) { … } // Collect implements Collector. func (c *selfCollector) Collect(ch chan<- Metric) { … } type collectorMetric …