clientmetric

package
v1.78.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: BSD-3-Clause Imports: 12 Imported by: 63

Documentation

Overview

Package clientmetric provides client-side metrics whose values get occasionally logged.

Index

Constants

This section is empty.

Variables

View Source
var TestHooks testHooks

Functions

func EncodeLogTailMetricsDelta

func EncodeLogTailMetricsDelta() string

EncodeLogTailMetricsDelta return an encoded string representing the metrics differences since the previous call.

It implements the requirements of a logtail.Config.MetricsDelta func. Notably, its output is safe to embed in a JSON string literal without further escaping.

The current encoding is:

  • name immediately following metric: 'N' + hex(varint(len(name))) + name
  • set value of a metric: 'S' + hex(varint(wireid)) + hex(varint(value))
  • increment a metric: (decrements if negative) 'I' + hex(varint(wireid)) + hex(varint(value))

func HasPublished added in v1.28.0

func HasPublished(name string) bool

HasPublished reports whether a metric with the given name has already been published.

func WritePrometheusExpositionFormat

func WritePrometheusExpositionFormat(w io.Writer)

WritePrometheusExpositionFormat writes all client metrics to w in the Prometheus text-based exposition format.

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

Types

type AggregateCounter added in v1.78.0

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

AggregateCounter returns a sum of expvar counters registered with it.

func NewAggregateCounter added in v1.78.0

func NewAggregateCounter(name string) *AggregateCounter

NewAggregateCounter returns a new aggregate counter that returns a sum of expvar variables registered with it.

func (*AggregateCounter) Register added in v1.78.0

func (c *AggregateCounter) Register(counter *expvar.Int)

Register registers provided expvar counter. When a counter is added to the counter, it will be reset to start counting from 0. This is to avoid incrementing the counter with an unexpectedly large value.

func (*AggregateCounter) UnregisterAll added in v1.78.0

func (c *AggregateCounter) UnregisterAll()

UnregisterAll unregisters all counters resulting in it starting back down at zero. This is to ensure monotonicity and respect the semantics of the counter.

func (*AggregateCounter) Value added in v1.78.0

func (c *AggregateCounter) Value() int64

type Metric

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

Metric is an integer metric value that's tracked over time.

It's safe for concurrent use.

func Metrics

func Metrics() []*Metric

Metrics returns the sorted list of metrics.

The returned slice should not be mutated.

func NewCounter

func NewCounter(name string) *Metric

NewCounter returns a new metric that can only increment.

func NewCounterFunc added in v1.40.0

func NewCounterFunc(name string, f func() int64) *Metric

NewCounterFunc returns a counter metric that has its value determined by calling the provided function (calling Add() and Set() will panic). No locking guarantees are made for the invocation.

func NewGauge

func NewGauge(name string) *Metric

NewGauge returns a new metric that can both increment and decrement.

func NewGaugeFunc added in v1.40.0

func NewGaugeFunc(name string, f func() int64) *Metric

NewGaugeFunc returns a gauge metric that has its value determined by calling the provided function (calling Add() and Set() will panic). No locking guarantees are made for the invocation.

func NewUnpublished

func NewUnpublished(name string, typ Type) *Metric

NewUnpublished initializes a new Metric without calling Publish on it.

func (*Metric) Add

func (m *Metric) Add(n int64)

Add increments m's value by n.

If m is of type counter, n should not be negative.

func (*Metric) DisableDeltas added in v1.40.0

func (m *Metric) DisableDeltas()

DisableDeltas disables uploading of deltas for this metric (absolute values are always uploaded).

func (*Metric) Name

func (m *Metric) Name() string

func (*Metric) Publish

func (m *Metric) Publish()

Publish registers a metric in the global map. It panics if the name is a duplicate anywhere in the process.

func (*Metric) Set

func (m *Metric) Set(v int64)

Set sets m's value to v.

If m is of type counter, Set should not be used.

func (*Metric) Type

func (m *Metric) Type() Type

func (*Metric) Value

func (m *Metric) Value() int64

type Type

type Type uint8

Type is a metric type: counter or gauge.

const (
	TypeGauge Type = iota
	TypeCounter
)

Jump to

Keyboard shortcuts

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