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.
This commit is contained in:
Rasmus Larsen 2016-08-30 12:29:46 +02:00
parent 7a97c1843e
commit 7ea24dd953
5 changed files with 53 additions and 57 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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)

View File

@ -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{}
})
}

View File

@ -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),