2016-07-28 11:31:11 +00:00
|
|
|
package models
|
2016-01-22 18:54:12 +00:00
|
|
|
|
|
|
|
import (
|
2016-09-08 14:22:10 +00:00
|
|
|
"fmt"
|
2016-01-22 18:54:12 +00:00
|
|
|
"time"
|
|
|
|
|
2016-12-23 15:18:27 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins"
|
2016-11-07 08:34:46 +00:00
|
|
|
"github.com/influxdata/telegraf/selfstat"
|
2016-01-22 18:54:12 +00:00
|
|
|
)
|
|
|
|
|
2016-11-07 08:34:46 +00:00
|
|
|
var GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", map[string]string{})
|
|
|
|
|
2016-01-22 18:54:12 +00:00
|
|
|
type RunningInput struct {
|
2016-12-23 15:18:27 +00:00
|
|
|
Input plugins.Input
|
2016-01-22 18:54:12 +00:00
|
|
|
Config *InputConfig
|
2016-09-08 14:22:10 +00:00
|
|
|
|
|
|
|
trace bool
|
|
|
|
defaultTags map[string]string
|
2016-11-07 08:34:46 +00:00
|
|
|
|
|
|
|
MetricsGathered selfstat.Stat
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRunningInput(
|
2016-12-23 15:18:27 +00:00
|
|
|
input plugins.Input,
|
2016-11-07 08:34:46 +00:00
|
|
|
config *InputConfig,
|
|
|
|
) *RunningInput {
|
|
|
|
return &RunningInput{
|
|
|
|
Input: input,
|
|
|
|
Config: config,
|
|
|
|
MetricsGathered: selfstat.Register(
|
|
|
|
"gather",
|
|
|
|
"metrics_gathered",
|
|
|
|
map[string]string{"input": config.Name},
|
|
|
|
),
|
|
|
|
}
|
2016-01-22 18:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InputConfig containing a name, interval, and filter
|
|
|
|
type InputConfig struct {
|
|
|
|
Name string
|
|
|
|
NameOverride string
|
|
|
|
MeasurementPrefix string
|
|
|
|
MeasurementSuffix string
|
|
|
|
Tags map[string]string
|
|
|
|
Filter Filter
|
|
|
|
Interval time.Duration
|
|
|
|
}
|
2016-09-08 14:22:10 +00:00
|
|
|
|
|
|
|
func (r *RunningInput) Name() string {
|
|
|
|
return "inputs." + r.Config.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeMetric either returns a metric, or returns nil if the metric doesn't
|
|
|
|
// need to be created (because of filtering, an error, etc.)
|
|
|
|
func (r *RunningInput) MakeMetric(
|
|
|
|
measurement string,
|
|
|
|
fields map[string]interface{},
|
|
|
|
tags map[string]string,
|
2016-12-23 15:18:27 +00:00
|
|
|
mType plugins.ValueType,
|
2016-09-08 14:22:10 +00:00
|
|
|
t time.Time,
|
2016-12-23 15:18:27 +00:00
|
|
|
) plugins.Metric {
|
2016-09-08 14:22:10 +00:00
|
|
|
m := makemetric(
|
|
|
|
measurement,
|
|
|
|
fields,
|
|
|
|
tags,
|
|
|
|
r.Config.NameOverride,
|
|
|
|
r.Config.MeasurementPrefix,
|
|
|
|
r.Config.MeasurementSuffix,
|
|
|
|
r.Config.Tags,
|
|
|
|
r.defaultTags,
|
|
|
|
r.Config.Filter,
|
|
|
|
true,
|
|
|
|
mType,
|
|
|
|
t,
|
|
|
|
)
|
|
|
|
|
|
|
|
if r.trace && m != nil {
|
|
|
|
fmt.Println("> " + m.String())
|
|
|
|
}
|
|
|
|
|
2016-11-07 08:34:46 +00:00
|
|
|
r.MetricsGathered.Incr(1)
|
|
|
|
GlobalMetricsGathered.Incr(1)
|
2016-09-08 14:22:10 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RunningInput) Trace() bool {
|
|
|
|
return r.trace
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RunningInput) SetTrace(trace bool) {
|
|
|
|
r.trace = trace
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RunningInput) SetDefaultTags(tags map[string]string) {
|
|
|
|
r.defaultTags = tags
|
|
|
|
}
|