Documentation
¶
Index ¶
- func CollectAndPrint(collector prometheus.Collector, names ...string)
- func FilterMetricsByName(metrics []*prommodel.MetricFamily, names ...string) []*prommodel.MetricFamily
- func GatherAndPrint(gatherer prometheus.Gatherer, names ...string)
- func MustCollect(collectors ...prometheus.Collector) prometheus.Gatherer
- func MustPrintMetrics(metrics []*prommodel.MetricFamily)
- func PrintMetrics(metrics []*prommodel.MetricFamily) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAndPrint ¶
func CollectAndPrint(collector prometheus.Collector, names ...string)
CollectAndPrint collects metrics, filters by names, and prints.
Example ¶
counterA := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_a",
Help: "counter_a help.",
})
counterA.Inc()
CollectAndPrint(counterA, "counter_a")
Output: # HELP counter_a counter_a help. # TYPE counter_a counter counter_a 1
func FilterMetricsByName ¶
func FilterMetricsByName( metrics []*prommodel.MetricFamily, names ...string, ) []*prommodel.MetricFamily
FilterMetricsByName filters metrics by specified names.
Example ¶
counterA := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_a",
Help: "counter_a help.",
})
counterB := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_b",
Help: "counter_b help.",
})
counterC := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_c",
Help: "counter_c help.",
})
counterC.Inc()
metrics, _ := MustCollect(counterA, counterB, counterC).Gather()
MustPrintMetrics(FilterMetricsByName(metrics, "counter_b", "counter_c"))
Output: # HELP counter_b counter_b help. # TYPE counter_b counter counter_b 0 # HELP counter_c counter_c help. # TYPE counter_c counter counter_c 1
func GatherAndPrint ¶
func GatherAndPrint(gatherer prometheus.Gatherer, names ...string)
GatherAndPrint gathers metrics, filters by names, and prints.
Example ¶
counterA := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_a",
Help: "counter_a help.",
})
counterB := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_b",
Help: "counter_b help.",
})
counterB.Inc()
GatherAndPrint(MustCollect(counterA, counterB), "counter_b")
Output: # HELP counter_b counter_b help. # TYPE counter_b counter counter_b 1
func MustCollect ¶
func MustCollect(collectors ...prometheus.Collector) prometheus.Gatherer
MustCollect collects metrics from collectors with pedantic checks.
Example ¶
counterA := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_a",
Help: "counter_a help.",
})
counterB := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_b",
Help: "counter_b help.",
})
counterB.Inc()
metrics, _ := MustCollect(counterA, counterB).Gather()
MustPrintMetrics(metrics)
Output: # HELP counter_a counter_a help. # TYPE counter_a counter counter_a 0 # HELP counter_b counter_b help. # TYPE counter_b counter counter_b 1
func MustPrintMetrics ¶
func MustPrintMetrics(metrics []*prommodel.MetricFamily)
MustPrintMetrics prints metrics or panic if error has occurred.
Example ¶
counterA := prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter_a",
Help: "counter_a help.",
})
counterA.Inc()
metrics, _ := MustCollect(counterA).Gather()
MustPrintMetrics(metrics)
Output: # HELP counter_a counter_a help. # TYPE counter_a counter counter_a 1
func PrintMetrics ¶
func PrintMetrics(metrics []*prommodel.MetricFamily) error
PrintMetrics prints metrics, otherwise return error.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.