Merge pull request #8 from influxdb/name-to-measurement
Change `name` to `measurement`
This commit is contained in:
commit
48b4b345d1
|
@ -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
|
||||
|
||||
|
|
|
@ -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,11 +37,11 @@ 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,
|
||||
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,11 +79,11 @@ 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,
|
||||
Measurement: measurement,
|
||||
Tags: tags,
|
||||
Fields: values,
|
||||
Time: timestamp,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,16 @@ package plugins
|
|||
import "time"
|
||||
|
||||
type Accumulator interface {
|
||||
// Create a named point with a value, decorating it with named tags
|
||||
// Create a point with a value, decorating it with tags
|
||||
// NOTE: tags is expected to be owned by the caller, don't mutate
|
||||
// it after passing to Add.
|
||||
Add(name string, value interface{}, tags map[string]string)
|
||||
Add(measurement string, value interface{}, tags map[string]string)
|
||||
|
||||
// Create a named point with a set of values, decorating it with named tags
|
||||
// Create a point with a set of values, decorating it with tags
|
||||
// NOTE: tags and values are expected to be owned by the caller, don't mutate
|
||||
// them after passing to AddValuesWithTime.
|
||||
AddValuesWithTime(
|
||||
name string,
|
||||
measurement string,
|
||||
values map[string]interface{},
|
||||
tags map[string]string,
|
||||
timestamp time.Time,
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
type Point struct {
|
||||
Name string
|
||||
Measurement string
|
||||
Value interface{}
|
||||
Tags map[string]string
|
||||
Values map[string]interface{}
|
||||
|
@ -17,11 +17,11 @@ 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,
|
||||
measurement: measurement,
|
||||
Value: value,
|
||||
Tags: tags,
|
||||
},
|
||||
|
@ -29,7 +29,7 @@ func (a *Accumulator) Add(name string, value interface{}, tags map[string]string
|
|||
}
|
||||
|
||||
func (a *Accumulator) AddValuesWithTime(
|
||||
name string,
|
||||
measurement string,
|
||||
values map[string]interface{},
|
||||
tags map[string]string,
|
||||
timestamp time.Time,
|
||||
|
@ -37,7 +37,7 @@ func (a *Accumulator) AddValuesWithTime(
|
|||
a.Points = append(
|
||||
a.Points,
|
||||
&Point{
|
||||
Name: name,
|
||||
Measurement: measurement,
|
||||
Values: values,
|
||||
Tags: tags,
|
||||
Time: timestamp,
|
||||
|
@ -45,9 +45,9 @@ func (a *Accumulator) AddValuesWithTime(
|
|||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue