0.3.0 output: librato
This commit is contained in:
parent
963729ae36
commit
bdbba81d46
|
@ -58,8 +58,8 @@ func (a *Amon) Write(points []*client.Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ts := TimeSeries{}
|
ts := TimeSeries{}
|
||||||
var tempSeries = make([]*Metric, len(points))
|
tempSeries := []*Metric{}
|
||||||
var acceptablePoints = 0
|
metricCounter := 0
|
||||||
|
|
||||||
for _, pt := range points {
|
for _, pt := range points {
|
||||||
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
||||||
|
@ -69,15 +69,15 @@ func (a *Amon) Write(points []*client.Point) error {
|
||||||
Metric: mname + "_" + strings.Replace(fieldName, "_", ".", -1),
|
Metric: mname + "_" + strings.Replace(fieldName, "_", ".", -1),
|
||||||
}
|
}
|
||||||
metric.Points[0] = amonPt
|
metric.Points[0] = amonPt
|
||||||
tempSeries[acceptablePoints] = metric
|
tempSeries = append(tempSeries, metric)
|
||||||
acceptablePoints += 1
|
metricCounter++
|
||||||
}
|
}
|
||||||
} 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, metricCounter)
|
||||||
copy(ts.Series, tempSeries[0:])
|
copy(ts.Series, tempSeries[0:])
|
||||||
tsBytes, err := json.Marshal(ts)
|
tsBytes, err := json.Marshal(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -67,8 +67,8 @@ func (d *Datadog) Write(points []*client.Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ts := TimeSeries{}
|
ts := TimeSeries{}
|
||||||
var tempSeries = make([]*Metric, len(points))
|
tempSeries := []*Metric{}
|
||||||
var acceptablePoints = 0
|
metricCounter := 0
|
||||||
|
|
||||||
for _, pt := range points {
|
for _, pt := range points {
|
||||||
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
mname := strings.Replace(pt.Name(), "_", ".", -1)
|
||||||
|
@ -78,15 +78,15 @@ func (d *Datadog) Write(points []*client.Point) error {
|
||||||
Metric: mname + strings.Replace(fieldName, "_", ".", -1),
|
Metric: mname + strings.Replace(fieldName, "_", ".", -1),
|
||||||
}
|
}
|
||||||
metric.Points[0] = amonPt
|
metric.Points[0] = amonPt
|
||||||
tempSeries[acceptablePoints] = metric
|
tempSeries = append(tempSeries, metric)
|
||||||
acceptablePoints += 1
|
metricCounter++
|
||||||
}
|
}
|
||||||
} 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, metricCounter)
|
||||||
copy(ts.Series, tempSeries[0:])
|
copy(ts.Series, tempSeries[0:])
|
||||||
tsBytes, err := json.Marshal(ts)
|
tsBytes, err := json.Marshal(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -74,17 +74,21 @@ func (l *Librato) Write(points []*client.Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
metrics := Metrics{}
|
metrics := Metrics{}
|
||||||
var tempGauges = make([]*Gauge, len(points))
|
tempGauges := []*Gauge{}
|
||||||
var acceptablePoints = 0
|
metricCounter := 0
|
||||||
|
|
||||||
for _, pt := range points {
|
for _, pt := range points {
|
||||||
if gauge, err := l.buildGauge(pt); err == nil {
|
if gauges, err := l.buildGauges(pt); err == nil {
|
||||||
tempGauges[acceptablePoints] = gauge
|
for _, gauge := range gauges {
|
||||||
acceptablePoints += 1
|
tempGauges = append(tempGauges, gauge)
|
||||||
|
metricCounter++
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("unable to build Gauge for %s, skipping\n", pt.Name())
|
log.Printf("unable to build Gauge for %s, skipping\n", pt.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
metrics.Gauges = make([]*Gauge, acceptablePoints)
|
|
||||||
|
metrics.Gauges = make([]*Gauge, metricCounter)
|
||||||
copy(metrics.Gauges, tempGauges[0:])
|
copy(metrics.Gauges, tempGauges[0:])
|
||||||
metricsBytes, err := json.Marshal(metrics)
|
metricsBytes, err := json.Marshal(metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,22 +122,28 @@ func (l *Librato) Description() string {
|
||||||
return "Configuration for Librato API to send metrics to."
|
return "Configuration for Librato API to send metrics to."
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Librato) buildGauge(pt *client.Point) (*Gauge, error) {
|
func (l *Librato) buildGauges(pt *client.Point) ([]*Gauge, error) {
|
||||||
gauge := &Gauge{
|
gauges := []*Gauge{}
|
||||||
Name: pt.Name(),
|
for fieldName, value := range pt.Fields() {
|
||||||
MeasureTime: pt.Time().Unix(),
|
gauge := &Gauge{
|
||||||
}
|
Name: pt.Name() + "_" + fieldName,
|
||||||
if err := gauge.setValue(pt.Fields()["value"]); err != nil {
|
MeasureTime: pt.Time().Unix(),
|
||||||
return gauge, fmt.Errorf("unable to extract value from Fields, %s\n", err.Error())
|
}
|
||||||
}
|
if err := gauge.setValue(value); err != nil {
|
||||||
if l.SourceTag != "" {
|
return gauges, fmt.Errorf("unable to extract value from Fields, %s\n",
|
||||||
if source, ok := pt.Tags()[l.SourceTag]; ok {
|
err.Error())
|
||||||
gauge.Source = source
|
}
|
||||||
} else {
|
if l.SourceTag != "" {
|
||||||
return gauge, fmt.Errorf("undeterminable Source type from Field, %s\n", l.SourceTag)
|
if source, ok := pt.Tags()[l.SourceTag]; ok {
|
||||||
|
gauge.Source = source
|
||||||
|
} else {
|
||||||
|
return gauges,
|
||||||
|
fmt.Errorf("undeterminable Source type from Field, %s\n",
|
||||||
|
l.SourceTag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gauge, nil
|
return gauges, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gauge) setValue(v interface{}) error {
|
func (g *Gauge) setValue(v interface{}) error {
|
||||||
|
|
Loading…
Reference in New Issue