Documentation ¶
Overview ¶
Package promfmt exports prometheus metrics to the default text format.
Basic usage to only show metrics that start with "promtest_"
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.
func WriteFile ¶ added in v0.0.9
func WriteFile(name string, f ...FilterFunc) error
WriteFile will gather all metrics using the prometheus.DefaultGatherer and will transform the metrics into text and write to the file named name. The file write is atomic (on Unix) by writing to a temp file and then moving it into place.
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.