gauge

package
v0.0.0-...-6140330 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

gauge

About

A gauge is used to keep track of discrete values over time, and export them to /private/v as a list of numbers. Thresholds can be defined to be evaluated over the values, and plugged into the healthcheck framework.

Example

Create a gauge.IntGauger, with a name for the varexp name, and a history of 30 values.

numNodes, err = gauge.Ints("my-gauge-name", 30)

Call .Gauge to emit a new value.

for range time.Tick(30 * time.Second) {
	nodes, _ := fetchLiveNodes(e.maxNodeAge, e.session)
	numNodes.Gauge(len(nodes))
}

Define a Healthcheck using various gauge.Threshold.

// DependencySet creates the set of healthchecks for BongoViewer.
func DependencySet(numNodes gauge.IntGauger) libhealth.DependencySet {
	numNodes.Set(gauge.MinIntThreshold{
		Threshold:   0,
		LastN:       1,
		Severity:    health.MINOR,
		Description: "lost connectivity once, stay calm",
	}).Set(gauge.MinIntThreshold{
		Threshold:   0,
		AnyN:        3,
		Severity:    health.MAJOR,
		Description: "lost connectivity a few times, network spotty?",
	}).Set(gauge.MinIntThreshold{
		Threshold:   0,
		LastN:       5,
		Severity:    health.OUTAGE,
		Description: "lost connectivity five times in a row, network is bad",
	})
 
	return libhealth.NewBasicDependencySet(
		libhealth.NewMonitor(
			"number-of-live-nodes-found",
			"if this goes to zero we have lost connectivity",
			"https://example.com/TODO",
			libhealth.REQUIRED,
			b.numNodes.Health,
		),
	)
}

Documentation

Overview

Package gauge provides mechanisms for gauging values.

Index

Constants

View Source
const (
	// OkMessage is the default health.Message returned
	// for things that are not currently on fire.
	OkMessage = "ok"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FloatGauger

type FloatGauger interface {
	Gaugeable
	Gauge(float64)
}

A FloatGauger represents Gaugable float values.

func Floats

func Floats(varname string, length int) (FloatGauger, error)

Floats will create a FloatGauger.

The value of varname is exported by varexp, and so it should follow the convention of being all lowercase with dashes, preferably prefixed with the name of the executable.

The specified length must be greater than zero.

Operations made available by the underlying implementation are threadsafe.

type Gaugeable

type Gaugeable interface {
	Health() libhealth.Health
	Set(threshold Threshold) Gaugeable
}

Gaugeable represents something which can apply thresholds to values collected over time, producing a resultant health.Health which represents the current state of the thing being gauged.

type IntGauger

type IntGauger interface {
	Gaugeable
	Gauge(int)
}

An IntGauger represents Gaugable int values.

func Ints

func Ints(varname string, length int) (IntGauger, error)

Ints will create an IntGauger.

The value of varname is exported by varexp, and so it should follow the convention of being all lowercase with dashes, and preferably prefixed with the name of the executable.

The specified length must be greater than zero.

Operations made available by the underlying implementation are threadsafe.

type MaxFloatThreshold

type MaxFloatThreshold floatThreshold

MaxFloatThreshold represents a maximum threshold over a sequence of float64.

func (MaxFloatThreshold) Apply

func (t MaxFloatThreshold) Apply(values *list.List) (libhealth.Status, string)

Apply the limits of t over values.

type MaxIntThreshold

type MaxIntThreshold intThreshold

MaxIntThreshold represents a maximum threshold over a sequence of int.

func (MaxIntThreshold) Apply

func (t MaxIntThreshold) Apply(values *list.List) (libhealth.Status, string)

Apply the limits of t over values.

Caller is responsible for protecting values with a lock.

type MinFloatThreshold

type MinFloatThreshold floatThreshold

MinFloatThreshold represents a minimum threshold over a sequence of float64.

func (MinFloatThreshold) Apply

func (t MinFloatThreshold) Apply(values *list.List) (libhealth.Status, string)

Apply the limits of t over values.

Caller is responsible for protecting values with a lock.

type MinIntThreshold

type MinIntThreshold intThreshold

MinIntThreshold represents a minimum threshold over a sequence of integers.

func (MinIntThreshold) Apply

func (t MinIntThreshold) Apply(values *list.List) (libhealth.Status, string)

Apply the limits of t over values.

Caller is responsible for protecting values with a lock.

type Threshold

type Threshold interface {
	Apply(*list.List) (libhealth.Status, string)
}

A Threshold represents some predicate which can be applied to an ordered list of values and return an either degraded or OK health.Status, along with a description.

Jump to

Keyboard shortcuts

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