const capMetricChan … const capDescChan … var defaultRegistry … var DefaultRegisterer … var DefaultGatherer … func init() { … } // NewRegistry creates a new vanilla Registry without any Collectors // pre-registered. func NewRegistry() *Registry { … } // NewPedanticRegistry returns a registry that checks during collection if each // collected Metric is consistent with its reported Desc, and if the Desc has // actually been registered with the registry. Unchecked Collectors (those whose // Describe method does not yield any descriptors) are excluded from the check. // // Usually, a Registry will be happy as long as the union of all collected // Metrics is consistent and valid even if some metrics are not consistent with // their own Desc or a Desc provided by their registered Collector. Well-behaved // Collectors and Metrics will only provide consistent Descs. This Registry is // useful to test the implementation of Collectors and Metrics. func NewPedanticRegistry() *Registry { … } type Registerer … type Gatherer … // Register registers the provided Collector with the DefaultRegisterer. // // Register is a shortcut for DefaultRegisterer.Register(c). See there for more // details. func Register(c Collector) error { … } // MustRegister registers the provided Collectors with the DefaultRegisterer and // panics if any error occurs. // // MustRegister is a shortcut for DefaultRegisterer.MustRegister(cs...). See // there for more details. func MustRegister(cs ...Collector) { … } // Unregister removes the registration of the provided Collector from the // DefaultRegisterer. // // Unregister is a shortcut for DefaultRegisterer.Unregister(c). See there for // more details. func Unregister(c Collector) bool { … } type GathererFunc … // Gather implements Gatherer. func (gf GathererFunc) Gather() ([]*dto.MetricFamily, error) { … } type AlreadyRegisteredError … func (err AlreadyRegisteredError) Error() string { … } type MultiError … // Error formats the contained errors as a bullet point list, preceded by the // total number of errors. Note that this results in a multi-line string. func (errs MultiError) Error() string { … } // Append appends the provided error if it is not nil. func (errs *MultiError) Append(err error) { … } // MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only // contained error as error if len(errs is 1). In all other cases, it returns // the MultiError directly. This is helpful for returning a MultiError in a way // that only uses the MultiError if needed. func (errs MultiError) MaybeUnwrap() error { … } type Registry … // Register implements Registerer. func (r *Registry) Register(c Collector) error { … } // Unregister implements Registerer. func (r *Registry) Unregister(c Collector) bool { … } // MustRegister implements Registerer. func (r *Registry) MustRegister(cs ...Collector) { … } // Gather implements Gatherer. func (r *Registry) Gather() ([]*dto.MetricFamily, error) { … } // Describe implements Collector. func (r *Registry) Describe(ch chan<- *Desc) { … } // Collect implements Collector. func (r *Registry) Collect(ch chan<- Metric) { … } // WriteToTextfile calls Gather on the provided Gatherer, encodes the result in the // Prometheus text format, and writes it to a temporary file. Upon success, the // temporary file is renamed to the provided filename. // // This is intended for use with the textfile collector of the node exporter. // Note that the node exporter expects the filename to be suffixed with ".prom". func WriteToTextfile(filename string, g Gatherer) error { … } // processMetric is an internal helper method only used by the Gather method. func processMetric( metric Metric, metricFamiliesByName map[string]*dto.MetricFamily, metricHashes map[uint64]struct{ … } type Gatherers … // Gather implements Gatherer. func (gs Gatherers) Gather() ([]*dto.MetricFamily, error) { … } // checkSuffixCollisions checks for collisions with the “magic” suffixes the // Prometheus text format and the internal metric representation of the // Prometheus server add while flattening Summaries and Histograms. func checkSuffixCollisions(mf *dto.MetricFamily, mfs map[string]*dto.MetricFamily) error { … } // checkMetricConsistency checks if the provided Metric is consistent with the // provided MetricFamily. It also hashes the Metric labels and the MetricFamily // name. If the resulting hash is already in the provided metricHashes, an error // is returned. If not, it is added to metricHashes. func checkMetricConsistency( metricFamily *dto.MetricFamily, dtoMetric *dto.Metric, metricHashes map[uint64]struct{ … } func checkDescConsistency( metricFamily *dto.MetricFamily, dtoMetric *dto.Metric, desc *Desc, ) error { … } var _ … type MultiTRegistry … // NewMultiTRegistry creates MultiTRegistry. func NewMultiTRegistry(tGatherers ...TransactionalGatherer) *MultiTRegistry { … } // Gather implements TransactionalGatherer interface. func (r *MultiTRegistry) Gather() (mfs []*dto.MetricFamily, done func(), err error) { … } type TransactionalGatherer … // ToTransactionalGatherer transforms Gatherer to transactional one with noop as done function. func ToTransactionalGatherer(g Gatherer) TransactionalGatherer { … } type noTransactionGatherer … // Gather implements TransactionalGatherer interface. func (g *noTransactionGatherer) Gather() (_ []*dto.MetricFamily, done func(), err error) { … }