metriks

package
v0.63.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distribution added in v0.51.0

func Distribution(name string, value float64, tags ...metrics.Label)

Distribution will report the value as a distribution metric to datadog. it only makes sense when you're using the datadog sink

func Gauge

func Gauge(name string, val float32, labels ...metrics.Label)

Gauge is used to report a single float32 value. It is most often used during a periodic update or timer to report the current size of a queue or how many connections are currently connected.

func GaugeLabels

func GaugeLabels(name string, labels []metrics.Label, val float32)

GaugeLabels is the same as Gauge but with additional labels

func Inc

func Inc(name string, val int64, labels ...metrics.Label)

Inc increments a simple counter

Example:

metriks.Inc("publisher.errors", 1)

func IncLabels

func IncLabels(name string, labels []metrics.Label, val int64)

IncLabels increments a counter with additional labels

Example:

metriks.IncLabels("publisher.errors", metriks.Labels(metriks.L("status_class", "4xx")), 1)

func Init

func Init(serviceName string, conf Config) error

Init will initialize the internal metrics system with a Datadog statsd sink

func InitTags

func InitTags(serviceName string, conf Config, extraTags []string) error

InitTags behaves like Init but allows appending extra tags

func InitWithSink

func InitWithSink(serviceName string, sink metrics.MetricSink) error

InitWithSink initializes the internal metrics system with custom sink

func InitWithURL

func InitWithURL(serviceName string, endpoint string) (metrics.MetricSink, error)

InitWithURL will initialize using a URL to identify the sink type

Examples:

InitWithURL("api", "datadog://187.32.21.12:8125/?hostname=foo.com&tag=env:production")

InitWithURL("api", "discard://nothing")

InitWithURL("api", "inmem://discarded/?interval=10s&duration=30s")

func L

func L(name string, value string) metrics.Label

L returns a single label, kept short for conciseness

func Labels

func Labels(labels ...metrics.Label) []metrics.Label

Labels builds a dynamic list of labels

func MeasureSince

func MeasureSince(name string, start time.Time, labels ...metrics.Label)

MeasureSince records the time from start until the invocation of the function It is usually used with `defer` to record time of a function.

Example:

func getRows() ([]Row) {
  defer metriks.MeasureSince("publisher-get-rows.time", time.Now())

  query := "SELECT * FROM publisher"
  return db.Execute(query)
}

func MeasureSinceLabels

func MeasureSinceLabels(name string, labels []metrics.Label, start time.Time)

MeasureSinceLabels is the same as MeasureSince, but with additional labels

func Sample

func Sample(name string, val float32, labels ...metrics.Label)

Sample records a float32 sample as part of a histogram. This will get histogram distribution metrics

Example:

metriks.Sample("publisher-payload-size", float32(len(payload)))

func SampleLabels

func SampleLabels(name string, labels []metrics.Label, val float32)

SampleLabels is the same as Sample but with additional labels

func SetDistributionErrorHandler added in v0.51.0

func SetDistributionErrorHandler(f func(error))

SetDistributionErrorHandler will set the global error handler. It will be invoked anytime that the statsd call produces an error

Types

type Config

type Config struct {
	Enabled bool
	Host    string `default:"localhost"`
	Port    int    `default:"8125"`

	Tags map[string]string
}

func (Config) StatsdAddr added in v0.40.1

func (conf Config) StatsdAddr() string

type DBStats

type DBStats interface {
	Start()
	Stop()
}

func NewDBStats

func NewDBStats(db *sql.DB, name string, labels []metrics.Label) DBStats

NewDBStats returns a managed object that when Start() is invoked, will periodically report the stats from the passed DB object.

Stop() should be called before the DB is closed.

type PersistentGauge added in v0.51.0

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

PersistentGauge will report on an interval the value to the metrics collector.

func NewPersistentGauge added in v0.51.0

func NewPersistentGauge(name string, tags ...metrics.Label) *PersistentGauge

NewPersistentGauge will create and start a PersistentGauge that reports the current value every 10s

func NewPersistentGaugeWithDuration added in v0.51.0

func NewPersistentGaugeWithDuration(name string, dur time.Duration, tags ...metrics.Label) *PersistentGauge

NewPersistentGaugeWithDuration will create and start a PersistentGauge that reports the current value every period

func (*PersistentGauge) Dec added in v0.51.0

func (g *PersistentGauge) Dec() int32

Dec will -1 to the current value and return the new value

func (*PersistentGauge) Inc added in v0.51.0

func (g *PersistentGauge) Inc() int32

Inc will +1 to the current value and return the new value

func (*PersistentGauge) Set added in v0.51.0

func (g *PersistentGauge) Set(value int32) int32

Set will replace the value with a new one, it returns the old value

func (*PersistentGauge) Stop added in v0.51.0

func (g *PersistentGauge) Stop()

Stop will make the gauge stop reporting. Any calls to Inc/Set/Dec will still report to the metrics collector

type ScheduledGauge added in v0.51.0

type ScheduledGauge struct {
	util.ScheduledExecutor
}

ScheduledGauge will call the provided method after a duration it will then report that value to the metrics system

func NewScheduledGauge added in v0.51.0

func NewScheduledGauge(name string, cb func() int32, tags ...metrics.Label) ScheduledGauge

NewScheduledGauge will create an start a ScheduledGauge that reports the value every 10s

func NewScheduledGaugeWithDuration added in v0.51.0

func NewScheduledGaugeWithDuration(name string, dur time.Duration, cb func() int32, tags ...metrics.Label) ScheduledGauge

NewScheduledGaugeWithDuration will create an start a ScheduledGauge that reports the value every period

Jump to

Keyboard shortcuts

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