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 {
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)
}
```
@ -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.
@ -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

View File

@ -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
}
}
@ -37,12 +37,12 @@ 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,
},
@ -50,15 +50,15 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)
}
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
}
}
@ -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,
})
}

View File

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

View File

@ -6,30 +6,30 @@ 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,
@ -37,17 +37,17 @@ func (a *Accumulator) AddValuesWithTime(
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
}
}
@ -55,9 +55,9 @@ func (a *Accumulator) Get(name string) (*Point, bool) {
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
}
}
@ -65,11 +65,11 @@ func (a *Accumulator) CheckValue(name string, val interface{}) bool {
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
@ -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)
}
@ -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
}
@ -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
}