metrics

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetricGroup name format for each user.
	UserMetricGroupFormat = "user - %s"

	UserMetricUploadBytes   = "UploadBytes"
	UserMetricDownloadBytes = "DownloadBytes"
)

Variables

View Source
var (
	// Max number of connections ever reached.
	MaxConn = RegisterMetric("connections", "MaxConn", GAUGE)

	// Accumulated active open connections.
	ActiveOpens = RegisterMetric("connections", "ActiveOpens", COUNTER)

	// Accumulated passive open connections.
	PassiveOpens = RegisterMetric("connections", "PassiveOpens", COUNTER)

	// Current number of established connections.
	CurrEstablished = RegisterMetric("connections", "CurrEstablished", GAUGE)

	// Number of bytes from client to server.
	UploadBytes = RegisterMetric("traffic", "UploadBytes", COUNTER)

	// Number of bytes from server to client.
	DownloadBytes = RegisterMetric("traffic", "DownloadBytes", COUNTER)

	// Number of padding bytes send to proxy connections.
	OutputPaddingBytes = RegisterMetric("traffic", "OutputPaddingBytes", COUNTER)
)

Functions

func DisableLogging

func DisableLogging()

Disable metrics logging.

func DisableMetricsDump

func DisableMetricsDump()

Stop dumping metrics to a file when it is logged.

func DumpMetricsNow

func DumpMetricsNow() error

DumpMetricsNow writes the current metrics to the dump file. This function can be called when metrics dump is disabled.

func EnableLogging

func EnableLogging()

Enable metrics logging with the given time duration. This function should not be called again before disable logging.

func EnableMetricsDump

func EnableMetricsDump() error

Dump metrics to a file when it is logged.

func GetMetricsAsJSON

func GetMetricsAsJSON() ([]byte, error)

GetMetricsAsJSON returns a JSON representation of all the metrics.

func LoadMetricsFromDump

func LoadMetricsFromDump() error

func LogMetricsNow

func LogMetricsNow()

LogMetricsNow writes the current metrics to log. This function can be called when (periodic) logging is disabled.

func SetLoggingDuration

func SetLoggingDuration(duration time.Duration) error

Set the metrics logging time duration. Need to disable and enable logging to make the change effective.

func SetMetricsDumpFilePath

func SetMetricsDumpFilePath(path string)

Types

type Counter

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

Counter holds a named int64 value that can't decrease.

If time series is enabled, user can query history updates in a given time range.

func (*Counter) Add

func (c *Counter) Add(delta int64) int64

func (*Counter) DeltaBetween

func (c *Counter) DeltaBetween(t1, t2 time.Time) int64

DeltaBetween returns the increment between t1 and t2.

func (*Counter) Load

func (c *Counter) Load() int64

func (*Counter) Name

func (c *Counter) Name() string

func (*Counter) Store

func (c *Counter) Store(val int64)

func (*Counter) Type

func (c *Counter) Type() MetricType

type Gauge

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

Gauge holds a named int64 value.

func (*Gauge) Add

func (g *Gauge) Add(delta int64) int64

func (*Gauge) Load

func (g *Gauge) Load() int64

func (*Gauge) Name

func (g *Gauge) Name() string

func (*Gauge) Store

func (g *Gauge) Store(val int64)

func (*Gauge) Type

func (g *Gauge) Type() MetricType

type Metric

type Metric interface {
	// Name returns the name of metric.
	Name() string

	// Type returns the metric type.
	Type() MetricType

	// Add increase or decrease the metric by the given value.
	Add(delta int64) int64

	// Load returns the current value of the metric.
	Load() int64

	// Store sets the metric to a particular value.
	// This operation is only supported by a GAUGE metric.
	Store(val int64)
}

Metric defines supported operations of a single metric.

func RegisterMetric

func RegisterMetric(groupName, metricName string, metricType MetricType) Metric

RegisterMetric registers a new metric. The caller should not take the ownership of the returned pointer. If the same metric is registered multiple times, the pointer to the first object is returned.

type MetricGroup

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

MetricGroup holds a list of metric under the same group.

func GetMetricGroupByName

func GetMetricGroupByName(groupName string) *MetricGroup

GetMetricGroupByName returns the MetricGroup by name. It returns nil if the MetricGroup is not found.

func (*MetricGroup) DisableLogging

func (g *MetricGroup) DisableLogging()

DisableLogging disables logging of this MetricGroup.

func (*MetricGroup) EnableLogging

func (g *MetricGroup) EnableLogging()

EnableLogging enables logging of this MetricGroup.

func (*MetricGroup) GetMetric

func (g *MetricGroup) GetMetric(name string) (Metric, bool)

GetMetric returns one metric from the metric group.

func (*MetricGroup) IsLoggingEnabled

func (g *MetricGroup) IsLoggingEnabled() bool

IsLoggingEnabled returns if logging is enabled in this MetricGroup.

func (*MetricGroup) NewLogFields

func (g *MetricGroup) NewLogFields() log.Fields

NewLogFields creates log fields from the MetricGroup.

func (*MetricGroup) NewLogMsg

func (g *MetricGroup) NewLogMsg() string

NewLogMsg creates a base log message without fields from the MetricGroup.

type MetricGroupList

type MetricGroupList []*MetricGroup

MetricGroupList is a list of MetricGroup.

func (MetricGroupList) Append

func (l MetricGroupList) Append(group *MetricGroup) MetricGroupList

Append adds a new MetricGroup to the end of list.

func (MetricGroupList) Len

func (l MetricGroupList) Len() int

Len implements sort.Interface.

func (MetricGroupList) Less

func (l MetricGroupList) Less(i, j int) bool

Less implements sort.Interface.

func (MetricGroupList) MarshalJSON

func (l MetricGroupList) MarshalJSON() ([]byte, error)

MarshalJSON export the content of MetricGroupList in JSON format.

func (MetricGroupList) Swap

func (l MetricGroupList) Swap(i, j int)

Swap implements sort.Interface.

type MetricType

type MetricType uint8
const (
	COUNTER MetricType = iota
	COUNTER_TIME_SERIES
	GAUGE
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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