Documentation
¶
Index ¶
- Constants
- Variables
- func ErrGenericError(text string) error
- func ErrGenericErrorWrap(text string, err error) error
- type CounterValue
- type Gauge
- type GaugeValue
- type Metrics
- func (m *Metrics) CounterAdd(name string)
- func (m *Metrics) CounterAddN(name string, delta uint64)
- func (m *Metrics) CounterRemove(name string)
- func (m *Metrics) CounterSetBatchFunc(name string, key interface{}, init func(), f func() uint64)
- func (m *Metrics) CounterSetFunc(name string, f func() uint64)
- func (m *Metrics) EncodeCounterMetrics(buf *bytes.Buffer, counters map[string]uint64) error
- func (m *Metrics) EncodeGaugeMetrics(buf *bytes.Buffer, gauges map[string]int64) error
- func (m *Metrics) GaugeRemove(name string)
- func (m *Metrics) GaugeSet(name string, value int64)
- func (m *Metrics) GaugeSetBatchFunc(name string, key interface{}, init func(), f func() int64)
- func (m *Metrics) GaugeSetFunc(name string, f func() int64)
- func (m *Metrics) Name() string
- func (m *Metrics) Reset()
- func (m *Metrics) RuntimeSnapshot()
- func (m *Metrics) Snapshot() (c map[string]uint64, g map[string]int64)
- func (m *Metrics) Start(ctx context.Context) error
- func (m *Metrics) Stop(ctx context.Context) error
- func (m *Metrics) WriteBufferToAdx(dst *adx.AzureDataExplorer, buf *bytes.Buffer) error
- type Option
Constants ¶
const ( RUNTIME_MEMSTATS_ALLOC = "runtime.MemStats.Alloc" RUNTIME_MEMSTATS_BUCKHASHSYS = "runtime.MemStats.BuckHashSys" RUNTIME_MEMSTATS_FREES = "runtime.MemStats.Frees" RUNTIME_MEMSTATS_HEAPALLOC = "runtime.MemStats.HeapAlloc" RUNTIME_MEMSTATS_HEAPIDLE = "runtime.MemStats.HeapIdle" RUNTIME_MEMSTATS_HEAPINUSE = "runtime.MemStats.HeapInuse" RUNTIME_MEMSTATS_HEAPOBJECTS = "runtime.MemStats.HeapObjects" RUNTIME_MEMSTATS_HEAPRELEASED = "runtime.MemStats.HeapReleased" RUNTIME_MEMSTATS_HEAPSYS = "runtime.MemStats.HeapSys" RUNTIME_MEMSTATS_LASTGC = "runtime.MemStats.LastGC" RUNTIME_MEMSTATS_LOOKUPS = "runtime.MemStats.Lookups" RUNTIME_MEMSTATS_MALLOCS = "runtime.MemStats.Mallocs" RUNTIME_MEMSTATS_MCACHEINUSE = "runtime.MemStats.MCacheInuse" RUNTIME_MEMSTATS_MCACHESYS = "runtime.MemStats.MCacheSys" RUNTIME_MEMSTATS_MSPANINUSE = "runtime.MemStats.MSpanInuse" RUNTIME_MEMSTATS_MSPANSYS = "runtime.MemStats.MSpanSys" RUNTIME_MEMSTATS_NEXTGC = "runtime.MemStats.NextGC" RUNTIME_MEMSTATS_NUMGC = "runtime.MemStats.NumGC" RUNTIME_MEMSTATS_PAUSENS = "runtime.MemStats.PauseNs" RUNTIME_MEMSTATS_PAUSETOTALNS = "runtime.MemStats.PauseTotalNs" RUNTIME_MEMSTATS_STACKINUSE = "runtime.MemStats.StackInuse" RUNTIME_MEMSTATS_STACKSYS = "runtime.MemStats.StackSys" RUNTIME_MEMSTATS_SYS = "runtime.MemStats.Sys" RUNTIME_MEMSTATS_TOTALALLOC = "runtime.MemStats.TotalAlloc" RUNTIME_MEMSTATS_NUMCGOCALL = "runtime.NumCgoCall" RUNTIME_MEMSTATS_NUMGOROUTINE = "runtime.NumGoroutine" RUNTIME_MEMSTATS_NUMTHREAD = "runtime.NumThread" RUNTIME_MEMSTATS_READMEMSTATS = "runtime.ReadMemStats" )
Variables ¶
var ErrMetrics = errors.New("error")
Functions ¶
func ErrGenericError ¶
func ErrGenericErrorWrap ¶
Types ¶
type CounterValue ¶
type CounterValue struct {
Name string `json:"name"`
Timestamp string `json:"timestamp" kusto:"type:datetime"`
Host string `json:"host" kusto:"name:host"`
Env string `json:"env" kusto:"name:env"`
Role string `json:"role" kusto:"name:role"`
Region string `json:"region" kusto:"name:region"`
Value uint64 `json:"value"`
}
CounterValue is a structure that holds the counter value data. It includes fields for name, timestamp, host, environment, role, region, and value.
type Gauge ¶
type Gauge string
A Gauge is an instantaneous measurement of a value. Use a gauge to track metrics which increase and decrease (e.g., amount of free memory).
type GaugeValue ¶
type GaugeValue struct {
Name string `json:"name"`
Timestamp string `json:"timestamp" kusto:"type:datetime"`
Host string `json:"host" kusto:"name:host"`
Env string `json:"env" kusto:"name:env"`
Role string `json:"role" kusto:"name:role"`
Region string `json:"region" kusto:"name:region"`
Value int64 `json:"value"`
}
GaugeValue is a structure that holds the gauge value data. It includes fields for name, timestamp, host, environment, role, region, and value.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is a structure that holds the metrics data and related configurations. It includes fields for pipeline, stop signal, counter functions, gauges, initializers, ADX gauges and counters, ADX client, configuration, logger, counters, region, hostname, environment, name, role, and mutexes for host, gauge, and counter maps.
func New ¶
New creates a new Metrics processor. It takes a configuration and an ADX client as parameters. The function initializes the processor with the provided configuration and ADX client. It also sets up the ADX counters and gauges tables. If there is an error during the setup, it wraps the error with a generic error message and returns it. If the setup is successful, it returns the initialized processor.
func (*Metrics) CounterAdd ¶
Add increments the counter by one.
func (*Metrics) CounterAddN ¶
AddN increments the counter by N.
func (*Metrics) CounterRemove ¶
Remove removes the given counter.
func (*Metrics) CounterSetBatchFunc ¶
SetBatchFunc sets the counter's value to the lazily-called return value of the given function, with an additional initializer function for a related batch of counters, all of which are keyed by an arbitrary value.
func (*Metrics) CounterSetFunc ¶
SetFunc sets the counter's value to the lazily-called return value of the given function.
func (*Metrics) EncodeCounterMetrics ¶
EncodeCounterMetrics encodes the counter metrics into a JSON format and writes it to the provided buffer. It takes a buffer and a map of counters as parameters. Each counter is encoded into a CounterValue object. If there is an error during encoding, it wraps the error with a generic error message and returns it.
func (*Metrics) EncodeGaugeMetrics ¶
EncodeGaugeMetrics encodes the gauge metrics into a JSON format and writes it to the provided buffer. It takes a buffer and a map of gauges as parameters. Each gauge is encoded into a GaugeValue object. If there is an error during encoding, it wraps the error with a generic error message and returns it.
func (*Metrics) GaugeRemove ¶
Remove removes the given gauge. It takes a name as a parameter. The function removes the gauge with the provided name.
func (*Metrics) GaugeSet ¶
Set the gauge's value to the given value. It takes a name and a value as parameters. The function sets the gauge's value to the provided value.
func (*Metrics) GaugeSetBatchFunc ¶
SetBatchFunc sets the gauge's value to the lazily-called return value of the given function, with an additional initializer function for a related batch of gauges, all of which are keyed by an arbitrary value. It takes a name, a key, an initializer function, and a function as parameters. The function sets the gauge's value to the return value of the provided function and initializes a batch of gauges.
func (*Metrics) GaugeSetFunc ¶
SetFunc sets the gauge's value to the lazily-called return value of the given function. It takes a name and a function as parameters. The function sets the gauge's value to the return value of the provided function.
func (*Metrics) Name ¶
Name returns the name of the Metrics. It does not take any parameters and returns a string. The returned string is the name field of the Metrics object.
func (*Metrics) RuntimeSnapshot ¶
func (m *Metrics) RuntimeSnapshot()
func (*Metrics) Snapshot ¶
Snapshot returns a copy of the values of all registered counters and gauges. It locks the metrics maps to prevent concurrent access, then iterates over the initializer functions and calls them. After that, it unlocks the metrics maps and returns the counters and gauges maps.
func (*Metrics) Start ¶
Start starts the metrics collection. It takes a context as a parameter. The function starts the metrics collection.
func (*Metrics) Stop ¶
Stop stops the metrics collection. It checks if the metrics collection has started, and if so, it sends a stop signal. It takes a context as a parameter. If the metrics collection is already stopped, it does nothing.
func (*Metrics) WriteBufferToAdx ¶
WriteBufferToAdx writes the contents of the provided buffer to the Azure Data Explorer (ADX). It takes a destination ADX instance and a buffer as parameters. The buffer's bytes are written to the ADX. If there is an error during writing, it wraps the error with a generic error message and returns it.
type Option ¶
type Option func(m *Metrics)
func AdxClient ¶
AdxClient is an Option that sets the ADX client for the Metrics. It takes a pointer to a kusto.Client object and returns an Option. The returned Option, when called, sets the adxClient field of a Metrics object.
func Config ¶
Config is an Option that sets the configuration for the Metrics. It takes a pointer to a config.Metrics object and returns an Option. The returned Option, when called, sets the config field of a Metrics object.
func Environment ¶
Environment is an Option that sets the environment for the Metrics. It takes a string and returns an Option. The returned Option, when called, sets the env field of a Metrics object.
func Logger ¶
Logger is an Option that sets the logger for the Metrics. It takes a pointer to a zerolog.Logger object and returns an Option. The returned Option, when called, sets the log field of a Metrics object.
func Name ¶
Name is an Option that sets the name for the Metrics. It takes a string and returns an Option. The returned Option, when called, sets the name field of a Metrics object.
func Next ¶
Next is an Option that sets the next pipeline for the Metrics. It takes a pipeline.Pipeline object and returns an Option. The returned Option, when called, sets the pipe field of a Metrics object.