Documentation ¶
Overview ¶
Package promfmt exports prometheus metrics to the default text format.
Basic usage to only show metrics that start with "prom_test"
var opsProcessed = promauto.NewCounter(prometheus.CounterOpts{ Name: "promtest_processed_ops_total", Help: "The total number of processed events", }) func main() { opsProcessed.Inc() tf := promfmt.NewPrefixFilter("promtest_") promfmt.Fprint(os.Stdout, tf) }
Main usage is aimed at simple Go binaries that run via CRON and dump their metrics in node exporter so it can be picked up. This negates the need to run your own webserver to expose the metrics and the assorted discovery from prometheus.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
func Fprint(w io.Writer, f ...FilterFunc) (int, error)
Fprint will gather all metrics using the prometheus.DefaultGatherer and will transform the metrics into text and write the result in w. The optional FilterFunc is used to filter out any unwanted metrics.
func NewPrefixFilter ¶
func NewPrefixFilter(prefix string) func(*dto.MetricFamily) bool
NewPrefixFilter returns a FilterFunc that can be used to filter on the prefix of the metric name.
Types ¶
type FilterFunc ¶
type FilterFunc func(mf *dto.MetricFamily) bool
FilterFunc is used to filter metrics, when the returned boolean is false the metrics is excluded.