metrics

package
v0.0.0-...-9d29f1b Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package metrics contains expvar & Prometheus types and code used by Tailscale for monitoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentFDs

func CurrentFDs() int

CurrentFDs reports how many file descriptors are currently open.

It only works on Linux. It returns zero otherwise.

Types

type Histogram

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

Histogram is a histogram of values. It should be created with NewHistogram.

func NewHistogram

func NewHistogram(buckets []float64) *Histogram

NewHistogram returns a new histogram that reports to the given expvar map under the given name.

The buckets are the boundaries of the histogram buckets, in increasing order. The last bucket is +Inf.

func (*Histogram) Do

func (h *Histogram) Do(f func(expvar.KeyValue))

Do calls f for each bucket in the histogram.

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

Observe records a new observation in the histogram.

func (*Histogram) PromExport

func (h *Histogram) PromExport(w io.Writer, name string)

PromExport writes the histogram to w in Prometheus exposition format.

func (*Histogram) String

func (h *Histogram) String() string

String returns a JSON representation of the histogram. This is used to satisfy the expvar.Var interface.

type LabelMap

type LabelMap struct {
	Label string
	expvar.Map
}

LabelMap is a string-to-Var map variable that satisfies the expvar.Var interface.

Semantically, this is mapped by tsweb's Prometheus exporter as a collection of variables with the same name, with a varying label value. Use this to export things that are intuitively breakdowns into different buckets.

func (*LabelMap) Get

func (m *LabelMap) Get(key string) *expvar.Int

Get returns a direct pointer to the expvar.Int for key, creating it if necessary.

func (*LabelMap) GetFloat

func (m *LabelMap) GetFloat(key string) *expvar.Float

GetFloat returns a direct pointer to the expvar.Float for key, creating it if necessary.

func (*LabelMap) GetIncrFunc

func (m *LabelMap) GetIncrFunc(key string) func(delta int64)

GetIncrFunc returns a function that increments the expvar.Int named by key.

Most callers should not need this; it exists to satisfy an interface elsewhere.

func (*LabelMap) SetInt64

func (m *LabelMap) SetInt64(key string, v int64)

SetInt64 sets the *Int value stored under the given map key.

type Set

type Set struct {
	expvar.Map
}

Set is a string-to-Var map variable that satisfies the expvar.Var interface.

Semantically, this is mapped by tsweb's Prometheus exporter as a collection of unrelated variables exported with a common prefix.

This lets us have tsweb recognize *expvar.Map for different purposes in the future. (Or perhaps all uses of expvar.Map will require explicit types like this one, declaring how we want tsweb to export it to Prometheus.)

Jump to

Keyboard shortcuts

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