0.3.0 output: librato

This commit is contained in:
Cameron Sparr 2015-12-19 14:19:43 -07:00
parent ec39d10695
commit 2611931f82
3 changed files with 40 additions and 30 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {
gauges := []*Gauge{}
for fieldName, value := range pt.Fields() {
gauge := &Gauge{ gauge := &Gauge{
Name: pt.Name(), Name: pt.Name() + "_" + fieldName,
MeasureTime: pt.Time().Unix(), MeasureTime: pt.Time().Unix(),
} }
if err := gauge.setValue(pt.Fields()["value"]); err != nil { if err := gauge.setValue(value); err != nil {
return gauge, fmt.Errorf("unable to extract value from Fields, %s\n", err.Error()) return gauges, fmt.Errorf("unable to extract value from Fields, %s\n",
err.Error())
} }
if l.SourceTag != "" { if l.SourceTag != "" {
if source, ok := pt.Tags()[l.SourceTag]; ok { if source, ok := pt.Tags()[l.SourceTag]; ok {
gauge.Source = source gauge.Source = source
} else { } else {
return gauge, fmt.Errorf("undeterminable Source type from Field, %s\n", l.SourceTag) 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 {