mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package metrics contains expvar & Prometheus types and code used by
|
|
// Tailscale for monitoring.
|
|
package metrics
|
|
|
|
import "expvar"
|
|
|
|
// 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.)
|
|
type Set struct {
|
|
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.
|
|
type LabelMap struct {
|
|
Label string
|
|
expvar.Map
|
|
}
|
|
|
|
// Get returns a direct pointer to the expvar.Int for key, creating it
|
|
// if necessary.
|
|
func (m *LabelMap) Get(key string) *expvar.Int {
|
|
m.Add(key, 0)
|
|
return m.Map.Get(key).(*expvar.Int)
|
|
}
|
|
|
|
// GetFloat returns a direct pointer to the expvar.Float for key, creating it
|
|
// if necessary.
|
|
func (m *LabelMap) GetFloat(key string) *expvar.Float {
|
|
m.AddFloat(key, 0.0)
|
|
return m.Map.Get(key).(*expvar.Float)
|
|
}
|
|
|
|
// CurrentFDs reports how many file descriptors are currently open.
|
|
//
|
|
// It only works on Linux. It returns zero otherwise.
|
|
func CurrentFDs() int {
|
|
return currentFDs()
|
|
}
|