metriks

package
v0.0.0-...-3e08555 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

Types

type Config

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

	// Name is typically the local hostname or pod name
	Name string `default:"local"`
	Tags map[string]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.

Jump to

Keyboard shortcuts

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