metrics

package
v1.1.1-5fda5e28 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultRotateInterval = 15

Variables

This section is empty.

Functions

This section is empty.

Types

type BasePrinter

type BasePrinter struct {
}

BasePrinter simply logs stats as structured log

func NewBasePrinter

func NewBasePrinter() *BasePrinter

NewBasePrinter returns new base printer struct

func NewCustomPrinter

func NewCustomPrinter(path string) (*BasePrinter, error)

NewCustomPrinter generates log formatter from the provided (as path) Ruby script

func (*BasePrinter) Print

func (*BasePrinter) Print(snapshot map[string]uint64)

Print logs stats data using global logger with info level

func (*BasePrinter) Run added in v1.1.0

func (p *BasePrinter) Run(interval int) error

Run prints a message to the log with metrics logging details

func (*BasePrinter) Stop added in v1.1.0

func (p *BasePrinter) Stop()

func (*BasePrinter) Write added in v1.1.0

func (p *BasePrinter) Write(m *Metrics) error

Write prints formatted snapshot to the log

type Config added in v1.0.1

type Config struct {
	Log            bool
	LogInterval    int // Deprecated
	RotateInterval int
	LogFormatter   string
	HTTP           string
	Host           string
	Port           int
	Statsd         StatsdConfig
}

Config contains metrics configuration

func NewConfig added in v1.0.1

func NewConfig() Config

NewConfig creates an empty Config struct

func (*Config) HTTPEnabled added in v1.0.1

func (c *Config) HTTPEnabled() bool

HTTPEnabled returns true iff HTTP is not empty

func (*Config) LogEnabled added in v1.0.1

func (c *Config) LogEnabled() bool

LogEnabled returns true iff any log option is specified

func (*Config) LogFormatterEnabled added in v1.0.1

func (c *Config) LogFormatterEnabled() bool

LogFormatterEnabled returns true iff LogFormatter is not empty

type Counter

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

Counter stores information about something "countable". Store

func NewCounter

func NewCounter(name string, desc string) *Counter

NewCounter creates new Counter.

func (*Counter) Add

func (c *Counter) Add(n uint64) uint64

Add adds the given number to the counter and returns the new value.

func (*Counter) Desc

func (c *Counter) Desc() string

Desc returns counter description

func (*Counter) Inc

func (c *Counter) Inc() uint64

Inc is equivalent to Add(name, 1)

func (*Counter) IntervalValue

func (c *Counter) IntervalValue() uint64

IntervalValue allows to get last interval value for counter.

func (*Counter) Name

func (c *Counter) Name() string

Name returns counter name

func (*Counter) UpdateDelta

func (c *Counter) UpdateDelta()

UpdateDelta updates the delta value for last interval based on current value and previous value.

func (*Counter) Value

func (c *Counter) Value() uint64

Value allows to get raw counter value.

type Gauge

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

Gauge stores an int value

func NewGauge

func NewGauge(name string, desc string) *Gauge

NewGauge initializes Gauge.

func (*Gauge) Dec added in v1.0.3

func (g *Gauge) Dec() uint64

Dec decrement the current value by 1

func (*Gauge) Desc

func (g *Gauge) Desc() string

Desc returns gauge description

func (*Gauge) Inc added in v1.0.3

func (g *Gauge) Inc() uint64

Inc increment the current value by 1

func (*Gauge) Name

func (g *Gauge) Name() string

Name returns gauge name

func (*Gauge) Set

func (g *Gauge) Set(value int)

Set gauge value

func (*Gauge) Set64 added in v1.0.1

func (g *Gauge) Set64(value uint64)

Set64 sets gauge value as uint64

func (*Gauge) Value

func (g *Gauge) Value() uint64

Value returns the current gauge value

type IntervalWriter added in v1.1.0

type IntervalWriter interface {
	Run(interval int) error
	Stop()
	Write(m *Metrics) error
}

IntervalHandler describe a periodical metrics writer interface

type Metrics

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

Metrics stores some useful stats about node

func FromConfig added in v1.0.1

func FromConfig(config *Config) (*Metrics, error)

FromConfig creates a new metrics instance from the prodived configuration

func NewMetrics

func NewMetrics(writers []IntervalWriter, rotateIntervalSeconds int) *Metrics

NewMetrics build new metrics struct

func (*Metrics) Counter

func (m *Metrics) Counter(name string) *Counter

Counter returns counter by name

func (*Metrics) EachCounter

func (m *Metrics) EachCounter(f func(c *Counter))

EachCounter applies function f(*Gauge) to each gauge in a set

func (*Metrics) EachGauge

func (m *Metrics) EachGauge(f func(g *Gauge))

EachGauge applies function f(*Gauge) to each gauge in a set

func (*Metrics) Gauge

func (m *Metrics) Gauge(name string) *Gauge

Gauge returns gauge by name

func (*Metrics) IntervalSnapshot

func (m *Metrics) IntervalSnapshot() map[string]uint64

IntervalSnapshot returns recorded interval metrics snapshot

func (*Metrics) Prometheus

func (m *Metrics) Prometheus() string

Prometheus returns metrics info in Prometheus format

func (*Metrics) PrometheusHandler

func (m *Metrics) PrometheusHandler(w http.ResponseWriter, r *http.Request)

PrometheusHandler is provide metrics to the world

func (*Metrics) RegisterCounter

func (m *Metrics) RegisterCounter(name string, desc string)

RegisterCounter adds new counter to the registry

func (*Metrics) RegisterGauge

func (m *Metrics) RegisterGauge(name string, desc string)

RegisterGauge adds new gauge to the registry

func (*Metrics) RegisterWriter added in v1.1.0

func (m *Metrics) RegisterWriter(w IntervalWriter)

func (*Metrics) Run

func (m *Metrics) Run() error

Run periodically updates counters delta (and logs metrics if necessary)

func (*Metrics) Shutdown

func (m *Metrics) Shutdown() (err error)

Shutdown stops metrics updates

type Printer

type Printer interface {
	Print(snapshot map[string]int64)
}

Printer describes metrics logging interface

type StatsdConfig added in v1.3.0

type StatsdConfig struct {
	Host          string
	Prefix        string
	MaxPacketSize int
}

func NewStatsdConfig added in v1.3.0

func NewStatsdConfig() StatsdConfig

func (StatsdConfig) Enabled added in v1.3.0

func (c StatsdConfig) Enabled() bool

type StatsdLogger added in v1.3.0

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

func (*StatsdLogger) Printf added in v1.3.0

func (lg *StatsdLogger) Printf(msg string, args ...interface{})

type StatsdWriter added in v1.3.0

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

func NewStatsdWriter added in v1.3.0

func NewStatsdWriter(c StatsdConfig) *StatsdWriter

func (*StatsdWriter) Run added in v1.3.0

func (sw *StatsdWriter) Run(interval int) error

func (*StatsdWriter) Stop added in v1.3.0

func (sw *StatsdWriter) Stop()

func (*StatsdWriter) Write added in v1.3.0

func (sw *StatsdWriter) Write(m *Metrics) error

Jump to

Keyboard shortcuts

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