From ff27648dcd569ea69b67c66d0ead87245a92fc15 Mon Sep 17 00:00:00 2001 From: Kelvin Wang Date: Fri, 5 Oct 2018 17:43:01 -0400 Subject: [PATCH] add plugins --- telegraf/plugins/inputs/cpu.go | 10 +++++++ telegraf/plugins/inputs/disk.go | 10 +++++++ telegraf/plugins/inputs/diskio.go | 10 +++++++ telegraf/plugins/inputs/docker.go | 21 +++++++++++++ telegraf/plugins/inputs/file.go | 29 ++++++++++++++++++ telegraf/plugins/inputs/kernel.go | 10 +++++++ telegraf/plugins/inputs/kubernetes.go | 17 +++++++++++ telegraf/plugins/inputs/logparser.go | 29 ++++++++++++++++++ telegraf/plugins/inputs/mem.go | 10 +++++++ telegraf/plugins/inputs/net.go | 10 +++++++ telegraf/plugins/inputs/net_response.go | 10 +++++++ telegraf/plugins/inputs/ngnix.go | 24 +++++++++++++++ telegraf/plugins/inputs/processes.go | 10 +++++++ telegraf/plugins/inputs/procstats.go | 16 ++++++++++ telegraf/plugins/inputs/prometheus.go | 24 +++++++++++++++ telegraf/plugins/inputs/redis.go | 36 ++++++++++++++++++++++ telegraf/plugins/inputs/swap.go | 10 +++++++ telegraf/plugins/inputs/syslog.go | 21 +++++++++++++ telegraf/plugins/inputs/system.go | 10 +++++++ telegraf/plugins/inputs/tail.go | 32 ++++++++++++++++++++ telegraf/plugins/outputs/file.go | 34 +++++++++++++++++++++ telegraf/plugins/outputs/influxdb_v2.go | 40 +++++++++++++++++++++++++ 22 files changed, 423 insertions(+) create mode 100644 telegraf/plugins/inputs/cpu.go create mode 100644 telegraf/plugins/inputs/disk.go create mode 100644 telegraf/plugins/inputs/diskio.go create mode 100644 telegraf/plugins/inputs/docker.go create mode 100644 telegraf/plugins/inputs/file.go create mode 100644 telegraf/plugins/inputs/kernel.go create mode 100644 telegraf/plugins/inputs/kubernetes.go create mode 100644 telegraf/plugins/inputs/logparser.go create mode 100644 telegraf/plugins/inputs/mem.go create mode 100644 telegraf/plugins/inputs/net.go create mode 100644 telegraf/plugins/inputs/net_response.go create mode 100644 telegraf/plugins/inputs/ngnix.go create mode 100644 telegraf/plugins/inputs/processes.go create mode 100644 telegraf/plugins/inputs/procstats.go create mode 100644 telegraf/plugins/inputs/prometheus.go create mode 100644 telegraf/plugins/inputs/redis.go create mode 100644 telegraf/plugins/inputs/swap.go create mode 100644 telegraf/plugins/inputs/syslog.go create mode 100644 telegraf/plugins/inputs/system.go create mode 100644 telegraf/plugins/inputs/tail.go create mode 100644 telegraf/plugins/outputs/file.go create mode 100644 telegraf/plugins/outputs/influxdb_v2.go diff --git a/telegraf/plugins/inputs/cpu.go b/telegraf/plugins/inputs/cpu.go new file mode 100644 index 0000000000..86d24e9208 --- /dev/null +++ b/telegraf/plugins/inputs/cpu.go @@ -0,0 +1,10 @@ +package inputs + +// CPUStats is based on telegraf CPUStats. +type CPUStats struct{} + +// TOML encodes to toml string +func (c *CPUStats) TOML() string { + return `[[inputs.cpu]] +` +} diff --git a/telegraf/plugins/inputs/disk.go b/telegraf/plugins/inputs/disk.go new file mode 100644 index 0000000000..7c1cc8bb2e --- /dev/null +++ b/telegraf/plugins/inputs/disk.go @@ -0,0 +1,10 @@ +package inputs + +// DiskStats is based on telegraf DiskStats. +type DiskStats struct{} + +// TOML encodes to toml string +func (d *DiskStats) TOML() string { + return `[[inputs.disk]] +` +} diff --git a/telegraf/plugins/inputs/diskio.go b/telegraf/plugins/inputs/diskio.go new file mode 100644 index 0000000000..09c5d39d23 --- /dev/null +++ b/telegraf/plugins/inputs/diskio.go @@ -0,0 +1,10 @@ +package inputs + +// DiskIO is based on telegraf DiskIO. +type DiskIO struct{} + +// TOML encodes to toml string +func (d *DiskIO) TOML() string { + return `[[inputs.diskio]] +` +} diff --git a/telegraf/plugins/inputs/docker.go b/telegraf/plugins/inputs/docker.go new file mode 100644 index 0000000000..14b6f44e35 --- /dev/null +++ b/telegraf/plugins/inputs/docker.go @@ -0,0 +1,21 @@ +package inputs + +import ( + "fmt" +) + +// Docker is based on telegraf Docker plugin. +type Docker struct { + Endpoint string `json:"endpoint"` +} + +// TOML encodes to toml string +func (d *Docker) TOML() string { + return fmt.Sprintf(`[[inputs.docker]] + ## Docker Endpoint + ## To use TCP, set endpoint = "tcp://[ip]:[port]" + ## To use environment variables (ie, docker-machine), set endpoint = "ENV" + ## exp: unix:///var/run/docker.sock + endpoint = "%s" +`, d.Endpoint) +} diff --git a/telegraf/plugins/inputs/file.go b/telegraf/plugins/inputs/file.go new file mode 100644 index 0000000000..604e531377 --- /dev/null +++ b/telegraf/plugins/inputs/file.go @@ -0,0 +1,29 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// File is based on telegraf input File plugin. +type File struct { + Files []string `json:"files"` +} + +// TOML encodes to toml string +func (f *File) TOML() string { + s := make([]string, len(f.Files)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.file]] + ## Files to parse each interval. + ## These accept standard unix glob matching rules, but with the addition of + ## ** as a "super asterisk". ie: + ## /var/log/**.log -> recursively find all .log files in /var/log + ## /var/log/*/*.log -> find all .log files with a parent dir in /var/log + ## /var/log/apache.log -> only read the apache log file + files = [%s] +`, strings.Join(f.Files, ", ")) +} diff --git a/telegraf/plugins/inputs/kernel.go b/telegraf/plugins/inputs/kernel.go new file mode 100644 index 0000000000..12b06292b0 --- /dev/null +++ b/telegraf/plugins/inputs/kernel.go @@ -0,0 +1,10 @@ +package inputs + +// Kernel is based on telegraf Kernel. +type Kernel struct{} + +// TOML encodes to toml string +func (k *Kernel) TOML() string { + return `[[inputs.kernel]] +` +} diff --git a/telegraf/plugins/inputs/kubernetes.go b/telegraf/plugins/inputs/kubernetes.go new file mode 100644 index 0000000000..b8a9973b5e --- /dev/null +++ b/telegraf/plugins/inputs/kubernetes.go @@ -0,0 +1,17 @@ +package inputs + +import "fmt" + +// Kubernetes is based on telegraf Kubernetes plugin +type Kubernetes struct { + URL string `json:"url"` +} + +// TOML encodes to toml string. +func (k *Kubernetes) TOML() string { + return fmt.Sprintf(`[[inputs.kubernetes]] + ## URL for the kubelet + ## exp: http://1.1.1.1:10255 + url = "%s" +`, k.URL) +} diff --git a/telegraf/plugins/inputs/logparser.go b/telegraf/plugins/inputs/logparser.go new file mode 100644 index 0000000000..7f1add52a5 --- /dev/null +++ b/telegraf/plugins/inputs/logparser.go @@ -0,0 +1,29 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// LogParserPlugin is based on telegraf LogParserPlugin. +type LogParserPlugin struct { + Files []string `json:"files"` +} + +// TOML encodes to toml string +func (l *LogParserPlugin) TOML() string { + s := make([]string, len(l.Files)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.logparser]] + ## Log files to parse. + ## These accept standard unix glob matching rules, but with the addition of + ## ** as a "super asterisk". ie: + ## /var/log/**.log -> recursively find all .log files in /var/log + ## /var/log/*/*.log -> find all .log files with a parent dir in /var/log + ## /var/log/apache.log -> only tail the apache log file + files = [%s] +`, strings.Join(s, ", ")) +} diff --git a/telegraf/plugins/inputs/mem.go b/telegraf/plugins/inputs/mem.go new file mode 100644 index 0000000000..eda138a8a8 --- /dev/null +++ b/telegraf/plugins/inputs/mem.go @@ -0,0 +1,10 @@ +package inputs + +// MemStats is based on telegraf MemStats. +type MemStats struct{} + +// TOML encodes to toml string +func (m *MemStats) TOML() string { + return `[[inputs.mem]] +` +} diff --git a/telegraf/plugins/inputs/net.go b/telegraf/plugins/inputs/net.go new file mode 100644 index 0000000000..d75d5257b2 --- /dev/null +++ b/telegraf/plugins/inputs/net.go @@ -0,0 +1,10 @@ +package inputs + +// NetIOStats is based on telegraf NetIOStats. +type NetIOStats struct{} + +// TOML encodes to toml string +func (n *NetIOStats) TOML() string { + return `[[inputs.net]] +` +} diff --git a/telegraf/plugins/inputs/net_response.go b/telegraf/plugins/inputs/net_response.go new file mode 100644 index 0000000000..b1f6ca5a26 --- /dev/null +++ b/telegraf/plugins/inputs/net_response.go @@ -0,0 +1,10 @@ +package inputs + +// NetResponse is based on telegraf NetResponse. +type NetResponse struct{} + +// TOML encodes to toml string +func (n *NetResponse) TOML() string { + return `[[inputs.net_response]] +` +} diff --git a/telegraf/plugins/inputs/ngnix.go b/telegraf/plugins/inputs/ngnix.go new file mode 100644 index 0000000000..a6e3db533d --- /dev/null +++ b/telegraf/plugins/inputs/ngnix.go @@ -0,0 +1,24 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// Nginx is based on telegraf nginx plugin. +type Nginx struct { + URLs []string `json:"urls,omitempty"` +} + +// TOML encodes to toml string +func (n *Nginx) TOML() string { + s := make([]string, len(n.URLs)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.nginx]] + # An array of Nginx stub_status URI to gather stats. + urls = [%s] +`, strings.Join(s, ", ")) +} diff --git a/telegraf/plugins/inputs/processes.go b/telegraf/plugins/inputs/processes.go new file mode 100644 index 0000000000..a23448eefb --- /dev/null +++ b/telegraf/plugins/inputs/processes.go @@ -0,0 +1,10 @@ +package inputs + +// Processes is based on telegraf Processes. +type Processes struct{} + +// TOML encodes to toml string +func (p *Processes) TOML() string { + return `[[inputs.processes]] +` +} diff --git a/telegraf/plugins/inputs/procstats.go b/telegraf/plugins/inputs/procstats.go new file mode 100644 index 0000000000..e4feeb88eb --- /dev/null +++ b/telegraf/plugins/inputs/procstats.go @@ -0,0 +1,16 @@ +package inputs + +import "fmt" + +// Procstat is based on telegraf procstat input plugin. +type Procstat struct { + Exe string `json:"exe,omitempty"` +} + +// TOML encodes to toml string. +func (p *Procstat) TOML() string { + return fmt.Sprintf(`[[inputs.procstat]] + ## executable name (ie, pgrep ) + # exe = "%s" +`, p.Exe) +} diff --git a/telegraf/plugins/inputs/prometheus.go b/telegraf/plugins/inputs/prometheus.go new file mode 100644 index 0000000000..f415b5dec4 --- /dev/null +++ b/telegraf/plugins/inputs/prometheus.go @@ -0,0 +1,24 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// Prometheus is based on telegraf Prometheus plugin. +type Prometheus struct { + URLs []string `json:"urls,omitempty"` +} + +// TOML encodes to toml string +func (p *Prometheus) TOML() string { + s := make([]string, len(p.URLs)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.prometheus]] + ## An array of urls to scrape metrics from. + urls = [%s] +`, strings.Join(s, ", ")) +} diff --git a/telegraf/plugins/inputs/redis.go b/telegraf/plugins/inputs/redis.go new file mode 100644 index 0000000000..171b981665 --- /dev/null +++ b/telegraf/plugins/inputs/redis.go @@ -0,0 +1,36 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// Redis is based on telegraf Redis plugin. +type Redis struct { + Servers []string `json:"servers"` + Password string `json:"password"` +} + +// TOML encodes to toml string +func (r *Redis) TOML() string { + s := make([]string, len(r.Servers)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.redis]] + ## specify servers via a url matching: + ## [protocol://][:password]@address[:port] + ## e.g. + ## tcp://localhost:6379 + ## tcp://:password@192.168.99.100 + ## unix:///var/run/redis.sock + ## + ## If no servers are specified, then localhost is used as the host. + ## If no port is specified, 6379 is used + servers = [%s] + + ## specify server password + # password = "%s" +`, strings.Join(s, ", "), r.Password) +} diff --git a/telegraf/plugins/inputs/swap.go b/telegraf/plugins/inputs/swap.go new file mode 100644 index 0000000000..58787e74b0 --- /dev/null +++ b/telegraf/plugins/inputs/swap.go @@ -0,0 +1,10 @@ +package inputs + +// SwapStats is based on telegraf SwapStats. +type SwapStats struct{} + +// TOML encodes to toml string +func (c *SwapStats) TOML() string { + return `[[inputs.swap]] +` +} diff --git a/telegraf/plugins/inputs/syslog.go b/telegraf/plugins/inputs/syslog.go new file mode 100644 index 0000000000..596c93eaa2 --- /dev/null +++ b/telegraf/plugins/inputs/syslog.go @@ -0,0 +1,21 @@ +package inputs + +import ( + "fmt" +) + +// Syslog is based on telegraf Syslog plugin. +type Syslog struct { + Address string `json:"server"` +} + +// TOML encodes to toml string +func (s *Syslog) TOML() string { + return fmt.Sprintf(`[[inputs.syslog]] + ## Specify an ip or hostname with port - eg., tcp://localhost:6514, tcp://10.0.0.1:6514 + ## Protocol, address and port to host the syslog receiver. + ## If no host is specified, then localhost is used. + ## If no port is specified, 6514 is used (RFC5425#section-4.1). + server = "%s" +`, s.Address) +} diff --git a/telegraf/plugins/inputs/system.go b/telegraf/plugins/inputs/system.go new file mode 100644 index 0000000000..c6bdb61864 --- /dev/null +++ b/telegraf/plugins/inputs/system.go @@ -0,0 +1,10 @@ +package inputs + +// SystemStats is based on telegraf SystemStats. +type SystemStats struct{} + +// TOML encodes to toml string +func (s *SystemStats) TOML() string { + return `[[inputs.system]] +` +} diff --git a/telegraf/plugins/inputs/tail.go b/telegraf/plugins/inputs/tail.go new file mode 100644 index 0000000000..051bf2a3bb --- /dev/null +++ b/telegraf/plugins/inputs/tail.go @@ -0,0 +1,32 @@ +package inputs + +import ( + "fmt" + "strconv" + "strings" +) + +// Tail is based on telegraf Tail plugin. +type Tail struct { + Files []string `json:"files"` +} + +// TOML encodes to toml string +func (t *Tail) TOML() string { + s := make([]string, len(t.Files)) + for k, v := range s { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[inputs.tail]] + ## files to tail. + ## These accept standard unix glob matching rules, but with the addition of + ## ** as a "super asterisk". ie: + ## "/var/log/**.log" -> recursively find all .log files in /var/log + ## "/var/log/*/*.log" -> find all .log files with a parent dir in /var/log + ## "/var/log/apache.log" -> just tail the apache log file + ## + ## See https://github.com/gobwas/glob for more examples + ## + files = [%s] +`, strings.Join(s, ", ")) +} diff --git a/telegraf/plugins/outputs/file.go b/telegraf/plugins/outputs/file.go new file mode 100644 index 0000000000..97429a1f04 --- /dev/null +++ b/telegraf/plugins/outputs/file.go @@ -0,0 +1,34 @@ +package outputs + +import ( + "fmt" + "strconv" + "strings" +) + +// File is based on telegraf file output plugin. +type File struct { + Files []FileConfig `json:"files"` +} + +// FileConfig is the config settings of outpu file plugin. +type FileConfig struct { + Typ string `json:"type"` + Path string `json:"path"` +} + +// TOML encodes to toml string. +func (f *File) TOML() string { + s := make([]string, len(f.Files)) + for k, v := range f.Files { + if v.Typ == "stdout" { + s[k] = strconv.Quote(v.Typ) + continue + } + s[k] = strconv.Quote(v.Path) + } + return fmt.Sprintf(`[[outputs.file]] + ## Files to write to, "stdout" is a specially handled file. + files = [%s] +`, strings.Join(s, ", ")) +} diff --git a/telegraf/plugins/outputs/influxdb_v2.go b/telegraf/plugins/outputs/influxdb_v2.go new file mode 100644 index 0000000000..5a01e165ba --- /dev/null +++ b/telegraf/plugins/outputs/influxdb_v2.go @@ -0,0 +1,40 @@ +package outputs + +import ( + "fmt" + "strconv" + "strings" +) + +// InfluxDBV2 is based on telegraf influxdb_v2 output plugin. +type InfluxDBV2 struct { + URLs []string `toml:"urls"` + Token string `toml:"token"` + Organization string `toml:"organization"` + Bucket string `toml:"bucket"` +} + +// TOML encodes to toml string. +func (i *InfluxDBV2) TOML() string { + s := make([]string, len(i.URLs)) + for k, v := range i.URLs { + s[k] = strconv.Quote(v) + } + return fmt.Sprintf(`[[outputs.influxdb_v2]] + ## The URLs of the InfluxDB cluster nodes. + ## + ## Multiple URLs can be specified for a single cluster, only ONE of the + ## urls will be written to each interval. + ## urls exp: http://127.0.0.1:9999 + urls = [%s] + + ## Token for authentication. + token = "%s" + + ## Organization is the name of the organization you wish to write to; must exist. + organization = "%s" + + ## Destination bucket to write into. + bucket = "%s" +`, strings.Join(s, ", "), i.Token, i.Organization, i.Bucket) +}