Datapup is metric-centered tool for sending metrics to DataDog.
When creating datapup client, in WithSender
you may to pass a sender which implements datapup.Sender
interface. Currently there are 2 senders available:
datapup.Lambda
- will print your metrics according to using-cloudwatch-logsdatapup.StatsD
- regular DataDog metrics client
If not passed, will use default DataDod's statsd.Client
with default address localhost:8126
and
"asynchronous" behavior (with statsd.WithAsyncUDS()
option).
Other configurations:
WithTag
- add default tag for all metrics, could be passed multiple times to set multiple tagsWithEnvironment
- add defaultenv
tag to all your metricsWithRate
- The sampling rate in [0,1]. For example 0.5 means that half the calls will result in a metric being sent to DataDog. Rate will be 1 if not passed (all metrics will be sent)
AWS Lambda:
dd := datapup.New(
"my.awesome.service",
datapup.WithSender(datapup.NewLambda()),
datapup.WithEnvironment("staging"),
datapup.WithTag("key1", "val1"),
datapup.WithTag("key2", "val2"),
)
StatsD:
dd := datapup.New(
"my.awesome.service",
datapup.WithSender(datapup.NewStatsD("localhost:8126")),
datapup.WithEnvironment("prod"),
datapup.WithRate(0.1),
)
Now, after client creation, you can create a DataDog metric to use:
successMetric := dd.NewMetric("success", datapup.Tag("key3", "val3"))
successMetric.Incr() // shortcut for successMetric.Count(1)
// AWS Lambda client will print
// MONITORING|12345|1|count|my.awesome.service.success|#env:staging,key1:val1,key2:val2,key3:val3
datapup.Tag
will format tag into key:value
string.
Available metrics:
- Count
- Gauge
- Histogram
- Check