第一步是在运行应用程序的服务器上安装 DataDog 代理:
https://docs.datadoghq.com/agent/ https://docs.datadoghq.com/agent/
然后您需要启用DogStatsD
DataDog 代理中的服务:
https://docs.datadoghq.com/developers/dogstatsd/ https://docs.datadoghq.com/developers/dogstatsd/
之后,您可以将指标发送到statsd
使用任何连接到的 Go 库的代理statsd
.
例如:
https://github.com/DataDog/datadog-go https://github.com/DataDog/datadog-go
https://github.com/go-kit/kit/tree/master/metrics/statsd https://github.com/go-kit/kit/tree/master/metrics/statsd
这是使用第一个库发送一些计数的示例程序:
import (
"github.com/DataDog/datadog-go/statsd"
"log"
)
func main() {
// Create the client
c, err := statsd.New("127.0.0.1:8125")
if err != nil {
log.Fatal(err)
}
// Prefix every metric with the app name
c.Namespace = "myapp."
// Count two events
err = c.Count("my_counter", 2, nil, 1)
if err != nil {
log.Fatal(err)
}
// Close the client
err = c.Close()
if err != nil {
log.Fatal(err)
}
}