Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data to Datadog using Go

Tags:

go

datadog

i'm collect data using Go and want to visualize it, i chose Datadog, but didn't find examples or live projects where Go used for sending metrics to Datadog. But in offical site says that Go is supported.

like image 221
TalkingJson Avatar asked Sep 02 '25 15:09

TalkingJson


1 Answers

First step is to install the DataDog agent on the server in which you are running your application:

https://docs.datadoghq.com/agent/

You then need to enable the DogStatsD service in the DataDog agent:

https://docs.datadoghq.com/developers/dogstatsd/

After that, you can send metrics to the statsd agent using any Go library that connects to statsd.

For example:

https://github.com/DataDog/datadog-go

https://github.com/go-kit/kit/tree/master/metrics/statsd

Here's an example program sending some counts using the first library:

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)
    }
}
like image 141
eugenioy Avatar answered Sep 05 '25 04:09

eugenioy