Skip to content

Commit

Permalink
Applying PR feedback:
Browse files Browse the repository at this point in the history
- Rebased onto master
- Updated README/CHANGELOG
- Limited lines to 80 chars
- Improved plugin docs and README
- added a dummy windows build file
  • Loading branch information
robinpercy-xm committed May 21, 2016
1 parent 95fd067 commit d505750
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- [#1164](https://github.com/influxdata/telegraf/pull/1164): conntrack input plugin. Thanks @robinpercy!
- [#1138](https://github.com/influxdata/telegraf/pull/1138): nstat input plugin. Thanks @Maksadbek!
- [#1139](https://github.com/influxdata/telegraf/pull/1139): instrumental output plugin. Thanks @jasonroelofs!
- [#1172](https://github.com/influxdata/telegraf/pull/1172): Ceph storage stats. Thanks @robinpercy!
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Currently implemented sources:
* [bcache](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/bcache)
* [cassandra](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/cassandra)
* [ceph](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/ceph)
* [conntrack](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/conntrack)
* [couchbase](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/couchbase)
* [couchdb](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/couchdb)
* [disque](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/disque)
Expand Down
33 changes: 27 additions & 6 deletions plugins/inputs/conntrack/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
# Conntrack Plugin

Collects conntrack stats from the configured directories and files.
Collects stats from Netfilter's conntrack-tools.

The conntrack-tools provide a mechanism for tracking various aspects of
network connections as they are processed by netfilter. At runtime,
conntrack exposes many of those connection statistics within /proc/sys/net.
Depending on your kernel version, these files can be found in either
/proc/sys/net/ipv4/netfilter or /proc/sys/net/netfilter and will be
prefixed with either ip_ or nf_. This plugin reads the files specified
in its configuration and publishes each one as a field, with the prefix
normalized to ip_.

In order to simplify configuration in a heterogeneous environment, a superset
of directory and filenames can be specified. Any locations that don't exist
will be ignored.

For more information on conntrack-tools, see the
[Netfilter Documentation](http://conntrack-tools.netfilter.org/).


### Configuration:

```toml
# Collects conntrack stats from the configured directories and files.
[[inputs.conntrack]]
## The following defaults would work with multiple versions of contrack. Note the nf_ and ip_
## filename prefixes are mutually exclusive across conntrack versions, as are the directory locations.
## The following defaults would work with multiple versions of conntrack.
## Note the nf_ and ip_ filename prefixes are mutually exclusive across
## kernel versions, as are the directory locations.

## Superset of filenames to look for within the conntrack dirs. Missing files will be ignored.
files = ["ip_conntrack_count","ip_conntrack_max","nf_conntrack_count","nf_conntrack_max"]
## Superset of filenames to look for within the conntrack dirs.
## Missing files will be ignored.
files = ["ip_conntrack_count","ip_conntrack_max",
"nf_conntrack_count","nf_conntrack_max"]

## Directories to search within for the conntrack files above. Missing directrories will be ignored.
## Directories to search within for the conntrack files above.
## Missing directrories will be ignored.
dirs = ["/proc/sys/net/ipv4/netfilter","/proc/sys/net/netfilter"]
```

Expand Down
27 changes: 17 additions & 10 deletions plugins/inputs/conntrack/conntrack.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !windows

package conntrack

import (
Expand Down Expand Up @@ -50,15 +52,17 @@ func (c *Conntrack) Description() string {
}

var sampleConfig = `
# Collects conntrack stats from the configured directories and files.
[[inputs.conntrack]]
## The following defaults would work with multiple versions of contrack. Note the nf_ and ip_
## filename prefixes are mutually exclusive across conntrack versions, as are the directory locations.
## The following defaults would work with multiple versions of conntrack.
## Note the nf_ and ip_ filename prefixes are mutually exclusive across
## kernel versions, as are the directory locations.
## Superset of filenames to look for within the conntrack dirs. Missing files will be ignored.
files = ["ip_conntrack_count","ip_conntrack_max","nf_conntrack_count","nf_conntrack_max"]
## Superset of filenames to look for within the conntrack dirs.
## Missing files will be ignored.
files = ["ip_conntrack_count","ip_conntrack_max",
"nf_conntrack_count","nf_conntrack_max"]
## Directories to search within for the conntrack files above. Missing directrories will be ignored.
## Directories to search within for the conntrack files above.
## Missing directrories will be ignored.
dirs = ["/proc/sys/net/ipv4/netfilter","/proc/sys/net/netfilter"]
`

Expand All @@ -74,7 +78,8 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {

for _, dir := range c.Dirs {
for _, file := range c.Files {
// NOTE: no system will have both nf_ and ip_ prefixes, so we're safe to branch on suffix only.
// NOTE: no system will have both nf_ and ip_ prefixes,
// so we're safe to branch on suffix only.
parts := strings.SplitN(file, "_", 2)
if len(parts) < 2 {
continue
Expand All @@ -94,13 +99,15 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {
v := strings.TrimSpace(string(contents))
fields[metricKey], err = strconv.ParseFloat(v, 64)
if err != nil {
log.Printf("failed to parse metric, expected number but found '%s': %v", v, err)
log.Printf("failed to parse metric, expected number but "+
" found '%s': %v", v, err)
}
}
}

if len(fields) == 0 {
return fmt.Errorf("Conntrack input failed to collect metrics. Is the conntrack kernel module loaded?")
return fmt.Errorf("Conntrack input failed to collect metrics. " +
"Is the conntrack kernel module loaded?")
}

acc.AddFields(inputName, fields, nil)
Expand Down
8 changes: 6 additions & 2 deletions plugins/inputs/conntrack/conntrack_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !windows

package conntrack

import (
Expand Down Expand Up @@ -25,7 +27,8 @@ func TestNoFilesFound(t *testing.T) {
acc := &testutil.Accumulator{}
err := c.Gather(acc)

assert.EqualError(t, err, "Conntrack input failed to collect metrics. Is the conntrack kernel module loaded?")
assert.EqualError(t, err, "Conntrack input failed to collect metrics. "+
"Is the conntrack kernel module loaded?")
}

func TestDefaultsUsed(t *testing.T) {
Expand All @@ -47,7 +50,8 @@ func TestDefaultsUsed(t *testing.T) {
acc := &testutil.Accumulator{}

c.Gather(acc)
acc.AssertContainsFields(t, inputName, map[string]interface{}{fname: float64(count)})
acc.AssertContainsFields(t, inputName, map[string]interface{}{
fname: float64(count)})
}

func TestConfigsUsed(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/conntrack/conntrack_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +build windows

package conntrack

0 comments on commit d505750

Please sign in to comment.