metrics2

package
v0.0.0-...-13f153f Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 15 Imported by: 62

Documentation

Overview

metrics2 is a client library for recording and reporting monitoring data.

Index

Constants

View Source
const (
	LIVENESS_REPORT_FREQUENCY = time.Minute
	MEASUREMENT_LIVENESS      = "liveness"
)
View Source
const (
	MEASUREMENT_TIMER = "timer"
	NAME_FUNC_TIMER   = "func_timer"
)

Variables

This section is empty.

Functions

func InitPrometheus

func InitPrometheus(port string)

InitPrometheus initializes metrics to be reported to Prometheus.

port - string, The port on which to serve the metrics, e.g. ":10110".

func NewPromClient

func NewPromClient() *promClient

Types

type BoolMetric

type BoolMetric interface {
	// Delete removes the metric from its Client's registry.
	Delete() error

	// Get returns the current value of the metric.
	Get() bool

	// Update adds a data point to the metric.
	Update(v bool)
}

BoolMetric is a metric which reports a Boolean value, represented on the backend as an int64.

func GetBoolMetric

func GetBoolMetric(measurement string, tags ...map[string]string) BoolMetric

GetBoolMetric returns a BoolMetric instance using the default client.

type Client

type Client interface {
	// Flush pushes any queued data immediately. Long running apps shouldn't worry about this as Client will auto-push every so often.
	Flush() error

	// GetCounter creates or retrieves a Counter with the given name and tag set and returns it.
	// Clients should cache this counter, as making multiple calls with the same keys will return
	// a fresh counter (initialized to 0), which is undesirable. These counters would all compete
	// with each other; the underlying metric would reflect the result of the most-recently
	// updated instance.
	GetCounter(name string, tagsList ...map[string]string) Counter

	// GetFloat64Metric returns a Float64Metric instance.
	GetFloat64Metric(measurement string, tags ...map[string]string) Float64Metric

	// GetInt64Metric returns an Int64Metric instance.
	GetInt64Metric(measurement string, tags ...map[string]string) Int64Metric

	// GetBoolMetric returns a BoolMetric instance.
	GetBoolMetric(name string, tags ...map[string]string) BoolMetric

	// GetFloat64SummaryMetric returns an Float64SummaryMetric instance.
	GetFloat64SummaryMetric(measurement string, tags ...map[string]string) Float64SummaryMetric

	// NewLiveness creates a new Liveness metric helper.
	NewLiveness(name string, tagsList ...map[string]string) Liveness

	// NewTimer creates and returns a new started timer.
	NewTimer(name string, tagsList ...map[string]string) Timer

	// Int64MetricExists returns true if the given Int64Metric already exists.
	Int64MetricExists(measurement string, tags ...map[string]string) bool
}

Client represents a set of metrics.

func GetDefaultClient

func GetDefaultClient() Client

GetDefaultClient returns the default Client.

type Counter

type Counter interface {
	// Dec decrements the counter by the given quantity.
	Dec(i int64)

	// Delete removes the counter from metrics.
	Delete() error

	// Get returns the current value in the counter.
	Get() int64

	// Inc increments the counter by the given quantity.
	Inc(i int64)

	// Reset sets the counter to zero.
	Reset()
}

Counter is a struct used for tracking metrics which increment or decrement.

func GetCounter

func GetCounter(name string, tags ...map[string]string) Counter

GetCounter creates and returns a new Counter using the default client.

type Float64Metric

type Float64Metric interface {
	// Delete removes the metric from its Client's registry.
	Delete() error

	// Get returns the current value of the metric.
	Get() float64

	// Update adds a data point to the metric.
	Update(v float64)
}

Float64Metric is a metric which reports a float64 value.

func GetFloat64Metric

func GetFloat64Metric(measurement string, tags ...map[string]string) Float64Metric

GetFloat64Metric returns a Float64Metric instance using the default client.

type Float64SummaryMetric

type Float64SummaryMetric interface {
	// Observe adds a data point to the metric.
	Observe(v float64)
}

Float64SummaryMetric is a metric which reports a summary of many float64 values.

func GetFloat64SummaryMetric

func GetFloat64SummaryMetric(measurement string, tags ...map[string]string) Float64SummaryMetric

GetFloat64SummaryMetric returns a Float64SummaryMetric instance using the default client.

type Int64Metric

type Int64Metric interface {
	// Delete removes the metric from its Client's registry.
	Delete() error

	// Get returns the current value of the metric.
	Get() int64

	// Update adds a data point to the metric.
	Update(v int64)
}

Int64Metric is a metric which reports an int64 value.

func GetInt64Metric

func GetInt64Metric(measurement string, tags ...map[string]string) Int64Metric

GetInt64Metric returns an Int64Metric instance using the default client.

type Liveness

type Liveness interface {
	// Get returns the current value of the Liveness.
	Get() int64

	// ManualReset sets the last-successful-update time of the Liveness to a specific value. Useful for tracking processes whose lifetimes are outside of that of the current process, but should not be needed in most cases.
	ManualReset(lastSuccessfulUpdate time.Time)

	// Reset should be called when some work has been successfully completed.
	Reset()

	// Close stops the internal goroutine. Usually used for testing since most Liveness instances
	// live for the duration of the process.
	Close()
}

Liveness keeps a time-since-last-successful-update metric.

The unit of the metrics is in seconds.

It is used to keep track of periodic processes to make sure that they are running successfully. Every liveness metric should have a corresponding alert set up that will fire of the time-since-last-successful-update metric gets too large.

func NewLiveness

func NewLiveness(name string, tags ...map[string]string) Liveness

NewLiveness creates a new Liveness metric helper using the default client. The current value is reported at the given frequency; if the report frequency is zero, the value is only reported when it changes.

type Timer

type Timer interface {
	// Start starts or resets the timer.
	Start()

	// Stop stops the timer and reports the elapsed time.
	Stop() time.Duration
}

Timer is a struct used for measuring elapsed time. Unlike the other metrics helpers, timer does not continuously report data; instead, it reports a single data point when Stop() is called.

func FuncTimer

func FuncTimer() Timer

FuncTimer is specifically intended for measuring the duration of functions. It uses the default client.

The standard way to use FuncTimer is at the top of the func you want to measure:

func myfunc() {
   defer metrics2.FuncTimer().Stop()
   ...
}

func NewTimer

func NewTimer(name string, tags ...map[string]string) Timer

NewTimer creates and returns a new Timer using the default client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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