Skip to content

Commit

Permalink
Cleanup config file
Browse files Browse the repository at this point in the history
closes #199
  • Loading branch information
sparrc committed Apr 1, 2016
1 parent 91957f0 commit dc4f87b
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 99 deletions.
47 changes: 21 additions & 26 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Telegraf configuration

# Telegraf Configuration
#
# Telegraf is entirely plugin driven. All metrics are gathered from the
# declared inputs, and sent to the declared outputs.

#
# Plugins must be declared in here to be active.
# To deactivate a plugin, comment out the name and any variables.

#
# Use 'telegraf -config telegraf.conf -test' to see what metrics a config
# file would generate.

Expand Down Expand Up @@ -48,10 +48,11 @@
quiet = false
## Override default hostname, if empty use os.Hostname()
hostname = ""

## If set to true, do no set the "host" tag in the telegraf agent.
omit_hostname = false

###############################################################################
# OUTPUTS #
# OUTPUT PLUGINS #
###############################################################################

# Configuration for influxdb server to send metrics to
Expand Down Expand Up @@ -86,43 +87,38 @@
## Use SSL but skip chain & host verification
# insecure_skip_verify = false


###############################################################################
# INPUTS #
# INPUT PLUGINS #
###############################################################################

# Read metrics about cpu usage
[[inputs.cpu]]
# Whether to report per-cpu stats or not
## Whether to report per-cpu stats or not
percpu = true
# Whether to report total system cpu stats or not
## Whether to report total system cpu stats or not
totalcpu = true
# Comment this line if you want the raw CPU time metrics
## Comment this line if you want the raw CPU time metrics
fielddrop = ["time_*"]

# Read metrics about disk usage by mount point
[[inputs.disk]]
# By default, telegraf gather stats for all mountpoints.
# Setting mountpoints will restrict the stats to the specified mountpoints.
# mount_points=["/"]
## By default, telegraf gather stats for all mountpoints.
## Setting mountpoints will restrict the stats to the specified mountpoints.
# mount_points = ["/"]

# Ignore some mountpoints by filesystem type. For example (dev)tmpfs (usually
# present on /run, /var/run, /dev/shm or /dev).
## Ignore some mountpoints by filesystem type. For example (dev)tmpfs (usually
## present on /run, /var/run, /dev/shm or /dev).
ignore_fs = ["tmpfs", "devtmpfs"]

# Read metrics about disk IO by device
[[inputs.diskio]]
# By default, telegraf will gather stats for all devices including
# disk partitions.
# Setting devices will restrict the stats to the specified devices.
## By default, telegraf will gather stats for all devices including
## disk partitions.
## Setting devices will restrict the stats to the specified devices.
# devices = ["sda", "sdb"]
# Uncomment the following line if you do not need disk serial numbers.
## Uncomment the following line if you do not need disk serial numbers.
# skip_serial_number = true

# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# no configuration

# Read metrics about memory usage
[[inputs.mem]]
# no configuration
Expand All @@ -139,7 +135,6 @@
[[inputs.system]]
# no configuration


###############################################################################
# SERVICE INPUTS #
# SERVICE INPUT PLUGINS #
###############################################################################
134 changes: 98 additions & 36 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import (
"github.com/influxdata/toml/ast"
)

var (
// Default input plugins
inputDefaults = []string{"cpu", "mem", "swap", "system", "kernel",
"processes", "disk", "diskio"}

// Default output plugins
outputDefaults = []string{"influxdb"}
)

// Config specifies the URL/user/password for the database that telegraf
// will be logging to, as well as all the plugins that the user has
// specified
Expand Down Expand Up @@ -135,21 +144,23 @@ func (c *Config) ListTags() string {
}

var header = `# Telegraf Configuration
#
# Telegraf is entirely plugin driven. All metrics are gathered from the
# declared inputs, and sent to the declared outputs.
#
# Plugins must be declared in here to be active.
# To deactivate a plugin, comment out the name and any variables.
#
# Use 'telegraf -config telegraf.conf -test' to see what metrics a config
# file would generate.
# Global tags can be specified here in key="value" format.
[global_tags]
# dc = "us-east-1" # will tag all metrics with dc=us-east-1
# rack = "1a"
# Configuration for telegraf agent
[agent]
## Default data collection interval for all inputs
Expand Down Expand Up @@ -188,55 +199,72 @@ var header = `# Telegraf Configuration
omit_hostname = false
#
# OUTPUTS:
#
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
`

var pluginHeader = `
#
# INPUTS:
#
var inputHeader = `
###############################################################################
# INPUT PLUGINS #
###############################################################################
`

var serviceInputHeader = `
#
# SERVICE INPUTS:
#
###############################################################################
# SERVICE INPUT PLUGINS #
###############################################################################
`

// PrintSampleConfig prints the sample config
func PrintSampleConfig(pluginFilters []string, outputFilters []string) {
func PrintSampleConfig(inputFilters []string, outputFilters []string) {
fmt.Printf(header)

// Filter outputs
var onames []string
for oname := range outputs.Outputs {
if len(outputFilters) == 0 || sliceContains(oname, outputFilters) {
onames = append(onames, oname)
if len(outputFilters) != 0 {
printFilteredOutputs(outputFilters, false)
} else {
printFilteredOutputs(outputDefaults, false)
// Print non-default outputs, commented
var pnames []string
for pname := range outputs.Outputs {
if !sliceContains(pname, outputDefaults) {
pnames = append(pnames, pname)
}
}
sort.Strings(pnames)
printFilteredOutputs(pnames, true)
}
sort.Strings(onames)

// Print Outputs
for _, oname := range onames {
creator := outputs.Outputs[oname]
output := creator()
printConfig(oname, output, "outputs")
fmt.Printf(inputHeader)
if len(inputFilters) != 0 {
printFilteredInputs(inputFilters, false)
} else {
printFilteredInputs(inputDefaults, false)
// Print non-default inputs, commented
var pnames []string
for pname := range inputs.Inputs {
if !sliceContains(pname, inputDefaults) {
pnames = append(pnames, pname)
}
}
sort.Strings(pnames)
printFilteredInputs(pnames, true)
}
}

func printFilteredInputs(inputFilters []string, commented bool) {
// Filter inputs
var pnames []string
for pname := range inputs.Inputs {
if len(pluginFilters) == 0 || sliceContains(pname, pluginFilters) {
if sliceContains(pname, inputFilters) {
pnames = append(pnames, pname)
}
}
sort.Strings(pnames)

// Print Inputs
fmt.Printf(pluginHeader)
servInputs := make(map[string]telegraf.ServiceInput)
for _, pname := range pnames {
creator := inputs.Inputs[pname]
Expand All @@ -248,13 +276,34 @@ func PrintSampleConfig(pluginFilters []string, outputFilters []string) {
continue
}

printConfig(pname, input, "inputs")
printConfig(pname, input, "inputs", commented)
}

// Print Service Inputs
if len(servInputs) == 0 {
return
}
fmt.Printf(serviceInputHeader)
for name, input := range servInputs {
printConfig(name, input, "inputs")
printConfig(name, input, "inputs", commented)
}
}

func printFilteredOutputs(outputFilters []string, commented bool) {
// Filter outputs
var onames []string
for oname := range outputs.Outputs {
if sliceContains(oname, outputFilters) {
onames = append(onames, oname)
}
}
sort.Strings(onames)

// Print Outputs
for _, oname := range onames {
creator := outputs.Outputs[oname]
output := creator()
printConfig(oname, output, "outputs", commented)
}
}

Expand All @@ -263,13 +312,26 @@ type printer interface {
SampleConfig() string
}

func printConfig(name string, p printer, op string) {
fmt.Printf("\n# %s\n[[%s.%s]]", p.Description(), op, name)
func printConfig(name string, p printer, op string, commented bool) {
comment := ""
if commented {
comment = "# "
}
fmt.Printf("\n%s# %s\n%s[[%s.%s]]", comment, p.Description(), comment,
op, name)

config := p.SampleConfig()
if config == "" {
fmt.Printf("\n # no configuration\n")
fmt.Printf("\n%s # no configuration\n\n", comment)
} else {
fmt.Printf(config)
lines := strings.Split(config, "\n")
for i, line := range lines {
if i == 0 || i == len(lines)-1 {
fmt.Print("\n")
continue
}
fmt.Print(comment + line + "\n")
}
}
}

Expand All @@ -285,7 +347,7 @@ func sliceContains(name string, list []string) bool {
// PrintInputConfig prints the config usage of a single input.
func PrintInputConfig(name string) error {
if creator, ok := inputs.Inputs[name]; ok {
printConfig(name, creator(), "inputs")
printConfig(name, creator(), "inputs", false)
} else {
return errors.New(fmt.Sprintf("Input %s not found", name))
}
Expand All @@ -295,7 +357,7 @@ func PrintInputConfig(name string) error {
// PrintOutputConfig prints the config usage of a single output.
func PrintOutputConfig(name string) error {
if creator, ok := outputs.Outputs[name]; ok {
printConfig(name, creator(), "outputs")
printConfig(name, creator(), "outputs", false)
} else {
return errors.New(fmt.Sprintf("Output %s not found", name))
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/inputs/disque/disque.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ type Disque struct {

var sampleConfig = `
## An array of URI to gather stats about. Specify an ip or hostname
## with optional port and password. ie disque://localhost, disque://10.10.3.33:18832,
## 10.0.0.1:10000, etc.
## with optional port and password.
## ie disque://localhost, disque://10.10.3.33:18832, 10.0.0.1:10000, etc.
## If no servers are specified, then localhost is used as the host.
servers = ["localhost"]
`
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/dns_query/dns_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var sampleConfig = `
## Domains or subdomains to query. "."(root) is default
domains = ["."] # optional
## Query record type. Posible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV. Default is "NS"
## Query record type. Default is "A"
## Posible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV.
record_type = "A" # optional
## Dns server port. 53 is default
Expand Down
11 changes: 10 additions & 1 deletion plugins/inputs/mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ var sampleConfig = `
# A list of Mesos masters, default value is localhost:5050.
masters = ["localhost:5050"]
# Metrics groups to be collected, by default, all enabled.
master_collections = ["resources","master","system","slaves","frameworks","messages","evqueue","registrar"]
master_collections = [
"resources",
"master",
"system",
"slaves",
"frameworks",
"messages",
"evqueue",
"registrar",
]
`

// SampleConfig returns a sample configuration block
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var ignoredColumns = map[string]bool{"datid": true, "datname": true, "stats_rese

var sampleConfig = `
## specify address via a url matching:
## postgres://[pqgotest[:password]]@localhost[/dbname]?sslmode=[disable|verify-ca|verify-full]
## postgres://[pqgotest[:password]]@localhost[/dbname]\
## ?sslmode=[disable|verify-ca|verify-full]
## or a simple string:
## host=localhost user=pqotest password=... sslmode=... dbname=app_production
##
Expand Down
Loading

0 comments on commit dc4f87b

Please sign in to comment.