Documentation ¶
Index ¶
- type HistogramOpts
- type Registry
- func (r *Registry) Collect(ch chan<- prometheus.Metric)
- func (r *Registry) Describe(ch chan<- *prometheus.Desc)
- func (r *Registry) NewCounter(name, help string, opts ...metrics.Option) metrics.Counter
- func (r *Registry) NewGauge(name, help string, opts ...metrics.Option) metrics.Gauge
- func (r *Registry) NewHistogram(name, help string, opts ...metrics.Option) metrics.Histogram
- func (r *Registry) NewLabeledCounter(name, help string, labels []string, opts ...metrics.Option) metrics.LabeledCounter
- func (r *Registry) NewLabeledGauge(name, help string, labels []string, opts ...metrics.Option) metrics.LabeledGauge
- func (r *Registry) NewLabeledHistogram(name, help string, labels []string, opts ...metrics.Option) metrics.LabeledHistogram
- func (r *Registry) NewLabeledTimer(name, help string, labels []string, opts ...metrics.Option) metrics.LabeledTimer
- func (r *Registry) NewTimer(name, help string, opts ...metrics.Option) metrics.Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HistogramOpts ¶
type HistogramOpts struct {
Buckets []float64
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry describes a set of metrics. It implements metrics.Registry as well as prometheus.Collector and can thus be used as an adapter to collect Conduit metrics and deliver them to the prometheus client.
func NewRegistry ¶
NewRegistry returns a registry that is responsible for managing a collection of metrics.
Labels allows constant labels to be added to all metrics created in this registry, although this parameter should be used responsibly. See also https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels,-not-static-scraped-labels
Example ¶
package main import ( "os" "strings" "time" "github.com/conduitio/conduit/pkg/foundation/metrics" "github.com/conduitio/conduit/pkg/foundation/metrics/prometheus" promclient "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/expfmt" ) var ( testCounter = metrics.NewCounter("prom_example_counter", "example") testTimer = metrics.NewTimer("prom_example_timer", "example") // nolint:deadcode,varcheck // the whole point of this is to show that even unused gauges show up in prometheus testGauge = metrics.NewGauge("prom_example_gauge", "example") ) func main() { // create a new registry and register it in the metrics package and as a // prometheus collector reg := prometheus.NewRegistry(map[string]string{"static_label": "example"}) metrics.Register(reg) promclient.MustRegister(reg) // add a metric dynamically labeledCounter := metrics.NewLabeledCounter("prom_example_dynamic_labeled", "example", []string{"test_label"}) // observe some metrics testCounter.Inc() testTimer.Update(time.Second) labeledCounter.WithValues("val1").Inc(100) labeledCounter.WithValues("val2") // gather and print metrics gatheredMetrics, err := promclient.DefaultGatherer.Gather() if err != nil { panic(err) } enc := expfmt.NewEncoder(os.Stdout, expfmt.FmtText) for _, m := range gatheredMetrics { if strings.HasPrefix(m.GetName(), "prom_example_") { err := enc.Encode(m) if err != nil { panic(err) } } } }
Output: # HELP prom_example_counter example # TYPE prom_example_counter counter prom_example_counter{static_label="example"} 1 # HELP prom_example_dynamic_labeled example # TYPE prom_example_dynamic_labeled counter prom_example_dynamic_labeled{static_label="example",test_label="val1"} 100 prom_example_dynamic_labeled{static_label="example",test_label="val2"} 0 # HELP prom_example_gauge example # TYPE prom_example_gauge gauge prom_example_gauge{static_label="example"} 0 # HELP prom_example_timer example # TYPE prom_example_timer histogram prom_example_timer_bucket{static_label="example",le="0.005"} 0 prom_example_timer_bucket{static_label="example",le="0.01"} 0 prom_example_timer_bucket{static_label="example",le="0.025"} 0 prom_example_timer_bucket{static_label="example",le="0.05"} 0 prom_example_timer_bucket{static_label="example",le="0.1"} 0 prom_example_timer_bucket{static_label="example",le="0.25"} 0 prom_example_timer_bucket{static_label="example",le="0.5"} 0 prom_example_timer_bucket{static_label="example",le="1"} 1 prom_example_timer_bucket{static_label="example",le="2.5"} 1 prom_example_timer_bucket{static_label="example",le="5"} 1 prom_example_timer_bucket{static_label="example",le="10"} 1 prom_example_timer_bucket{static_label="example",le="+Inf"} 1 prom_example_timer_sum{static_label="example"} 1 prom_example_timer_count{static_label="example"} 1
func (*Registry) Collect ¶
func (r *Registry) Collect(ch chan<- prometheus.Metric)
func (*Registry) Describe ¶
func (r *Registry) Describe(ch chan<- *prometheus.Desc)
func (*Registry) NewCounter ¶
func (*Registry) NewHistogram ¶
func (*Registry) NewLabeledCounter ¶
func (*Registry) NewLabeledGauge ¶
func (*Registry) NewLabeledHistogram ¶
func (*Registry) NewLabeledTimer ¶
Click to show internal directories.
Click to hide internal directories.