testutil

package
v0.0.0-...-8de0eed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL