Documentation
¶
Index ¶
- func Distribution(name string, value float64, tags ...metrics.Label)
- func Gauge(name string, val float32, labels ...metrics.Label)
- func GaugeLabels(name string, labels []metrics.Label, val float32)
- func Inc(name string, val int64, labels ...metrics.Label)
- func IncLabels(name string, labels []metrics.Label, val int64)
- func Init(serviceName string, conf Config) error
- func InitTags(serviceName string, conf Config, extraTags []string) error
- func InitWithSink(serviceName string, sink metrics.MetricSink) error
- func InitWithURL(serviceName string, endpoint string) (metrics.MetricSink, error)
- func L(name string, value string) metrics.Label
- func Labels(labels ...metrics.Label) []metrics.Label
- func MeasureSince(name string, start time.Time, labels ...metrics.Label)
- func MeasureSinceLabels(name string, labels []metrics.Label, start time.Time)
- func Sample(name string, val float32, labels ...metrics.Label)
- func SampleLabels(name string, labels []metrics.Label, val float32)
- func SetDistributionErrorHandler(f func(error))
- type Config
- type DBStats
- type PersistentGauge
- type ScheduledGauge
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Distribution ¶ added in v0.51.0
Distribution will report the value as a distribution metric to datadog. it only makes sense when you're using the datadog sink
func Gauge ¶
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 ¶
GaugeLabels is the same as Gauge but with additional labels
func IncLabels ¶
IncLabels increments a counter with additional labels
Example:
metriks.IncLabels("publisher.errors", metriks.Labels(metriks.L("status_class", "4xx")), 1)
func InitWithSink ¶
InitWithSink initializes the internal metrics system with custom sink
func InitWithURL ¶
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 Labels ¶
func Labels(labels ...metrics.Label) []metrics.Label
Labels builds a dynamic list of labels
func MeasureSince ¶
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 ¶
MeasureSinceLabels is the same as MeasureSince, but with additional labels
func Sample ¶
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 ¶
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
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