metrics

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: MIT Imports: 10 Imported by: 807

README

Build Status GoDoc Go Report codecov

metrics - lightweight alternative to github.com/prometheus/client_golang/prometheus.

Features
  • Lightweight. Has minimal number of third-party dependencies and all these deps are small. See this article for details.
  • Easy to use. See the API docs.
  • Fast.
Limitations
Usage
var (
	requestsTotal = metrics.NewCounter("requests_total")

	queueSize = metrics.NewGauge(`queue_size{queue="foobar"}`, func() float64 {
		return float64(foobarQueue.Len())
	})

	requestDuration = metrics.NewSummary(`requests_duration_seconds{handler="/my/super/handler"}`)
)

func requestHandler() {
	startTime := time.Now()
	...
	requestsTotal.Inc()
	requestDuration.UpdateDuration(startTime)
}

See docs for more info.

Users

Documentation

Overview

Package metrics implements Prometheus-compatible metrics for applications.

This package is similar to https://github.com/prometheus/client_golang , but is simpler to use and is more lightweight.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGauge

func NewGauge(name string, f func() float64)

NewGauge creates a gauge with the given name, which calls f to obtain gauge value.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

f must be safe for concurrent calls.

func WritePrometheus

func WritePrometheus(w io.Writer, exposeProcessMetrics bool)

WritePrometheus writes all the registered metrics in Prometheus format to w.

If exposeProcessMetrics is true, then various `go_*` metrics are exposed for the current process.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a counter.

It may be used as a gauge if Dec and Set are called.

func NewCounter

func NewCounter(name string) *Counter

NewCounter creates and returns new counter with the given name.

name must be valid Prometheus-compatible metric with possible lables. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned counter is safe to use from concurrent goroutines.

func (*Counter) Add

func (c *Counter) Add(n int)

Add adds n to c.

func (*Counter) Dec

func (c *Counter) Dec()

Dec decrements c.

func (*Counter) Get

func (c *Counter) Get() uint64

Get returns the current value for c.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments c.

func (*Counter) Set

func (c *Counter) Set(n uint64)

Set sets c value to n.

type Summary

type Summary struct {
	// contains filtered or unexported fields
}

Summary implements summary.

func NewSummary

func NewSummary(name string) *Summary

NewSummary creates and returns new summary with the given name.

name must be valid Prometheus-compatible metric with possible lables. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

func NewSummaryExt

func NewSummaryExt(name string, window time.Duration, quantiles []float64) *Summary

NewSummaryExt creates and returns new summary with the given name, window and quantiles.

name must be valid Prometheus-compatible metric with possible lables. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

func (*Summary) Update

func (s *Summary) Update(v float64)

Update updates the summary.

func (*Summary) UpdateDuration

func (s *Summary) UpdateDuration(startTime time.Time)

UpdateDuration updates request duration based on the given startTime.

Jump to

Keyboard shortcuts

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