0.3.0 output: datadog and amon
This commit is contained in:
parent
6bb34fcda3
commit
963729ae36
|
@ -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 {
|
||||||
metric := &Metric{
|
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
||||||
Metric: strings.Replace(pt.Name(), "_", ".", -1),
|
if amonPts, err := buildPoints(pt); err == nil {
|
||||||
}
|
for fieldName, amonPt := range amonPts {
|
||||||
if p, err := buildPoint(pt); err == nil {
|
metric := &Metric{
|
||||||
metric.Points[0] = p
|
Metric: mname + "_" + strings.Replace(fieldName, "_", ".", -1),
|
||||||
tempSeries[acceptablePoints] = metric
|
}
|
||||||
acceptablePoints += 1
|
metric.Points[0] = amonPt
|
||||||
|
tempSeries[acceptablePoints] = metric
|
||||||
|
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) {
|
||||||
var p Point
|
pts := make(map[string]Point)
|
||||||
if err := p.setValue(pt.Fields()["value"]); err != nil {
|
for k, v := range pt.Fields() {
|
||||||
return p, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
|
var p Point
|
||||||
|
if err := p.setValue(v); err != nil {
|
||||||
|
return pts, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
|
||||||
|
}
|
||||||
|
p[0] = float64(pt.Time().Unix())
|
||||||
|
pts[k] = p
|
||||||
}
|
}
|
||||||
p[0] = float64(pt.Time().Unix())
|
return pts, nil
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) setValue(v interface{}) error {
|
func (p *Point) setValue(v interface{}) error {
|
||||||
|
|
|
@ -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 {
|
||||||
metric := &Metric{
|
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
||||||
Metric: strings.Replace(pt.Name(), "_", ".", -1),
|
if amonPts, err := buildPoints(pt); err == nil {
|
||||||
Tags: buildTags(pt.Tags()),
|
for fieldName, amonPt := range amonPts {
|
||||||
Host: pt.Tags()["host"],
|
metric := &Metric{
|
||||||
}
|
Metric: mname + strings.Replace(fieldName, "_", ".", -1),
|
||||||
if p, err := buildPoint(pt); err == nil {
|
}
|
||||||
metric.Points[0] = p
|
metric.Points[0] = amonPt
|
||||||
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) {
|
||||||
var p Point
|
pts := make(map[string]Point)
|
||||||
if err := p.setValue(pt.Fields()["value"]); err != nil {
|
for k, v := range pt.Fields() {
|
||||||
return p, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
|
var p Point
|
||||||
|
if err := p.setValue(v); err != nil {
|
||||||
|
return pts, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
|
||||||
|
}
|
||||||
|
p[0] = float64(pt.Time().Unix())
|
||||||
|
pts[k] = p
|
||||||
}
|
}
|
||||||
p[0] = float64(pt.Time().Unix())
|
return pts, nil
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTags(ptTags map[string]string) []string {
|
func buildTags(ptTags map[string]string) []string {
|
||||||
|
|
Loading…
Reference in New Issue