-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from callumj/cj-statsd
Add StatsD support
- Loading branch information
Showing
12 changed files
with
859 additions
and
6 deletions.
There are no files selected for viewing
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,8 @@ | ||
package backend | ||
|
||
import "github.com/buildkite/buildkite-metrics/collector" | ||
|
||
// Backend is a receiver of metrics | ||
type Backend interface { | ||
Collect(r *collector.Result) error | ||
} |
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,67 @@ | ||
package backend | ||
|
||
import ( | ||
"github.com/DataDog/datadog-go/statsd" | ||
"github.com/buildkite/buildkite-metrics/collector" | ||
) | ||
|
||
// StatsD sends metrics to StatsD (Datadog spec) | ||
type StatsD struct { | ||
client *statsd.Client | ||
tagsSupported bool | ||
} | ||
|
||
func NewStatsDBackend(host string, tagsSupported bool) (*StatsD, error) { | ||
c, err := statsd.NewBuffered(host, 100) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// prefix every metric with the app name | ||
c.Namespace = "buildkite." | ||
return &StatsD{ | ||
client: c, | ||
tagsSupported: tagsSupported, | ||
}, nil | ||
} | ||
|
||
func (cb *StatsD) Collect(r *collector.Result) error { | ||
for name, value := range r.Totals { | ||
if err := cb.client.Gauge(name, float64(value), []string{}, 1.0); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for queue, counts := range r.Queues { | ||
for name, value := range counts { | ||
var finalName string | ||
tags := []string{} | ||
if cb.tagsSupported { | ||
finalName = "queues." + name | ||
tags = []string{"queue:" + queue} | ||
} else { | ||
finalName = "queues." + queue + "." + name | ||
} | ||
if err := cb.client.Gauge(finalName, float64(value), tags, 1.0); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
for pipeline, counts := range r.Pipelines { | ||
for name, value := range counts { | ||
var finalName string | ||
tags := []string{} | ||
if cb.tagsSupported { | ||
finalName = "pipeline." + name | ||
tags = []string{"pipeline:" + pipeline} | ||
} else { | ||
finalName = "pipeline." + pipeline + "." + name | ||
} | ||
if err := cb.client.Gauge(finalName, float64(value), tags, 1.0); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.