datadog

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

README

Metric Source: Datadog

To import a metric from Datadog, ts-bridge regularly runs a configured query against the Datadog Query API.

Metrics imported from Datadog are defined in the datadog_metrics section of app/metrics.yaml. The following parameters need to be specified for each metric:

  • name: base name of the metric. While exporting to Stackdriver, this name will be prefixed with custom.googleapis.com/datadog/.
  • query: Datadog query expression. This needs to return a single time series (tags/labels are not supported yet).
  • api_key: Datadog API key. See API and application keys on getting your API key.
  • application_key: Datadog Application key.
  • destination: name of the Stackdriver destination that query result will be written to. Destinations need to be explicitly listed in the stackdriver_destinations section of the configuration file.
  • cumulative: a boolean flag describing whether query result should be imported as a cumulative metric (a monotonically increasing counter). See Cumulative metrics section below for more details.

All parameters are required, except for cumulative (which defaults to false).

For metrics that have measurements more often than every minute, you might also want to append the .rollup() function to avoid aggregation on Datadog's side.

Please keep in mind the following details about Datadog API:

  • There is an API rate limit of 300 queries per hour that applies to the whole organization. Even if ts-bridge is the only user of the Query API, it still means you can only import 5 metrics if you are querying every minute (which is the default). The limit can be raised.
  • If you are using a rollup function as part of your query, Datadog will return a single point per each rollup interval. If rollup interval is longer than the importing period of ts-bridge, some import operations will fetch 0 new points. For example, if your query is producing a 10-minute ratio ( xxx.rollup(sum, 600) / yyy.rollup(sum, 600)) and you are using the default importing period (1 minute), ts-bridge will still issue the query every minute, however Datadog will only return a single point once every 10 minutes.
  • If you are not using the rollup function, Datadog will return points at maximum possible resolution (unless the query covers a very long time interval). Please keep in mind that Datadog might return more than 1 point per minute, and all points will be written to Stackdriver, even though Stackdriver does not allow querying with alignment period shorter than 1 minute.

Cumulative metrics

Cumulative metrics are supported through Datadog's cumsum() function, which returns a monotonically increasing time series with a sum of all measurements since the given 'start time'.

Often, for Datadog to provide a cumulative sum of all measurements, the .as_count() suffix needs to be appended to metric name. Otherwise measurements might be provided as per-second rates rather than exact counts.

For example, to import the counter metric called http_requests as a cumulative metric to Stackdriver, you might configure the following query in ts-bridge (and set cumulative to true):

cumsum(sum:http_requests{*}.as_count().rollup(sum, 60))

To unpack this:

  • cumsum() makes Datadog return a cumulative sum of measurements;
  • sum: prefix ensures that sum is used as the aggregation method if there are multiple time series with the same metric name but different tags (for example, reported from different machines);
  • .as_count() suffix gathers actual measurements rather than per-second rates;
  • .rollup(sum, 60) aggregates values into 60-second intervals in case there are multiple measurements for this metric reported per minute. See rollup documentation for more.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric

type Metric struct {
	Name string
	// contains filtered or unexported fields
}

Metric defines a Datadog-based metric. It implements the SourceMetric interface.

func NewSourceMetric

func NewSourceMetric(name string, config *MetricConfig, minPointAge, counterResetInterval time.Duration) (*Metric, error)

NewSourceMetric creates a new SourceMetric from a metric name and configuration parameters.

func (*Metric) Query

func (m *Metric) Query() string

Query returns the query being imported from Datadog.

func (*Metric) StackdriverData

func (m *Metric) StackdriverData(ctx context.Context, lastPoint time.Time, rec storage.MetricRecord) (*metricpb.MetricDescriptor, []*monitoringpb.TimeSeries, error)

StackdriverData issues a Datadog query, returning metric descriptor and time series data. Time series data will include points after the given lastPoint timestamp.

func (*Metric) StackdriverName

func (m *Metric) StackdriverName() string

StackdriverName returns the full Stackdriver metric name (also called "metric type") for this metric.

type MetricConfig

type MetricConfig struct {
	APIKey         string `yaml:"api_key" validate:"nonzero"`
	ApplicationKey string `yaml:"application_key" validate:"nonzero"`
	Query          string `validate:"nonzero"`
	Cumulative     bool
}

MetricConfig defines configuration file parameters for a specific metric imported from Datadog.

Jump to

Keyboard shortcuts

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