in prometheus/metrics_collector.go [46:94]
func (mc *metricCollector) registerMetrics() {
for idx := 0; idx < mc.metricCount; idx++ {
namespace := "test"
counter := prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Name: fmt.Sprintf("counter%v", idx),
Help: "This is my counter",
// labels can be added like this
// ConstLabels: prometheus.Labels{
// "label1": "val1",
// },
})
gauge := prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: fmt.Sprintf("gauge%v", idx),
Help: "This is my gauge",
})
histogram := prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Name: fmt.Sprintf("histogram%v", idx),
Help: "This is my histogram",
Buckets: []float64{0.005, 0.1, 1},
})
summary := prometheus.NewSummary(
prometheus.SummaryOpts{
Namespace: namespace,
Name: fmt.Sprintf("summary%v", idx),
Help: "This is my summary",
Objectives: map[float64]float64{
0.1: 0.5,
0.5: 0.5,
0.99: 0.5,
},
})
promRegistry.MustRegister(counter)
promRegistry.MustRegister(gauge)
promRegistry.MustRegister(histogram)
promRegistry.MustRegister(summary)
mc.counters = append(mc.counters, counter)
mc.gauges = append(mc.gauges, gauge)
mc.histograms = append(mc.histograms, histogram)
mc.summarys = append(mc.summarys, summary)
}
}