Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include mount options in disk metrics #3027

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions plugins/inputs/system/DISK_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ In this case, the host's root volume should be mounted into the container and th
- All measurements have the following tags:
- fstype (filesystem type)
- path (mount point path)
- mode (whether the mount is rw or ro)

### Example Output:

```
% ./telegraf --config ~/ws/telegraf.conf --input-filter disk --test
* Plugin: disk, Collection 1
> disk,fstype=hfs,path=/ free=398407520256i,inodes_free=97267461i,inodes_total=121847806i,inodes_used=24580345i,total=499088621568i,used=100418957312i,used_percent=20.131039916242397 1453832006274071563
> disk,fstype=devfs,path=/dev free=0i,inodes_free=0i,inodes_total=628i,inodes_used=628i,total=185856i,used=185856i,used_percent=100 1453832006274137913
> disk,fstype=autofs,path=/net free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274157077
> disk,fstype=autofs,path=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274169688
> disk,fstype=hfs,mode=ro,path=/ free=398407520256i,inodes_free=97267461i,inodes_total=121847806i,inodes_used=24580345i,total=499088621568i,used=100418957312i,used_percent=20.131039916242397 1453832006274071563
> disk,fstype=devfs,mode=rw,path=/dev free=0i,inodes_free=0i,inodes_total=628i,inodes_used=628i,total=185856i,used=185856i,used_percent=100 1453832006274137913
> disk,fstype=autofs,mode=rw,path=/net free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274157077
> disk,fstype=autofs,mode=rw,path=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274169688
```


Expand Down
27 changes: 27 additions & 0 deletions plugins/inputs/system/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ func (s *DiskStats) Gather(acc telegraf.Accumulator) error {
// Skip dummy filesystem (procfs, cgroupfs, ...)
continue
}
mountOpts := parseOptions(partitions[i].Opts)
tags := map[string]string{
"path": du.Path,
"device": strings.Replace(partitions[i].Device, "/dev/", "", -1),
"fstype": du.Fstype,
"mode": mountOpts.Mode(),
}
var used_percent float64
if du.Used+du.Free > 0 {
Expand Down Expand Up @@ -219,6 +221,31 @@ func (s *DiskIOStats) diskTags(devName string) map[string]string {
return tags
}

type MountOptions []string

func (opts MountOptions) Mode() string {
if opts.exists("rw") {
return "rw"
} else if opts.exists("ro") {
return "ro"
} else {
return "unknown"
}
}

func (opts MountOptions) exists(opt string) bool {
for _, o := range opts {
if o == opt {
return true
}
}
return false
}

func parseOptions(opts string) MountOptions {
return strings.Split(opts, ",")
}

func init() {
ps := newSystemPS()
inputs.Add("disk", func() telegraf.Input {
Expand Down
14 changes: 9 additions & 5 deletions plugins/inputs/system/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestDiskUsage(t *testing.T) {
Device: "/dev/sda",
Mountpoint: "/",
Fstype: "ext4",
Opts: "",
Opts: "ro,noatime,nodiratime",
},
{
Device: "/dev/sdb",
Mountpoint: "/home",
Fstype: "ext4",
Opts: "",
Opts: "rw,noatime,nodiratime,errors=remount-ro",
},
}
duAll := []disk.UsageStat{
Expand Down Expand Up @@ -78,11 +78,13 @@ func TestDiskUsage(t *testing.T) {
"path": "/",
"fstype": "ext4",
"device": "sda",
"mode": "ro",
}
tags2 := map[string]string{
"path": "/home",
"fstype": "ext4",
"device": "sdb",
"mode": "rw",
}

fields1 := map[string]interface{}{
Expand Down Expand Up @@ -163,13 +165,13 @@ func TestDiskStats(t *testing.T) {
Device: "/dev/sda",
Mountpoint: "/",
Fstype: "ext4",
Opts: "",
Opts: "ro,noatime,nodiratime",
},
{
Device: "/dev/sdb",
Mountpoint: "/home",
Fstype: "ext4",
Opts: "",
Opts: "rw,noatime,nodiratime,errors=remount-ro",
},
}

Expand All @@ -178,7 +180,7 @@ func TestDiskStats(t *testing.T) {
Device: "/dev/sda",
Mountpoint: "/",
Fstype: "ext4",
Opts: "",
Opts: "ro,noatime,nodiratime",
},
}

Expand All @@ -197,11 +199,13 @@ func TestDiskStats(t *testing.T) {
"path": "/",
"fstype": "ext4",
"device": "sda",
"mode": "ro",
}
tags2 := map[string]string{
"path": "/home",
"fstype": "ext4",
"device": "sdb",
"mode": "rw",
}

fields1 := map[string]interface{}{
Expand Down