metrics

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 5 Imported by: 15

README

vulcan-metrics-client

Metrics client abstraction used in Vulcan components.

Configuration and behaviour

Internally the client abstraction works as a pool of clients for the supported implementations. Each client is enabled/disabled and configured through environment variables, so for each input metric it will be pushed through every client in the pool.

Current supported clients and its configurations are: DataDog

  • DOGSTATSD_ENABLED
  • DOGSTATSD_HOST
  • DOGSTATSD_PORT

Metrics are divided in Metric, which defaults to a sample rate of 1.0, and RatedMetric which allows to specify its sample rate between 0 (everything is sampled) and 1 (no sample); see the sample rates section in DataDog.

Current supported metric types are:

  • count
  • gauge
  • histogram
  • distribution

Example of pushing a metric:

metricsClient, err := metrics.NewClient()
if err != nil {
    return err
}

metricsClient.Push(metrics.Metric{
    Name: "vulcan.scan.count",
    Typ: metrics.Count,
    Value: 1.0,
    Tags: []string{"team:purple"},
})

Example of pushing a rated metric:

metricsClient, err := metrics.NewClient()
if err != nil {
    return err
}

metricsClient.PushWithRate(metrics.RatedMetric{
    Metric: Metric{
        Name:  "vulcan.requests.count",
        Typ:   metrics.Count,
        Value: 1,
        Tags:  []string{"team:purple"},
    },
    Rate: 0.5,
})

Documentation

Index

Constants

View Source
const (
	// Count represents a count metric type.
	Count = iota
	// Gauge represents a gauge metric type.
	Gauge = iota
	// Histogram represents a histogram metric type.
	Histogram = iota
	// Distribution represents a distribution metric type.
	Distribution = iota
)
View Source
const (
	// DDEnabled represents the config env var to enabled DD client.
	DDEnabled = "DOGSTATSD_ENABLED"
	// DDHost represents the config env var to set DD client's statsd host.
	DDHost = "DOGSTATSD_HOST"
	// DDPort represents the config env var to set DD client's statsd port.
	DDPort = "DOGSTATSD_PORT"
)

Variables

View Source
var (
	// ErrDDClientDisabled indicates that DataDog metrics client is disabled by config.
	ErrDDClientDisabled = errors.New("DataDog metrics client disabled")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Push(metric Metric)
	PushWithRate(ratedMetric RatedMetric)
}

Client represents a metrics service client.

func NewClient

func NewClient() (Client, error)

NewClient creates a new metrics client based on environment variables config.

type Metric

type Metric struct {
	Name  string
	Typ   Type
	Value float64
	Tags  []string
}

Metric represents a metric.

type RatedMetric

type RatedMetric struct {
	Metric
	Rate float64
}

RatedMetric represents a metric with rate.

type Type

type Type int

Type represents the type of metric to push. Supports Count, Gauge, Histogram and Distribution types.

Jump to

Keyboard shortcuts

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