0.3.0: prometheus & puppetagent

This commit is contained in:
Cameron Sparr 2015-12-15 10:03:22 -06:00
parent 2749dcd128
commit 7746a2b3cd
3 changed files with 10 additions and 7 deletions

View File

@ -5,6 +5,8 @@
- **breaking change** Plugin measurements aggregated into a single measurement. - **breaking change** Plugin measurements aggregated into a single measurement.
- `procstat` cpu measurements are now prepended with `cpu_time_` instead of - `procstat` cpu measurements are now prepended with `cpu_time_` instead of
only `cpu_` only `cpu_`
- The prometheus plugin schema has not been changed (measurements have not been
aggregated).
### Features ### Features
- Plugin measurements aggregated into a single measurement. - Plugin measurements aggregated into a single measurement.

View File

@ -80,14 +80,14 @@ func (g *Prometheus) gatherURL(url string, acc plugins.Accumulator) error {
return fmt.Errorf("error getting processing samples for %s: %s", url, err) return fmt.Errorf("error getting processing samples for %s: %s", url, err)
} }
for _, sample := range samples { for _, sample := range samples {
tags := map[string]string{} tags := make(map[string]string)
for key, value := range sample.Metric { for key, value := range sample.Metric {
if key == model.MetricNameLabel { if key == model.MetricNameLabel {
continue continue
} }
tags[string(key)] = string(value) tags[string(key)] = string(value)
} }
acc.Add(string(sample.Metric[model.MetricNameLabel]), acc.Add("prometheus_"+string(sample.Metric[model.MetricNameLabel]),
float64(sample.Value), tags) float64(sample.Value), tags)
} }
} }

View File

@ -104,15 +104,16 @@ func (pa *PuppetAgent) Gather(acc plugins.Accumulator) error {
return fmt.Errorf("%s", err) return fmt.Errorf("%s", err)
} }
structPrinter(&puppetState, acc) tags := map[string]string{"location": pa.Location}
structPrinter(&puppetState, acc, tags)
return nil return nil
} }
func structPrinter(s *State, acc plugins.Accumulator) { func structPrinter(s *State, acc plugins.Accumulator, tags map[string]string) {
e := reflect.ValueOf(s).Elem() e := reflect.ValueOf(s).Elem()
fields := make(map[string]interface{})
for tLevelFNum := 0; tLevelFNum < e.NumField(); tLevelFNum++ { for tLevelFNum := 0; tLevelFNum < e.NumField(); tLevelFNum++ {
name := e.Type().Field(tLevelFNum).Name name := e.Type().Field(tLevelFNum).Name
nameNumField := e.FieldByName(name).NumField() nameNumField := e.FieldByName(name).NumField()
@ -123,10 +124,10 @@ func structPrinter(s *State, acc plugins.Accumulator) {
lname := strings.ToLower(name) lname := strings.ToLower(name)
lsName := strings.ToLower(sName) lsName := strings.ToLower(sName)
acc.Add(fmt.Sprintf("%s_%s", lname, lsName), sValue, nil) fields[fmt.Sprintf("%s_%s", lname, lsName)] = sValue
} }
} }
acc.AddFields("puppetagent", fields, tags)
} }
func init() { func init() {