Telegraf is an agent written in Go for collecting metrics from the system it’s running on or from other services and writing them into InfluxDB.
Design goals are to have a minimal memory footprint with a plugin system so that developers in the community can easily add support for collecting metrics from well known services (like Hadoop, or Postgres, or Redis) and third party APIs (like Mailchimp, AWS CloudWatch, or Google Analytics).
We’ll eagerly accept pull requests for new plugins and will manage the set of plugins that Telegraf supports. See the bottom of this doc for instructions on writing new plugins.
http://get.influxdb.org/telegraf/telegraf_0.1.2_amd64.deb
http://get.influxdb.org/telegraf/telegraf-0.1.2-1.x86_64.rpm
brew update
brew install telegraf
telegraf -sample-config > telegraf.toml to create an initial configurationtelegraf -config telegraf.toml -test to output one full measurement sample to STDOUTtelegraf -config telegraf.toml to gather and send metrics to InfluxDBTelegraf has a few options you can configure under the agent section of the config. If you don’t see an agent section run telegraf -sample-config > telegraf.toml to create a valid initial configuration:
hostname on the machine running Telegraf. You can override that value here.Telegraf currently has support for collecting metrics from:
We’ll be adding support for many more over the coming months. Read on if you want to add support for another service or third-party API.
There are 3 configuration options that are configurable per plugin:
This section is for developers that want to create new collection plugins. Telegraf is entirely plugin driven. This interface allows for operators to
pick and chose what is gathered as well as makes it easy for developers
to create new ways of generating metrics.
Plugin authorship is kept as simple as possible to promote people to develop
and submit new plugins.
plugins.Plugin interface.plugins.Add in their init function to register themselves.github.com/influxdb/telegraf/plugins/all/all.go file.SampleConfig function should return valid toml that describes how the plugin can be configured. This is include in telegraf -sample-config.Description function should say in one line what this plugin does.type Plugin interface {
SampleConfig() string
Description() string
Gather(Accumulator) error
}
type Accumulator interface {
Add(measurement string, value interface{}, tags map[string]string)
AddValuesWithTime(measurement string, values map[string]interface{}, tags map[string]string, timestamp time.Time)
}
The way that a plugin emits metrics is by interacting with the Accumulator.
The Add function takes 3 arguments:
bytes_read or faults.int64float64, useful for gauges, percentages, etc.true or false, useful to indicate the presence of a state. light_on, etc.light_on_since.net plugin adds a tag named "interface" set to the name of the network interface, like "eth0".The AddValuesWithTime allows multiple values for a point to be passed. The values
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 about processes on the current host.
type Process struct {
CPUTime float64
MemoryBytes int64
PID int
}
func Gather(acc plugins.Accumulator) error {
for _, process := range system.Processes() {
tags := map[string]string {
"pid": fmt.Sprintf("%d", process.Pid),
}
acc.Add("cpu", process.CPUTime, tags)
acc.Add("memory", process.MemoryBytes, tags)
}
}
package simple
// simple.go
import "github.com/influxdb/telegraf/plugins"
type Simple struct {
Ok bool
}
func (s *Simple) Description() string {
return "a demo plugin"
}
func (s *Simple) SampleConfig() string {
return "ok = true # indicate if everything is fine"
}
func (s *Simple) Gather(acc plugins.Accumulator) error {
if s.Ok {
acc.Add("state", "pretty good", nil)
} else {
acc.Add("state", "not great", nil)
}
return nil
}
func init() {
plugins.Add("simple", func() plugins.Plugin { return &Simple{} })
}
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.