Documentation ¶
Overview ¶
Package clientmetric provides client-side metrics whose values get occasionally logged.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
HasPublished reports whether a metric with the given name has already been published.
func WritePrometheusExpositionFormat ¶
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 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 ¶
NewCounter returns a new metric that can only increment.
func NewUnpublished ¶
NewUnpublished initializes a new Metric without calling Publish on it.
func (*Metric) Add ¶
Add increments m's value by n.
If m is of type counter, n should not be negative.
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.