stats

package
v2.3.0-alpha.2+incompa... Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CounterToPrometheus

func CounterToPrometheus(name string, value int, now time.Time, labels prometheus.Labels) []byte

CounterToPrometheus generates a single Prometheus line for a counter.

func NewLabels

func NewLabels(component, name string) prometheus.Labels

NewLabels creates a new prometheus.Labels with the component and name set as given.

func SetHostname

func SetHostname(h string)

SetHostname allows the hostname reported for metrics to be overridden. This is mainly intended for tests.

func SnapshotToPrometheus

func SnapshotToPrometheus(snap Snapshot, now time.Time, labels prometheus.Labels) []byte

SnapshotToPrometheus takes Snapshot produced by a Stats instance and formats it into Prometheus metrics lines using the timestamp and labels provided.

Types

type AnonStats

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

AnonStats tracks a number of counters in a goroutine safe way. Counters are addressed by integer index.

func NewAnon

func NewAnon(size int) *AnonStats

NewAnon creates a new AnonStats instance of the given size.

func (*AnonStats) Get

func (s *AnonStats) Get(i int) uint64

Get retrieves the current value of a counter. It panics if the counter is not valid.

func (*AnonStats) Inc

func (s *AnonStats) Inc(i int) uint64

Inc increments a stats counter, returning the new value. It panics if the counter is not valid.

func (*AnonStats) Max

func (s *AnonStats) Max(i int, newVal uint64) uint64

Max updates a counter if the value supplied is greater than the previous one. It panics if the counter is not valid.

func (*AnonStats) Snapshot

func (s *AnonStats) Snapshot() []uint64

Snapshot returns the current values of all the counters.

type CounterPair

type CounterPair struct {
	Name  string
	Value uint64
}

CounterPair holds the and value for one Stats counter at a given point in time.

type Snapshot

type Snapshot []CounterPair

Snapshot holds the names and values of some counters.

type Stats

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

Stats tracks a number of named counters in a goroutine safe way. It wraps an AnonStats.

func New

func New(names ...string) *Stats

New creates a new Stats instance using the provided stats names.

func (*Stats) Get

func (s *Stats) Get(name string) uint64

Get retrieves the current value of a counter. It panics if the counter is not valid.

func (*Stats) Inc

func (s *Stats) Inc(name string) uint64

Inc increments a stats counter, returning the new value. It panics if the counter is not valid.

func (*Stats) Max

func (s *Stats) Max(name string, newVal uint64) uint64

Max updates a counter if the value supplied is greater than the previous one. It panics if the name is not valid.

func (*Stats) Snapshot

func (s *Stats) Snapshot() Snapshot

Snapshot returns the current values of all the counters.

Jump to

Keyboard shortcuts

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