circonus-gometrics.go
func (m *CirconusMetrics) PromOutput() (*bytes.Buffer, error) {
	m.lastMetrics.metricsmu.Lock()
	defer m.lastMetrics.metricsmu.Unlock()

	if m.lastMetrics.metrics == nil {
		return nil, errors.New("no metrics available")
	}

	var b bytes.Buffer
	w := bufio.NewWriter(&b)

	ts := m.lastMetrics.ts.UnixNano() / int64(time.Millisecond)

	for name, metric := range *m.lastMetrics.metrics {
		switch metric.Type {
		case "n":
			if strings.HasPrefix(fmt.Sprintf("%v", metric.Value), "[H[") {
				continue // circonus histogram != prom "histogram" (aka percentile)
			}
		case "s":
			continue // text metrics unsupported
		}
		fmt.Fprintf(w, "%s %v %d\n", name, metric.Value, ts)
	}

	err := w.Flush()
	if err != nil {
		return nil, errors.Wrap(err, "flushing metric buffer")
	}

	return &b, err
}
func (m *CirconusMetrics) PromOutput() (*bytes.Buffer, error) {
	m.lastMetrics.metricsmu.Lock()
	defer m.lastMetrics.metricsmu.Unlock()

	if m.lastMetrics.metrics == nil {
		return nil, errors.New("no metrics available")
	}

	var b bytes.Buffer
	w := bufio.NewWriter(&b)

	ts := m.lastMetrics.ts.UnixNano() / int64(time.Millisecond)

	for name, metric := range *m.lastMetrics.metrics {
		switch metric.Type {
		case "n":
			if strings.HasPrefix(fmt.Sprintf("%v", metric.Value), "[H[") {
				continue // circonus histogram != prom "histogram" (aka percentile)
			}
		case "s":
			continue // text metrics unsupported
		}
		fmt.Fprintf(w, "%s %v %d\n", name, metric.Value, ts)
	}

	err := w.Flush()
	if err != nil {
		return nil, errors.Wrap(err, "flushing metric buffer")
	}

	return &b, err
}
func ( m * CirconusMetrics ) PromOutput ( ) ( * bytes . Buffer , error ) { m . lastMetrics . metricsmu . Lock ( ) defer m . lastMetrics . metricsmu . Unlock ( ) if m . lastMetrics . metrics == nil { return nil , errors . New ( " " ) } var b bytes . Buffer w := bufio . NewWriter ( & b ) ts := m . lastMetrics . ts . UnixNano ( ) / int64 ( time . Millisecond ) for name , metric := range * m . lastMetrics . metrics { switch metric . Type { case " " : if strings . HasPrefix ( fmt . Sprintf ( " " , metric . Value ) , " " ) { continue // circonus histogram != prom "histogram" (aka percentile) } case " " : continue // text metrics unsupported } fmt . Fprintf ( w , " \n " , name , metric . Value , ts ) } err := w . Flush ( ) if err != nil { return nil , errors . Wrap ( err , " " ) } return & b , err }
// PromOutput returns lines of metrics in prom format
PromOutput returns lines of metrics in prom format