Movatterモバイル変換


[0]ホーム

URL:


metrics

package
v1.92.3Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License:BSD-3-ClauseImports:12Imported by:23

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcCurrentFDsadded inv1.16.0

func CurrentFDs()int

CurrentFDs reports how many file descriptors are currently open.

It only works on Linux. It returns zero otherwise.

funcLabelStringadded inv1.74.0

func LabelString(kany)string

LabelString returns a Prometheus-formatted label string for the given key.k must be a struct type with scalar fields, as required by MultiLabelMap,if k is not a struct, it will panic.

Types

typeHistogramadded inv1.46.0

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

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

funcNewHistogramadded inv1.46.0

func NewHistogram(buckets []float64) *Histogram

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

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

func (*Histogram)Doadded inv1.46.0

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

Do calls f for each bucket in the histogram.

func (*Histogram)Observeadded inv1.46.0

func (h *Histogram) Observe(vfloat64)

Observe records a new observation in the histogram.

func (*Histogram)PromExportadded inv1.46.0

func (h *Histogram) PromExport(wio.Writer, namestring)

PromExport writes the histogram to w in Prometheus exposition format.

func (*Histogram)Stringadded inv1.46.0

func (h *Histogram) String()string

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

typeKeyValueadded inv1.64.0

type KeyValue[Tcomparable] struct {Key   TValueexpvar.Var}

KeyValue represents a single entry in aMultiLabelMap.

typeLabelMap

type LabelMap struct {Labelstringexpvar.Map// contains filtered or unexported fields}

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

Semantically, this is mapped by tsweb's Prometheus exporter as acollection of variables with the same name, with a varying labelvalue. Use this to export things that are intuitively breakdownsinto different buckets.

func (*LabelMap)Addadded inv1.80.0

func (m *LabelMap) Add(keystring, deltaint64)

Add adds delta to the any int-like value stored under the given map key.

func (*LabelMap)Get

func (m *LabelMap) Get(keystring) *expvar.Int

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

func (*LabelMap)GetFloatadded inv1.0.0

func (m *LabelMap) GetFloat(keystring) *expvar.Float

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

func (*LabelMap)GetIncrFuncadded inv1.46.0

func (m *LabelMap) GetIncrFunc(keystring) func(deltaint64)

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

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

func (*LabelMap)GetShardedIntadded inv1.80.0

func (m *LabelMap) GetShardedInt(keystring) *syncs.ShardedInt

GetShardedInt returns a direct pointer to the syncs.ShardedInt for key,creating it if necessary.

func (*LabelMap)SetInt64added inv1.38.0

func (m *LabelMap) SetInt64(keystring, vint64)

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

typeMultiLabelMapadded inv1.64.0

type MultiLabelMap[Tcomparable] struct {Typestring// optional Prometheus type ("counter", "gauge")Helpstring// optional Prometheus help string// contains filtered or unexported fields}

MultiLabelMap is a struct-value-to-Var map variable that satisfies theexpvar.Var interface but also allows for multiple Prometheus labels to beassociated with each value.

T must be a struct type with scalar fields. The struct field names(lowercased) are used as the labels, unless a "prom" struct tag is present.The struct fields must all be strings, and the string values must be validPrometheus label values without requiring quoting.

funcNewMultiLabelMapadded inv1.64.0

func NewMultiLabelMap[Tcomparable](namestring, promType, helpTextstring) *MultiLabelMap[T]

NewMultiLabelMap creates and publishes (via expvar.Publish) a newMultiLabelMap[T] variable with the given name and returns it.

func (*MultiLabelMap[T])Addadded inv1.64.0

func (v *MultiLabelMap[T]) Add(key T, deltaint64)

Add adds delta to the *expvar.Int value stored under the given map key,creating it if it doesn't exist yet.It does nothing if key exists but is of the wrong type.

func (*MultiLabelMap[T])AddFloatadded inv1.64.0

func (v *MultiLabelMap[T]) AddFloat(key T, deltafloat64)

Add adds delta to the *expvar.Float value stored under the given map key,creating it if it doesn't exist yet.It does nothing if key exists but is of the wrong type.

func (*MultiLabelMap[T])Deleteadded inv1.64.0

func (v *MultiLabelMap[T]) Delete(key T)

Delete deletes the given key from the map.

This is not optimized for highly concurrent usage; it's presumed to only beused rarely, at startup.

func (*MultiLabelMap[T])Doadded inv1.64.0

func (v *MultiLabelMap[T]) Do(f func(KeyValue[T]))

Do calls f for each entry in the map.The map is locked during the iteration,but existing entries may be concurrently updated.

func (*MultiLabelMap[T])Getadded inv1.64.0

func (v *MultiLabelMap[T]) Get(key T)expvar.Var

Get returns the expvar for the given key, or nil if it doesn't exist.

func (*MultiLabelMap[T])Initadded inv1.64.0

func (v *MultiLabelMap[T]) Init() *MultiLabelMap[T]

Init removes all keys from the map.

Think of it as "Reset", but it's named Init to match expvar.Map.Init.

func (*MultiLabelMap[T])ResetAllForTestadded inv1.76.0

func (v *MultiLabelMap[T]) ResetAllForTest()

ResetAllForTest resets all values for metrics to zero.Should only be used in tests.

func (*MultiLabelMap[T])Setadded inv1.64.0

func (v *MultiLabelMap[T]) Set(key T, valexpvar.Var)

Set sets key to val.

This is not optimized for highly concurrent usage; it's presumed to only beused rarely, at startup.

func (*MultiLabelMap[T])SetFloatadded inv1.74.0

func (v *MultiLabelMap[T]) SetFloat(key T, valfloat64)

SetFloat sets val to the *expvar.Float value stored under the given map key,creating it if it doesn't exist yet.It does nothing if key exists but is of the wrong type.

func (*MultiLabelMap[T])SetIntadded inv1.74.0

func (v *MultiLabelMap[T]) SetInt(key T, valint64)

SetInt sets val to the *expvar.Int value stored under the given map key,creating it if it doesn't exist yet.It does nothing if key exists but is of the wrong type.

func (*MultiLabelMap[T])Stringadded inv1.64.0

func (v *MultiLabelMap[T]) String()string

func (*MultiLabelMap[T])WritePrometheusadded inv1.64.0

func (v *MultiLabelMap[T]) WritePrometheus(wio.Writer, namestring)

WritePrometheus writes v to w in Prometheus exposition format.The name argument is the metric name.

typeSet

type Set struct {expvar.Map}

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

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

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

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp