This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write simple metrics and events to Datadog
- Loading branch information
Showing
7 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package telemetry | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/DataDog/datadog-go/statsd" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Datadog interface { | ||
Incr(name string, tags []string) | ||
Failure(title, text string) | ||
} | ||
|
||
type Client struct { | ||
client *statsd.Client | ||
initialized bool | ||
} | ||
|
||
func (c *Client) on_error(err error) { | ||
log.Println(err) | ||
} | ||
|
||
func (c *Client) Failure(title, text string) { | ||
if c.initialized { | ||
ev := statsd.NewEvent(title, text) | ||
ev.AlertType = statsd.Error | ||
err := errors.Wrap(c.client.Event(ev), "Failed sending event to DataDog") | ||
if err != nil { | ||
c.on_error(err) | ||
} | ||
} | ||
} | ||
|
||
func (c *Client) Incr(name string, tags []string) { | ||
if c.initialized { | ||
err := c.client.Incr(name, tags, 1.0) | ||
if err != nil { | ||
c.on_error(err) | ||
} | ||
} | ||
} | ||
|
||
func NewDatadog(addr string, namespace string) Datadog { | ||
c, err := statsd.New(addr) | ||
if err != nil { | ||
client := &Client{} | ||
client.on_error(err) | ||
return client | ||
} | ||
c.Namespace = namespace + "." | ||
return &Client{client: c, initialized: true} | ||
} |