varz

package
v1.106.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: BSD-3-Clause Imports: 23 Imported by: 4 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package varz contains code to export metrics in Prometheus format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpvarDoHandler added in v1.74.0

func ExpvarDoHandler(expvarDoFunc func(f func(expvar.KeyValue))) func(http.ResponseWriter, *http.Request)

ExpvarDoHandler handler returns a Handler like above, but takes an optional expvar.Do func allow the usage of alternative containers of metrics, other than the global expvar.Map.

Unlike Handler, it does not export the Go runtime/metrics.

func Handler

func Handler(w http.ResponseWriter, r *http.Request)

Handler is an HTTP handler to write expvar values into the prometheus export format:

https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md

It makes the following assumptions:

  • *expvar.Int are counters (unless marked as a gauge_; see below)
  • a *tailscale/metrics.Set is descended into, joining keys with underscores. So use underscores as your metric names.
  • an expvar named starting with "gauge_" or "counter_" is of that Prometheus type, and has that prefix stripped.
  • anything else is untyped and thus not exported.
  • expvar.Func can return an int or int64 (for now) and anything else is not exported.

This will evolve over time, or perhaps be replaced.

It also exports the Go runtime/metrics in [runtimeMetricSpecs] and the legacy memstats_* metrics, both read from runtime/metrics.

func StaticStringVar added in v1.78.0

func StaticStringVar(s string) expvar.Var

StaticStringVar returns a new expvar.Var that always returns s.

func Uptime

func Uptime() time.Duration

func WritePrometheusExpvar

func WritePrometheusExpvar(w io.Writer, kv expvar.KeyValue)

WritePrometheusExpvar writes kv to w in Prometheus metrics format.

See VarzHandler for conventions. This is exported primarily for people to test their varz.

Types

type PrometheusMetricsReflectRooter

type PrometheusMetricsReflectRooter interface {
	expvar.Var

	// PrometheusMetricsReflectRoot returns the struct or struct pointer to walk.
	PrometheusMetricsReflectRoot() any
}

PrometheusMetricsReflectRooter is an optional interface that expvar.Var implementations can implement to indicate that they should be walked recursively with reflect to find sets of fields to export.

type PrometheusWriter added in v1.64.0

type PrometheusWriter interface {
	WritePrometheus(w io.Writer, name string)
}

PrometheusWriter is the interface implemented by metrics that can write themselves into Prometheus exposition format.

As of 2024-03-25, this is only *metrics.MultiLabelMap.

Jump to

Keyboard shortcuts

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