func (sc *sliceCollector) Describe(ch chan<- *prometheus.Desc) {
	for _, m := range sc.metrics {
		ch <- m.Desc()
	}
}
Descript implements Collector.
package main
import (
	"bosun.org/opentsdb"
	"bufio"
	"fmt"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	dto "github.com/prometheus/client_model/go"
	"github.com/prometheus/common/expfmt"
	"net/http"
	"sort"
	"strconv"
	"strings"
)
func serveMetricsFromText(opentsdb bool, w http.ResponseWriter, r *http.Request, text string) error {
	reg := prometheus.NewRegistry()
	gatherers := prometheus.Gatherers{}
	var collector prometheus.Collector
	if opentsdb {
		metrics, err := translateOpenTsdb(text)
		if err != nil {
			return fmt.Errorf("Error parsing OpenTSDB text format: %v", err)
		}
		collector = &sliceCollector{metrics}
		reg.Register(collector)
		gatherers = append(gatherers, reg)
	} else {
		tp := &expfmt.TextParser{}
		nameToFam, err := tp.TextToMetricFamilies(strings.NewReader(text))
		if err != nil {
			return fmt.Errorf("Error parsing Prometheus TextFormat: %v", err)
		}
		gatherers = append(gatherers, regatherer(nameToFam))
	}
	handler := promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
	handler.ServeHTTP(w, r)
	return nil
}
type regatherer map[string]*dto.MetricFamily
func (r regatherer) Gather() ([]*dto.MetricFamily, error) {
	fams := make([]*dto.MetricFamily, 0, len(r))
	for _, fam := range r {
		for i := range fam.Metric {
			sort.Sort(prometheus.LabelPairSorter(fam.Metric[i].Label))
		}
		fams = append(fams, fam)
	}
	return fams, nil
}
type sliceCollector struct {
	metrics []prometheus.Metric
}
func (sc *sliceCollector) Collect(ch chan<- prometheus.Metric) {
	for _, m := range sc.metrics {
		ch <- m
	}
}