From 7ea24dd953be4715363a02cc8920a38aa918b1b9 Mon Sep 17 00:00:00 2001 From: Rasmus Larsen Date: Tue, 30 Aug 2016 12:29:46 +0200 Subject: [PATCH] Change input name from NFS to NFSCLIENT. - Remove Iostat option and enable it generally. - Disable Fullstat by default. - Move mountpoint tag into two separate tags, one still called mountpoint and one called serverexport. - Update descriptions. - Fix bug that caused the tags not to show up on Ubuntu 16.04. --- plugins/inputs/all/all.go | 2 +- plugins/inputs/nfs/README.md | 14 ------ plugins/inputs/nfsclient/README.md | 14 ++++++ .../{nfs/nfs.go => nfsclient/nfsclient.go} | 48 +++++++++---------- .../nfsclient_test.go} | 32 ++++++------- 5 files changed, 53 insertions(+), 57 deletions(-) delete mode 100644 plugins/inputs/nfs/README.md create mode 100644 plugins/inputs/nfsclient/README.md rename plugins/inputs/{nfs/nfs.go => nfsclient/nfsclient.go} (85%) rename plugins/inputs/{nfs/nfs_test.go => nfsclient/nfsclient_test.go} (93%) diff --git a/plugins/inputs/all/all.go b/plugins/inputs/all/all.go index cfa4b47ad..228e5d2b6 100644 --- a/plugins/inputs/all/all.go +++ b/plugins/inputs/all/all.go @@ -41,7 +41,7 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/nats_consumer" _ "github.com/influxdata/telegraf/plugins/inputs/net_response" _ "github.com/influxdata/telegraf/plugins/inputs/nginx" - _ "github.com/influxdata/telegraf/plugins/inputs/nfs" + _ "github.com/influxdata/telegraf/plugins/inputs/nfsclient" _ "github.com/influxdata/telegraf/plugins/inputs/nsq" _ "github.com/influxdata/telegraf/plugins/inputs/nsq_consumer" _ "github.com/influxdata/telegraf/plugins/inputs/nstat" diff --git a/plugins/inputs/nfs/README.md b/plugins/inputs/nfs/README.md deleted file mode 100644 index 6c748079c..000000000 --- a/plugins/inputs/nfs/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Telegraf plugin: NFS - -#### Plugin arguments: -- **iostat** bool: Collect only the common iostat metrics -- **fullstat** bool: Collect all metrics available - -#### Description - -The NFS plugin collects data from /proc/self/mountstats - -#### References -[nfsiostat](http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=summary) - -[What is in /proc/self/mountstats for NFS mounts: an introduction](https://utcc.utoronto.ca/~cks/space/blog/linux/NFSMountstatsIndex) diff --git a/plugins/inputs/nfsclient/README.md b/plugins/inputs/nfsclient/README.md new file mode 100644 index 000000000..7f514c3be --- /dev/null +++ b/plugins/inputs/nfsclient/README.md @@ -0,0 +1,14 @@ +# Telegraf plugin: NFSCLIENT + +#### Plugin arguments: +- **fullstat** bool: Collect per-operation statistics + +#### Description + +The NFSCLIENT plugin collects data from /proc/self/mountstats, by default it will only include a quite limited set of IO metrics. +If fullstat is set, it will collect a lot of per-operation statistics. + +#### References +[nfsiostat](http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=summary) + +[What is in /proc/self/mountstats for NFS mounts: an introduction](https://utcc.utoronto.ca/~cks/space/blog/linux/NFSMountstatsIndex) diff --git a/plugins/inputs/nfs/nfs.go b/plugins/inputs/nfsclient/nfsclient.go similarity index 85% rename from plugins/inputs/nfs/nfs.go rename to plugins/inputs/nfsclient/nfsclient.go index 69ed58b46..3365040bd 100644 --- a/plugins/inputs/nfs/nfs.go +++ b/plugins/inputs/nfsclient/nfsclient.go @@ -1,4 +1,4 @@ -package nfs +package nfsclient import ( "bufio" @@ -12,26 +12,22 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) -type NFS struct { - Iostat bool +type NFSCLIENT struct { Fullstat bool } var sampleConfig = ` - # iostat = true - # Read iostat metrics - iostat = true # fullstat = true - # Read all metrics - fullstat = true + # Read more low-level metrics + fullstat = false ` -func (n *NFS) SampleConfig() string { +func (n *NFSCLIENT) SampleConfig() string { return sampleConfig } -func (n *NFS) Description() string { - return "Read NFS metrics from /proc/self/mountstats" +func (n *NFSCLIENT) Description() string { + return "Read per-mount NFS metrics from /proc/self/mountstats" } var eventsFields = []string{ @@ -214,8 +210,8 @@ func In(list []string, val string) bool { return false } -func (n *NFS) parseStat(mountpoint string, version string, line []string, acc telegraf.Accumulator) error { - tags := map[string]string{"mountpoint": mountpoint} +func (n *NFSCLIENT) parseStat(mountpoint string, export string, version string, line []string, acc telegraf.Accumulator) error { + tags := map[string]string{"mountpoint": mountpoint, "serverexport": export} nline := convert(line) first := strings.Replace(line[0], ":", "", 1) @@ -243,8 +239,8 @@ func (n *NFS) parseStat(mountpoint string, version string, line []string, acc te return nil } -func (n *NFS) parseData(mountpoint string, version string, line []string, acc telegraf.Accumulator) error { - tags := map[string]string{"mountpoint": mountpoint} +func (n *NFSCLIENT) parseData(mountpoint string, export string, version string, line []string, acc telegraf.Accumulator) error { + tags := map[string]string{"mountpoint": mountpoint, "serverexport": export} nline := convert(line) first := strings.Replace(line[0], ":", "", 1) @@ -295,29 +291,29 @@ func (n *NFS) parseData(mountpoint string, version string, line []string, acc te return nil } -func (n *NFS) processText(scanner *bufio.Scanner, acc telegraf.Accumulator) error { +func (n *NFSCLIENT) processText(scanner *bufio.Scanner, acc telegraf.Accumulator) error { var device string var version string + var export string for scanner.Scan() { line := strings.Fields(scanner.Text()) - if In(line, "fstype") && In(line, "nfs") { - device = fmt.Sprintf("%s %s", line[1], line[4]) - } else if In(line, "(nfs)") { + if In(line, "fstype") && In(line, "nfs") || In(line, "nfs4") { + device = line[4] + export = line[1] + } else if In(line, "(nfs)") || In(line, "(nfs4)") { version = strings.Split(line[5], "/")[1] } if (len(line) > 0) { - if n.Iostat == true { - n.parseStat(device, version, line, acc) - } + n.parseStat(device, export, version, line, acc) if n.Fullstat == true { - n.parseData(device, version, line, acc) + n.parseData(device, export, version, line, acc) } } } return nil } -func (n *NFS) Gather(acc telegraf.Accumulator) error { +func (n *NFSCLIENT) Gather(acc telegraf.Accumulator) error { var outerr error file, err := os.Open("/proc/self/mountstats") @@ -337,7 +333,7 @@ func (n *NFS) Gather(acc telegraf.Accumulator) error { } func init() { - inputs.Add("nfs", func() telegraf.Input { - return &NFS{} + inputs.Add("nfsclient", func() telegraf.Input { + return &NFSCLIENT{} }) } diff --git a/plugins/inputs/nfs/nfs_test.go b/plugins/inputs/nfsclient/nfsclient_test.go similarity index 93% rename from plugins/inputs/nfs/nfs_test.go rename to plugins/inputs/nfsclient/nfsclient_test.go index 75d73c9d8..248e9301a 100644 --- a/plugins/inputs/nfs/nfs_test.go +++ b/plugins/inputs/nfsclient/nfsclient_test.go @@ -1,4 +1,4 @@ -package nfs +package nfsclient import ( "testing" @@ -34,7 +34,7 @@ device cgroup mounted on /cgroup/blkio with fstype cgroup device sunrpc mounted on /var/lib/nfs/rpc_pipefs with fstype rpc_pipefs device /etc/auto.misc mounted on /misc with fstype autofs device -hosts mounted on /net with fstype autofs -device 1.2.3.4:/storage/NFS mounted on /storage/NFS with fstype nfs statvers=1.1 +device 1.2.3.4:/storage/NFSCLIENT mounted on /storage/NFS with fstype nfs statvers=1.1 opts: rw,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=60,acregmax=60,acdirmin=60,acdirmax=60,hard,nolock,noacl,nordirplus,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=1.2.3.4,mountvers=3,mountport=49193,mountproto=tcp,local_lock=all age: 1136770 caps: caps=0x3fe6,wtmult=512,dtsize=8192,bsize=0,namlen=255 @@ -130,12 +130,12 @@ device 2.2.2.2:/nfsdata/ mounted on /mnt with fstype nfs4 statvers=1.1 ` -func TestNFSParsev3(t *testing.T) { +func TestNFSCLIENTParsev3(t *testing.T) { var acc testutil.Accumulator - nfs := NFS{} + nfsclient := NFSCLIENT{} data := strings.Fields(" READLINK: 500 501 502 503 504 505 506 507") - nfs.parseData("1.2.3.4:/storage/NFS /storage/NFS", "3", data, &acc) + nfsclient.parseData("1.2.3.4:/storage/NFSCLIENT /storage/NFS", "3", data, &acc) fields_ops := map[string]interface{}{ "READLINK_ops": float64(500), @@ -150,10 +150,10 @@ func TestNFSParsev3(t *testing.T) { acc.AssertContainsFields(t, "nfs_ops", fields_ops) } -func TestNFSParsev4(t *testing.T) { +func TestNFSCLIENTParsev4(t *testing.T) { var acc testutil.Accumulator - nfs := NFS{} + nfsclient := NFSCLIENT{} data := strings.Fields(" DESTROY_SESSION: 500 501 502 503 504 505 506 507") nfs.parseData("2.2.2.2:/nfsdata/ /mnt", "4", data, &acc) @@ -170,14 +170,14 @@ func TestNFSParsev4(t *testing.T) { acc.AssertContainsFields(t, "nfs_ops", fields_ops) } -func TestNFSProcessStat(t *testing.T) { +func TestNFSCLIENTProcessStat(t *testing.T) { var acc testutil.Accumulator - nfs := NFS{} - nfs.Iostat = true + nfsclient := NFSCLIENT{} + nfsclient.Iostat = true scanner := bufio.NewScanner(strings.NewReader(mountstatstext)) - nfs.processText(scanner, &acc) + nfsclient.processText(scanner, &acc) fields_readstat := map[string]interface{}{ "read_ops": float64(600), @@ -194,20 +194,20 @@ func TestNFSProcessStat(t *testing.T) { "write_exe": float64(707), } tags := map[string]string { - "mountpoint": "1.2.3.4:/storage/NFS /storage/NFS", + "mountpoint": "1.2.3.4:/storage/NFSCLIENT /storage/NFS", } acc.AssertContainsTaggedFields(t, "nfsstat_read", fields_readstat, tags) acc.AssertContainsTaggedFields(t, "nfsstat_write", fields_writestat, tags) } -func TestNFSProcessFull(t *testing.T) { +func TestNFSCLIENTProcessFull(t *testing.T) { var acc testutil.Accumulator - nfs := NFS{} - nfs.Fullstat = true + nfsclient := NFSCLIENT{} + nfsclient.Fullstat = true scanner := bufio.NewScanner(strings.NewReader(mountstatstext)) - nfs.processText(scanner, &acc) + nfsclient.processText(scanner, &acc) fields_events := map[string]interface{}{ "inoderevalidates": float64(301736),