0.3.0 output: datadog and amon

This commit is contained in:
Cameron Sparr 2015-12-19 14:08:31 -07:00
parent 6bb34fcda3
commit 963729ae36
2 changed files with 44 additions and 28 deletions

View File

@ -60,18 +60,23 @@ func (a *Amon) Write(points []*client.Point) error {
ts := TimeSeries{} ts := TimeSeries{}
var tempSeries = make([]*Metric, len(points)) var tempSeries = make([]*Metric, len(points))
var acceptablePoints = 0 var acceptablePoints = 0
for _, pt := range points { for _, pt := range points {
mname := strings.Replace(pt.Name(), "_", ".", -1)
if amonPts, err := buildPoints(pt); err == nil {
for fieldName, amonPt := range amonPts {
metric := &Metric{ metric := &Metric{
Metric: strings.Replace(pt.Name(), "_", ".", -1), Metric: mname + "_" + strings.Replace(fieldName, "_", ".", -1),
} }
if p, err := buildPoint(pt); err == nil { metric.Points[0] = amonPt
metric.Points[0] = p
tempSeries[acceptablePoints] = metric tempSeries[acceptablePoints] = metric
acceptablePoints += 1 acceptablePoints += 1
}
} else { } else {
log.Printf("unable to build Metric for %s, skipping\n", pt.Name()) log.Printf("unable to build Metric for %s, skipping\n", pt.Name())
} }
} }
ts.Series = make([]*Metric, acceptablePoints) ts.Series = make([]*Metric, acceptablePoints)
copy(ts.Series, tempSeries[0:]) copy(ts.Series, tempSeries[0:])
tsBytes, err := json.Marshal(ts) tsBytes, err := json.Marshal(ts)
@ -110,13 +115,17 @@ func (a *Amon) authenticatedUrl() string {
return fmt.Sprintf("%s/api/system/%s", a.AmonInstance, a.ServerKey) return fmt.Sprintf("%s/api/system/%s", a.AmonInstance, a.ServerKey)
} }
func buildPoint(pt *client.Point) (Point, error) { func buildPoints(pt *client.Point) (map[string]Point, error) {
pts := make(map[string]Point)
for k, v := range pt.Fields() {
var p Point var p Point
if err := p.setValue(pt.Fields()["value"]); err != nil { if err := p.setValue(v); err != nil {
return p, fmt.Errorf("unable to extract value from Fields, %s", err.Error()) return pts, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
} }
p[0] = float64(pt.Time().Unix()) p[0] = float64(pt.Time().Unix())
return p, nil pts[k] = p
}
return pts, nil
} }
func (p *Point) setValue(v interface{}) error { func (p *Point) setValue(v interface{}) error {

View File

@ -69,20 +69,23 @@ func (d *Datadog) Write(points []*client.Point) error {
ts := TimeSeries{} ts := TimeSeries{}
var tempSeries = make([]*Metric, len(points)) var tempSeries = make([]*Metric, len(points))
var acceptablePoints = 0 var acceptablePoints = 0
for _, pt := range points { for _, pt := range points {
mname := strings.Replace(pt.Name(), "_", ".", -1)
if amonPts, err := buildPoints(pt); err == nil {
for fieldName, amonPt := range amonPts {
metric := &Metric{ metric := &Metric{
Metric: strings.Replace(pt.Name(), "_", ".", -1), Metric: mname + strings.Replace(fieldName, "_", ".", -1),
Tags: buildTags(pt.Tags()),
Host: pt.Tags()["host"],
} }
if p, err := buildPoint(pt); err == nil { metric.Points[0] = amonPt
metric.Points[0] = p
tempSeries[acceptablePoints] = metric tempSeries[acceptablePoints] = metric
acceptablePoints += 1 acceptablePoints += 1
}
} else { } else {
log.Printf("unable to build Metric for %s, skipping\n", pt.Name()) log.Printf("unable to build Metric for %s, skipping\n", pt.Name())
} }
} }
ts.Series = make([]*Metric, acceptablePoints) ts.Series = make([]*Metric, acceptablePoints)
copy(ts.Series, tempSeries[0:]) copy(ts.Series, tempSeries[0:])
tsBytes, err := json.Marshal(ts) tsBytes, err := json.Marshal(ts)
@ -123,13 +126,17 @@ func (d *Datadog) authenticatedUrl() string {
return fmt.Sprintf("%s?%s", d.apiUrl, q.Encode()) return fmt.Sprintf("%s?%s", d.apiUrl, q.Encode())
} }
func buildPoint(pt *client.Point) (Point, error) { func buildPoints(pt *client.Point) (map[string]Point, error) {
pts := make(map[string]Point)
for k, v := range pt.Fields() {
var p Point var p Point
if err := p.setValue(pt.Fields()["value"]); err != nil { if err := p.setValue(v); err != nil {
return p, fmt.Errorf("unable to extract value from Fields, %s", err.Error()) return pts, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
} }
p[0] = float64(pt.Time().Unix()) p[0] = float64(pt.Time().Unix())
return p, nil pts[k] = p
}
return pts, nil
} }
func buildTags(ptTags map[string]string) []string { func buildTags(ptTags map[string]string) []string {