Update name -> measurement

This commit is contained in:
gunnaraasen 2015-05-29 13:25:48 -07:00
parent 2bd58ee4df
commit 4d5782df53
4 changed files with 50 additions and 50 deletions

View File

@ -28,8 +28,8 @@ type Plugin interface {
} }
type Accumulator interface { type Accumulator interface {
Add(name string, value interface{}, tags map[string]string) Add(measurement string, value interface{}, tags map[string]string)
AddValuesWithTime(name string, values map[string]interface{}, tags map[string]string, timestamp time.Time) AddValuesWithTime(measurement string, values map[string]interface{}, tags map[string]string, timestamp time.Time)
} }
``` ```
@ -38,7 +38,7 @@ type Accumulator interface {
The way that a plugin emits metrics is by interacting with the Accumulator. The way that a plugin emits metrics is by interacting with the Accumulator.
The `Add` function takes 3 arguments: The `Add` function takes 3 arguments:
* **name**: A string which names the metric. For instance `bytes_read` or `faults`. * **measurement**: A string description of the metric. For instance `bytes_read` or `faults`.
* **value**: A value for the metric. This accepts 5 different types of value: * **value**: A value for the metric. This accepts 5 different types of value:
* **int**: The most common type. All int types are accepted but favor using `int64` * **int**: The most common type. All int types are accepted but favor using `int64`
Useful for counters, etc. Useful for counters, etc.
@ -52,7 +52,7 @@ The `AddValuesWithTime` allows multiple values for a point to be passed. The val
used are the same type profile as **value** above. The **timestamp** argument used are the same type profile as **value** above. The **timestamp** argument
allows a point to be registered as having occurred at an arbitrary time. allows a point to be registered as having occurred at an arbitrary time.
Let's say you've written a plugin that emits metrics abuot processes on the current host. Let's say you've written a plugin that emits metrics about processes on the current host.
```go ```go

View File

@ -19,11 +19,11 @@ type BatchPoints struct {
Config *ConfiguredPlugin Config *ConfiguredPlugin
} }
func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string) { func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
name = bp.Prefix + name measurement = bp.Prefix + measurement
if bp.Config != nil { if bp.Config != nil {
if !bp.Config.ShouldPass(name) { if !bp.Config.ShouldPass(measurement) {
return return
} }
} }
@ -37,12 +37,12 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)
sort.Strings(tg) sort.Strings(tg)
fmt.Printf("> [%s] %s value=%v\n", strings.Join(tg, " "), name, val) fmt.Printf("> [%s] %s value=%v\n", strings.Join(tg, " "), measurement, val)
} }
bp.Points = append(bp.Points, client.Point{ bp.Points = append(bp.Points, client.Point{
Name: name, Measurement: measurement,
Tags: tags, Tags: tags,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"value": val, "value": val,
}, },
@ -50,15 +50,15 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)
} }
func (bp *BatchPoints) AddValuesWithTime( func (bp *BatchPoints) AddValuesWithTime(
name string, measurement string,
values map[string]interface{}, values map[string]interface{},
tags map[string]string, tags map[string]string,
timestamp time.Time, timestamp time.Time,
) { ) {
name = bp.Prefix + name measurement = bp.Prefix + measurement
if bp.Config != nil { if bp.Config != nil {
if !bp.Config.ShouldPass(name) { if !bp.Config.ShouldPass(measurement) {
return return
} }
} }
@ -79,13 +79,13 @@ func (bp *BatchPoints) AddValuesWithTime(
sort.Strings(tg) sort.Strings(tg)
sort.Strings(vals) sort.Strings(vals)
fmt.Printf("> [%s] %s %s\n", strings.Join(tg, " "), name, strings.Join(vals, " ")) fmt.Printf("> [%s] %s %s\n", strings.Join(tg, " "), measurement, strings.Join(vals, " "))
} }
bp.Points = append(bp.Points, client.Point{ bp.Points = append(bp.Points, client.Point{
Name: name, Measurement: measurement,
Tags: tags, Tags: tags,
Fields: values, Fields: values,
Time: timestamp, Time: timestamp,
}) })
} }

View File

@ -53,10 +53,10 @@ type ConfiguredPlugin struct {
Interval time.Duration Interval time.Duration
} }
func (cp *ConfiguredPlugin) ShouldPass(name string) bool { func (cp *ConfiguredPlugin) ShouldPass(measurement string) bool {
if cp.Pass != nil { if cp.Pass != nil {
for _, pat := range cp.Pass { for _, pat := range cp.Pass {
if strings.HasPrefix(name, pat) { if strings.HasPrefix(measurement, pat) {
return true return true
} }
} }
@ -66,7 +66,7 @@ func (cp *ConfiguredPlugin) ShouldPass(name string) bool {
if cp.Drop != nil { if cp.Drop != nil {
for _, pat := range cp.Drop { for _, pat := range cp.Drop {
if strings.HasPrefix(name, pat) { if strings.HasPrefix(measurement, pat) {
return false return false
} }
} }

View File

@ -6,30 +6,30 @@ import (
) )
type Point struct { type Point struct {
Name string Measurement string
Value interface{} Value interface{}
Tags map[string]string Tags map[string]string
Values map[string]interface{} Values map[string]interface{}
Time time.Time Time time.Time
} }
type Accumulator struct { type Accumulator struct {
Points []*Point Points []*Point
} }
func (a *Accumulator) Add(name string, value interface{}, tags map[string]string) { func (a *Accumulator) Add(measurement string, value interface{}, tags map[string]string) {
a.Points = append( a.Points = append(
a.Points, a.Points,
&Point{ &Point{
Name: name, measurement: measurement,
Value: value, Value: value,
Tags: tags, Tags: tags,
}, },
) )
} }
func (a *Accumulator) AddValuesWithTime( func (a *Accumulator) AddValuesWithTime(
name string, measurement string,
values map[string]interface{}, values map[string]interface{},
tags map[string]string, tags map[string]string,
timestamp time.Time, timestamp time.Time,
@ -37,17 +37,17 @@ func (a *Accumulator) AddValuesWithTime(
a.Points = append( a.Points = append(
a.Points, a.Points,
&Point{ &Point{
Name: name, Measurement: measurement,
Values: values, Values: values,
Tags: tags, Tags: tags,
Time: timestamp, Time: timestamp,
}, },
) )
} }
func (a *Accumulator) Get(name string) (*Point, bool) { func (a *Accumulator) Get(measurement string) (*Point, bool) {
for _, p := range a.Points { for _, p := range a.Points {
if p.Name == name { if p.Measurement == measurement {
return p, true return p, true
} }
} }
@ -55,9 +55,9 @@ func (a *Accumulator) Get(name string) (*Point, bool) {
return nil, false return nil, false
} }
func (a *Accumulator) CheckValue(name string, val interface{}) bool { func (a *Accumulator) CheckValue(measurement string, val interface{}) bool {
for _, p := range a.Points { for _, p := range a.Points {
if p.Name == name { if p.Measurement == measurement {
return p.Value == val return p.Value == val
} }
} }
@ -65,11 +65,11 @@ func (a *Accumulator) CheckValue(name string, val interface{}) bool {
return false return false
} }
func (a *Accumulator) CheckTaggedValue(name string, val interface{}, tags map[string]string) bool { func (a *Accumulator) CheckTaggedValue(measurement string, val interface{}, tags map[string]string) bool {
return a.ValidateTaggedValue(name, val, tags) == nil return a.ValidateTaggedValue(measurement, val, tags) == nil
} }
func (a *Accumulator) ValidateTaggedValue(name string, val interface{}, tags map[string]string) error { func (a *Accumulator) ValidateTaggedValue(measurement string, val interface{}, tags map[string]string) error {
for _, p := range a.Points { for _, p := range a.Points {
var found bool var found bool
@ -84,7 +84,7 @@ func (a *Accumulator) ValidateTaggedValue(name string, val interface{}, tags map
} }
} }
if found && p.Name == name { if found && p.Measurement == measurement {
if p.Value != val { if p.Value != val {
return fmt.Errorf("%v (%T) != %v (%T)", p.Value, p.Value, val, val) return fmt.Errorf("%v (%T) != %v (%T)", p.Value, p.Value, val, val)
} }
@ -93,16 +93,16 @@ func (a *Accumulator) ValidateTaggedValue(name string, val interface{}, tags map
} }
} }
return fmt.Errorf("unknown value %s with tags %v", name, tags) return fmt.Errorf("unknown value %s with tags %v", measurement, tags)
} }
func (a *Accumulator) ValidateValue(name string, val interface{}) error { func (a *Accumulator) ValidateValue(measurement string, val interface{}) error {
return a.ValidateTaggedValue(name, val, nil) return a.ValidateTaggedValue(measurement, val, nil)
} }
func (a *Accumulator) HasIntValue(name string) bool { func (a *Accumulator) HasIntValue(measurement string) bool {
for _, p := range a.Points { for _, p := range a.Points {
if p.Name == name { if p.Measurement == measurement {
_, ok := p.Value.(int64) _, ok := p.Value.(int64)
return ok return ok
} }
@ -111,9 +111,9 @@ func (a *Accumulator) HasIntValue(name string) bool {
return false return false
} }
func (a *Accumulator) HasFloatValue(name string) bool { func (a *Accumulator) HasFloatValue(measurement string) bool {
for _, p := range a.Points { for _, p := range a.Points {
if p.Name == name { if p.Measurement == measurement {
_, ok := p.Value.(float64) _, ok := p.Value.(float64)
return ok return ok
} }