Skip to content

Commit

Permalink
Update name -> measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnaraasen committed May 29, 2015
1 parent 2bd58ee commit 4d5782d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
8 changes: 4 additions & 4 deletions PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Plugin interface {
}

type Accumulator interface {
Add(name string, value interface{}, tags map[string]string)
AddValuesWithTime(name string, values map[string]interface{}, tags map[string]string, timestamp time.Time)
Add(measurement string, value interface{}, tags map[string]string)
AddValuesWithTime(measurement string, values map[string]interface{}, tags map[string]string, timestamp time.Time)
}
```

Expand All @@ -38,7 +38,7 @@ type Accumulator interface {
The way that a plugin emits metrics is by interacting with the Accumulator.

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:
* **int**: The most common type. All int types are accepted but favor using `int64`
Useful for counters, etc.
Expand All @@ -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
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

Expand Down
28 changes: 14 additions & 14 deletions accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type BatchPoints struct {
Config *ConfiguredPlugin
}

func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string) {
name = bp.Prefix + name
func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
measurement = bp.Prefix + measurement

if bp.Config != nil {
if !bp.Config.ShouldPass(name) {
if !bp.Config.ShouldPass(measurement) {
return
}
}
Expand All @@ -37,28 +37,28 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)

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{
Name: name,
Tags: tags,
Measurement: measurement,
Tags: tags,
Fields: map[string]interface{}{
"value": val,
},
})
}

func (bp *BatchPoints) AddValuesWithTime(
name string,
measurement string,
values map[string]interface{},
tags map[string]string,
timestamp time.Time,
) {
name = bp.Prefix + name
measurement = bp.Prefix + measurement

if bp.Config != nil {
if !bp.Config.ShouldPass(name) {
if !bp.Config.ShouldPass(measurement) {
return
}
}
Expand All @@ -79,13 +79,13 @@ func (bp *BatchPoints) AddValuesWithTime(
sort.Strings(tg)
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{
Name: name,
Tags: tags,
Fields: values,
Time: timestamp,
Measurement: measurement,
Tags: tags,
Fields: values,
Time: timestamp,
})
}
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ type ConfiguredPlugin struct {
Interval time.Duration
}

func (cp *ConfiguredPlugin) ShouldPass(name string) bool {
func (cp *ConfiguredPlugin) ShouldPass(measurement string) bool {
if cp.Pass != nil {
for _, pat := range cp.Pass {
if strings.HasPrefix(name, pat) {
if strings.HasPrefix(measurement, pat) {
return true
}
}
Expand All @@ -66,7 +66,7 @@ func (cp *ConfiguredPlugin) ShouldPass(name string) bool {

if cp.Drop != nil {
for _, pat := range cp.Drop {
if strings.HasPrefix(name, pat) {
if strings.HasPrefix(measurement, pat) {
return false
}
}
Expand Down
58 changes: 29 additions & 29 deletions testutil/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,70 @@ import (
)

type Point struct {
Name string
Value interface{}
Tags map[string]string
Values map[string]interface{}
Time time.Time
Measurement string
Value interface{}
Tags map[string]string
Values map[string]interface{}
Time time.Time
}

type Accumulator struct {
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,
&Point{
Name: name,
Value: value,
Tags: tags,
measurement: measurement,
Value: value,
Tags: tags,
},
)
}

func (a *Accumulator) AddValuesWithTime(
name string,
measurement string,
values map[string]interface{},
tags map[string]string,
timestamp time.Time,
) {
a.Points = append(
a.Points,
&Point{
Name: name,
Values: values,
Tags: tags,
Time: timestamp,
Measurement: measurement,
Values: values,
Tags: tags,
Time: timestamp,
},
)
}

func (a *Accumulator) Get(name string) (*Point, bool) {
func (a *Accumulator) Get(measurement string) (*Point, bool) {
for _, p := range a.Points {
if p.Name == name {
if p.Measurement == measurement {
return p, true
}
}

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 {
if p.Name == name {
if p.Measurement == measurement {
return p.Value == val
}
}

return false
}

func (a *Accumulator) CheckTaggedValue(name string, val interface{}, tags map[string]string) bool {
return a.ValidateTaggedValue(name, val, tags) == nil
func (a *Accumulator) CheckTaggedValue(measurement string, val interface{}, tags map[string]string) bool {
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 {
var found bool

Expand All @@ -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 {
return fmt.Errorf("%v (%T) != %v (%T)", p.Value, p.Value, val, val)
}
Expand All @@ -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 {
return a.ValidateTaggedValue(name, val, nil)
func (a *Accumulator) ValidateValue(measurement string, val interface{}) error {
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 {
if p.Name == name {
if p.Measurement == measurement {
_, ok := p.Value.(int64)
return ok
}
Expand All @@ -111,9 +111,9 @@ func (a *Accumulator) HasIntValue(name string) bool {
return false
}

func (a *Accumulator) HasFloatValue(name string) bool {
func (a *Accumulator) HasFloatValue(measurement string) bool {
for _, p := range a.Points {
if p.Name == name {
if p.Measurement == measurement {
_, ok := p.Value.(float64)
return ok
}
Expand Down

0 comments on commit 4d5782d

Please sign in to comment.