Help us shape the future of Go! Take the 2026 Go Developer Survey

metricsutil

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenMetricsMIMEType = "application/openmetrics-text"

	PrometheusSchemaMIMEType = "prometheus/telemetry"

	// ErrorContentType is the content type returned by an error response.
	ErrorContentType = "text/plain"
)
View Source
const (
	PrometheusDefaultRetentionTime = 24 * time.Hour
	UsageGaugeDefaultPeriod        = 10 * time.Minute
	MaximumGaugeCardinalityDefault = 500
)
View Source
const OverflowBucket = "+Inf"
View Source
const (
	PrometheusMetricFormat = "prometheus"
)

Variables

This section is empty.

Functions

func FormatFromRequest

func FormatFromRequest(req *logical.Request) string

func TTLBucket

func TTLBucket(ttl time.Duration) string

TTLBucket computes the label to apply for a token TTL.

Types

type ClusterMetricSink

type ClusterMetricSink struct {
	// ClusterName is either the cluster ID, or a name provided
	// in the telemetry configuration stanza.
	//
	// Because it may be set after the Core is initialized, we need
	// to protect against concurrent access.
	ClusterName atomic.Value

	MaxGaugeCardinality int
	GaugeInterval       time.Duration

	// Sink is the go-metrics instance to send to.
	Sink metrics.MetricSink
}

ClusterMetricSink serves as a shim around go-metrics and inserts a "cluster" label.

It also provides a mechanism to limit the cardinality of the labels on a gauge (at each reporting interval, which isn't sufficient if there is variability in which labels are the top N) and a backoff mechanism for gauge computation.

func BlackholeSink

func BlackholeSink() *ClusterMetricSink

BlackholeSink is a default suitable for use in unit tests.

func NewClusterMetricSink

func NewClusterMetricSink(clusterName string, sink metrics.MetricSink) *ClusterMetricSink

func SetupTelemetry

func SetupTelemetry(opts *SetupTelemetryOpts) (*metrics.InmemSink, *ClusterMetricSink, bool, error)

SetupTelemetry is used to setup the telemetry sub-systems and returns the in-memory sink to be used in http configuration

func (*ClusterMetricSink) AddDurationWithLabels

func (m *ClusterMetricSink) AddDurationWithLabels(key []string, d time.Duration, labels []Label)

func (*ClusterMetricSink) AddSampleWithLabels

func (m *ClusterMetricSink) AddSampleWithLabels(key []string, val float32, labels []Label)

func (*ClusterMetricSink) IncrCounterWithLabels

func (m *ClusterMetricSink) IncrCounterWithLabels(key []string, val float32, labels []Label)

func (*ClusterMetricSink) MeasureSinceWithLabels

func (m *ClusterMetricSink) MeasureSinceWithLabels(key []string, start time.Time, labels []Label)

func (*ClusterMetricSink) NewGaugeCollectionProcess

func (m *ClusterMetricSink) NewGaugeCollectionProcess(
	key []string,
	id []Label,
	collector GaugeCollector,
	logger log.Logger,
) (*GaugeCollectionProcess, error)

NewGaugeCollectionProcess creates a new collection process for the callback function given as an argument, and starts it running. A label should be provided for metrics *about* this collection process.

The Run() method must be called to start the process.

func (*ClusterMetricSink) SetDefaultClusterName

func (m *ClusterMetricSink) SetDefaultClusterName(clusterName string)

SetDefaultClusterName changes the cluster name from its default value, if it has not previously been configured.

func (*ClusterMetricSink) SetGaugeWithLabels

func (m *ClusterMetricSink) SetGaugeWithLabels(key []string, val float32, labels []Label)

type GaugeCollectionProcess

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

A GaugeCollectionProcess is responsible for one particular gauge metric. It handles a delay on initial startup; limiting the cardinality; and exponential backoff on the requested interval.

func (*GaugeCollectionProcess) Run

func (p *GaugeCollectionProcess) Run()

Run should be called as a goroutine.

func (*GaugeCollectionProcess) Stop

func (p *GaugeCollectionProcess) Stop()

Stop the collection process

type GaugeCollector

type GaugeCollector = func(context.Context) ([]GaugeLabelValues, error)

GaugeCollector is a callback function that returns an unfiltered set of label-value pairs. It may be cancelled if it takes too long.

type GaugeLabelValues

type GaugeLabelValues struct {
	Labels []Label
	Value  float32
}

GaugeLabelValues is one gauge in a set sharing a single key, that are measured in a batch.

type Label

type Label = metrics.Label

Convenience alias

type MetricsHelper

type MetricsHelper struct {
	PrometheusEnabled bool
	// contains filtered or unexported fields
}

func NewMetricsHelper

func NewMetricsHelper(inMem *metrics.InmemSink, enablePrometheus bool) *MetricsHelper

func (*MetricsHelper) GenericResponse

func (m *MetricsHelper) GenericResponse() *logical.Response

func (*MetricsHelper) PrometheusResponse

func (m *MetricsHelper) PrometheusResponse() *logical.Response

func (*MetricsHelper) ResponseForFormat

func (m *MetricsHelper) ResponseForFormat(format string) *logical.Response

type SetupTelemetryOpts

type SetupTelemetryOpts struct {
	Config      *Telemetry
	Ui          cli.Ui
	ServiceName string
	DisplayName string
	UserAgent   string
	ClusterName string
}

type Telemetry

type Telemetry struct {
	StatsiteAddr string `hcl:"statsite_address"`
	StatsdAddr   string `hcl:"statsd_address"`

	DisableHostname     bool   `hcl:"disable_hostname"`
	EnableHostnameLabel bool   `hcl:"enable_hostname_label"`
	MetricsPrefix       string `hcl:"metrics_prefix"`
	UsageGaugePeriod    time.Duration
	UsageGaugePeriodRaw interface{} `hcl:"usage_gauge_period"`

	MaximumGaugeCardinality int `hcl:"maximum_gauge_cardinality"`

	// CirconusAPIToken is a valid API Token used to create/manage check. If provided,
	// metric management is enabled.
	// Default: none
	CirconusAPIToken string `hcl:"circonus_api_token"`
	// CirconusAPIApp is an app name associated with API token.
	// Default: "consul"
	CirconusAPIApp string `hcl:"circonus_api_app"`
	// CirconusAPIURL is the base URL to use for contacting the Circonus API.
	// Default: "https://api.circonus.com/v2"
	CirconusAPIURL string `hcl:"circonus_api_url"`
	// CirconusSubmissionInterval is the interval at which metrics are submitted to Circonus.
	// Default: 10s
	CirconusSubmissionInterval string `hcl:"circonus_submission_interval"`
	// CirconusCheckSubmissionURL is the check.config.submission_url field from a
	// previously created HTTPTRAP check.
	// Default: none
	CirconusCheckSubmissionURL string `hcl:"circonus_submission_url"`
	// CirconusCheckID is the check id (not check bundle id) from a previously created
	// HTTPTRAP check. The numeric portion of the check._cid field.
	// Default: none
	CirconusCheckID string `hcl:"circonus_check_id"`
	// CirconusCheckForceMetricActivation will force enabling metrics, as they are encountered,
	// if the metric already exists and is NOT active. If check management is enabled, the default
	// behavior is to add new metrics as they are encountered. If the metric already exists in the
	// check, it will *NOT* be activated. This setting overrides that behavior.
	// Default: "false"
	CirconusCheckForceMetricActivation string `hcl:"circonus_check_force_metric_activation"`
	// CirconusCheckInstanceID serves to uniquely identify the metrics coming from this "instance".
	// It can be used to maintain metric continuity with transient or ephemeral instances as
	// they move around within an infrastructure.
	// Default: hostname:app
	CirconusCheckInstanceID string `hcl:"circonus_check_instance_id"`
	// CirconusCheckSearchTag is a special tag which, when coupled with the instance id, helps to
	// narrow down the search results when neither a Submission URL or Check ID is provided.
	// Default: service:app (e.g. service:consul)
	CirconusCheckSearchTag string `hcl:"circonus_check_search_tag"`
	// CirconusCheckTags is a comma separated list of tags to apply to the check. Note that
	// the value of CirconusCheckSearchTag will always be added to the check.
	// Default: none
	CirconusCheckTags string `hcl:"circonus_check_tags"`
	// CirconusCheckDisplayName is the name for the check which will be displayed in the Circonus UI.
	// Default: value of CirconusCheckInstanceID
	CirconusCheckDisplayName string `hcl:"circonus_check_display_name"`
	// CirconusBrokerID is an explicit broker to use when creating a new check. The numeric portion
	// of broker._cid. If metric management is enabled and neither a Submission URL nor Check ID
	// is provided, an attempt will be made to search for an existing check using Instance ID and
	// Search Tag. If one is not found, a new HTTPTRAP check will be created.
	// Default: use Select Tag if provided, otherwise, a random Enterprise Broker associated
	// with the specified API token or the default Circonus Broker.
	// Default: none
	CirconusBrokerID string `hcl:"circonus_broker_id"`
	// CirconusBrokerSelectTag is a special tag which will be used to select a broker when
	// a Broker ID is not provided. The best use of this is to as a hint for which broker
	// should be used based on *where* this particular instance is running.
	// (e.g. a specific geo location or datacenter, dc:sfo)
	// Default: none
	CirconusBrokerSelectTag string `hcl:"circonus_broker_select_tag"`

	// Dogstats:
	// DogStatsdAddr is the address of a dogstatsd instance. If provided,
	// metrics will be sent to that instance
	DogStatsDAddr string `hcl:"dogstatsd_addr"`

	// DogStatsdTags are the global tags that should be sent with each packet to dogstatsd
	// It is a list of strings, where each string looks like "my_tag_name:my_tag_value"
	DogStatsDTags []string `hcl:"dogstatsd_tags"`

	// Prometheus:
	// PrometheusRetentionTime is the retention time for prometheus metrics if greater than 0.
	// Default: 24h
	PrometheusRetentionTime    time.Duration `hcl:"-"`
	PrometheusRetentionTimeRaw interface{}   `hcl:"prometheus_retention_time"`

	// Stackdriver:
	// StackdriverProjectID is the project to publish stackdriver metrics to.
	StackdriverProjectID string `hcl:"stackdriver_project_id"`
	// StackdriverLocation is the GCP or AWS region of the monitored resource.
	StackdriverLocation string `hcl:"stackdriver_location"`
	// StackdriverNamespace is the namespace identifier, such as a cluster name.
	StackdriverNamespace string `hcl:"stackdriver_namespace"`
	// StackdriverDebugLogs will write additional stackdriver related debug logs to stderr.
	StackdriverDebugLogs bool `hcl:"stackdriver_debug_logs"`
}

Telemetry is the telemetry configuration for the server

func (*Telemetry) GoString

func (t *Telemetry) GoString() string

Jump to

Keyboard shortcuts

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