Documentation ¶
Overview ¶
Example ¶
package main import ( "os" "github.com/colega/gaugefuncvec" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/expfmt" ) func main() { g := gaugefuncvec.New( prometheus.GaugeOpts{ Namespace: "database", Name: "connections", Help: "Number of connections per database connection", }, []string{"connection_id"}, ) db1 := &db{conns: 42} g.MustRegister( prometheus.Labels{"connection_id": "master"}, func() float64 { return float64(db1.stats().conns) }, ) db2 := &db{conns: 288} g.MustRegister( prometheus.Labels{"connection_id": "slave"}, func() float64 { return float64(db2.stats().conns) }, ) registry := prometheus.NewRegistry() registry.MustRegister(g) gatherAndPrintMetrics(registry) } func gatherAndPrintMetrics(gatherer prometheus.Gatherer) { metrics, _ := gatherer.Gather() enc := expfmt.NewEncoder(os.Stdout, expfmt.FmtText) for _, mf := range metrics { _ = enc.Encode(mf) } } type db struct{ conns int } func (d db) stats() struct{ conns int } { return struct{ conns int }{d.conns} }
Output: # HELP database_connections Number of connections per database connection # TYPE database_connections gauge database_connections{connection_id="master"} 42 database_connections{connection_id="slave"} 288
Index ¶
- type GaugeFuncVec
- func (g *GaugeFuncVec) Collect(metrics chan<- prometheus.Metric)
- func (g *GaugeFuncVec) Describe(desc chan<- *prometheus.Desc)
- func (g *GaugeFuncVec) MustRegister(labels prometheus.Labels, function func() float64)
- func (g *GaugeFuncVec) Register(labels prometheus.Labels, function func() float64) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GaugeFuncVec ¶
type GaugeFuncVec struct {
// contains filtered or unexported fields
}
GaugeFuncVec is a prometheus.Collector that allows registering GaugeFunc's for different labels
func New ¶
func New(opts prometheus.GaugeOpts, variableLabelNames []string) *GaugeFuncVec
New returns a GaugeFuncVec variableLabelNames should not include the ConstLabels defined in GaugeOpts, it will panic if they do
func (*GaugeFuncVec) Collect ¶
func (g *GaugeFuncVec) Collect(metrics chan<- prometheus.Metric)
Collect implements prometheus.Collector
func (*GaugeFuncVec) Describe ¶
func (g *GaugeFuncVec) Describe(desc chan<- *prometheus.Desc)
Describe implements prometheus.Collector
func (*GaugeFuncVec) MustRegister ¶
func (g *GaugeFuncVec) MustRegister(labels prometheus.Labels, function func() float64)
MustRegister calls Register and panics if it returns an error
func (*GaugeFuncVec) Register ¶
func (g *GaugeFuncVec) Register(labels prometheus.Labels, function func() float64) error
Register will register a function for the given set of labels Labels should respect the variable labels provided in New() and should not collide with const labels
Click to show internal directories.
Click to hide internal directories.