metrics

package
v0.0.0-...-57b1a46 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var ErrMetrics = errors.New("error")

Functions

func ErrGenericError

func ErrGenericError(text string) error

func ErrGenericErrorWrap

func ErrGenericErrorWrap(text string, err error) error

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

func New(opts ...Option) (*Metrics, error)

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

func (m *Metrics) CounterAdd(name string)

Add increments the counter by one.

func (*Metrics) CounterAddN

func (m *Metrics) CounterAddN(name string, delta uint64)

AddN increments the counter by N.

func (*Metrics) CounterRemove

func (m *Metrics) CounterRemove(name string)

Remove removes the given counter.

func (*Metrics) CounterSetBatchFunc

func (m *Metrics) CounterSetBatchFunc(name string, key interface{}, init func(), f func() uint64)

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

func (m *Metrics) CounterSetFunc(name string, f func() uint64)

SetFunc sets the counter's value to the lazily-called return value of the given function.

func (*Metrics) EncodeCounterMetrics

func (m *Metrics) EncodeCounterMetrics(buf *bytes.Buffer, counters map[string]uint64) error

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

func (m *Metrics) EncodeGaugeMetrics(buf *bytes.Buffer, gauges map[string]int64) error

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

func (m *Metrics) GaugeRemove(name string)

Remove removes the given gauge. It takes a name as a parameter. The function removes the gauge with the provided name.

func (*Metrics) GaugeSet

func (m *Metrics) GaugeSet(name string, value int64)

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

func (m *Metrics) GaugeSetBatchFunc(name string, key interface{}, init func(), f func() int64)

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

func (m *Metrics) GaugeSetFunc(name string, f func() int64)

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

func (m *Metrics) Name() string

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) Reset

func (m *Metrics) Reset()

Reset removes all existing counters and gauges.

func (*Metrics) RuntimeSnapshot

func (m *Metrics) RuntimeSnapshot()

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() (c map[string]uint64, g map[string]int64)

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

func (m *Metrics) Start(ctx context.Context) error

Start starts the metrics collection. It takes a context as a parameter. The function starts the metrics collection.

func (*Metrics) Stop

func (m *Metrics) Stop(ctx context.Context) error

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

func (m *Metrics) WriteBufferToAdx(dst *adx.AzureDataExplorer, buf *bytes.Buffer) error

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

func AdxClient(client *kusto.Client) Option

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

func Config(cfg *config.Metrics) Option

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

func Environment(name string) Option

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

func Logger(log *zerolog.Logger) Option

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

func Name(name string) Option

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

func Next(next pipeline.Pipeline) Option

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.

func Region

func Region(name string) Option

Region is an Option that sets the region for the Metrics. It takes a string and returns an Option. The returned Option, when called, sets the region field of a Metrics object.

func Role

func Role(name string) Option

Role is an Option that sets the role for the Metrics. It takes a string and returns an Option. The returned Option, when called, sets the role field of a Metrics object.

Jump to

Keyboard shortcuts

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