// PrintAsText outputs all metrics in text format. func (r *Registry) PrintAsText(w io.Writer) error { var metricFamily prometheusgo.MetricFamily var ret error labels := r.getLabels() for _, metric := range r.tracked { metric.Inspect(func(v interface{}) { if ret != nil { return } if prom, ok := v.(PrometheusExportable); ok { metricFamily.Reset() metricFamily.Name = proto.String(exportedName(metric.GetName())) metricFamily.Help = proto.String(metric.GetHelp()) prom.FillPrometheusMetric(&metricFamily) if len(labels) != 0 { // Set labels from registry. We only set one metric in the slice, but loop anyway. for _, m := range metricFamily.Metric { m.Label = labels } } if l := prom.GetLabels(); len(l) != 0 { // Append per-metric labels. for _, m := range metricFamily.Metric { m.Label = append(m.Label, l...) } } if _, err := expfmt.MetricFamilyToText(w, &metricFamily); err != nil { ret = err } } }) } return ret }
func (r *registry) giveMetricFamily(mf *dto.MetricFamily) { mf.Reset() select { case r.metricFamilyPool <- mf: default: } }
// PrintAsText outputs all metrics in text format. func (r *Registry) PrintAsText(w io.Writer) error { var metricFamily prometheusgo.MetricFamily var ret error r.Each(func(name string, v interface{}) { if ret != nil { return } if metric, ok := v.(PrometheusExportable); ok { metricFamily.Reset() metricFamily.Name = proto.String(exportedName(name)) metric.FillPrometheusMetric(&metricFamily) if _, err := expfmt.MetricFamilyToText(w, &metricFamily); err != nil { ret = err } } }) return ret }