Include mount mode option in disk metrics (#3027)
This commit is contained in:
parent
144862354a
commit
99dfc69fbb
|
@ -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:
|
- All measurements have the following tags:
|
||||||
- fstype (filesystem type)
|
- fstype (filesystem type)
|
||||||
- path (mount point path)
|
- path (mount point path)
|
||||||
|
- mode (whether the mount is rw or ro)
|
||||||
|
|
||||||
### Example Output:
|
### Example Output:
|
||||||
|
|
||||||
```
|
```
|
||||||
% ./telegraf --config ~/ws/telegraf.conf --input-filter disk --test
|
% ./telegraf --config ~/ws/telegraf.conf --input-filter disk --test
|
||||||
* Plugin: disk, Collection 1
|
* 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=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,path=/dev free=0i,inodes_free=0i,inodes_total=628i,inodes_used=628i,total=185856i,used=185856i,used_percent=100 1453832006274137913
|
> 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,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=/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=autofs,mode=rw,path=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274169688
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,12 @@ func (s *DiskStats) Gather(acc telegraf.Accumulator) error {
|
||||||
// Skip dummy filesystem (procfs, cgroupfs, ...)
|
// Skip dummy filesystem (procfs, cgroupfs, ...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
mountOpts := parseOptions(partitions[i].Opts)
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"path": du.Path,
|
"path": du.Path,
|
||||||
"device": strings.Replace(partitions[i].Device, "/dev/", "", -1),
|
"device": strings.Replace(partitions[i].Device, "/dev/", "", -1),
|
||||||
"fstype": du.Fstype,
|
"fstype": du.Fstype,
|
||||||
|
"mode": mountOpts.Mode(),
|
||||||
}
|
}
|
||||||
var used_percent float64
|
var used_percent float64
|
||||||
if du.Used+du.Free > 0 {
|
if du.Used+du.Free > 0 {
|
||||||
|
@ -219,6 +221,31 @@ func (s *DiskIOStats) diskTags(devName string) map[string]string {
|
||||||
return tags
|
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() {
|
func init() {
|
||||||
ps := newSystemPS()
|
ps := newSystemPS()
|
||||||
inputs.Add("disk", func() telegraf.Input {
|
inputs.Add("disk", func() telegraf.Input {
|
||||||
|
|
|
@ -28,13 +28,13 @@ func TestDiskUsage(t *testing.T) {
|
||||||
Device: "/dev/sda",
|
Device: "/dev/sda",
|
||||||
Mountpoint: "/",
|
Mountpoint: "/",
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Opts: "",
|
Opts: "ro,noatime,nodiratime",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Device: "/dev/sdb",
|
Device: "/dev/sdb",
|
||||||
Mountpoint: "/home",
|
Mountpoint: "/home",
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Opts: "",
|
Opts: "rw,noatime,nodiratime,errors=remount-ro",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
duAll := []disk.UsageStat{
|
duAll := []disk.UsageStat{
|
||||||
|
@ -78,11 +78,13 @@ func TestDiskUsage(t *testing.T) {
|
||||||
"path": "/",
|
"path": "/",
|
||||||
"fstype": "ext4",
|
"fstype": "ext4",
|
||||||
"device": "sda",
|
"device": "sda",
|
||||||
|
"mode": "ro",
|
||||||
}
|
}
|
||||||
tags2 := map[string]string{
|
tags2 := map[string]string{
|
||||||
"path": "/home",
|
"path": "/home",
|
||||||
"fstype": "ext4",
|
"fstype": "ext4",
|
||||||
"device": "sdb",
|
"device": "sdb",
|
||||||
|
"mode": "rw",
|
||||||
}
|
}
|
||||||
|
|
||||||
fields1 := map[string]interface{}{
|
fields1 := map[string]interface{}{
|
||||||
|
@ -163,13 +165,13 @@ func TestDiskStats(t *testing.T) {
|
||||||
Device: "/dev/sda",
|
Device: "/dev/sda",
|
||||||
Mountpoint: "/",
|
Mountpoint: "/",
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Opts: "",
|
Opts: "ro,noatime,nodiratime",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Device: "/dev/sdb",
|
Device: "/dev/sdb",
|
||||||
Mountpoint: "/home",
|
Mountpoint: "/home",
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Opts: "",
|
Opts: "rw,noatime,nodiratime,errors=remount-ro",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +180,7 @@ func TestDiskStats(t *testing.T) {
|
||||||
Device: "/dev/sda",
|
Device: "/dev/sda",
|
||||||
Mountpoint: "/",
|
Mountpoint: "/",
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Opts: "",
|
Opts: "ro,noatime,nodiratime",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,11 +199,13 @@ func TestDiskStats(t *testing.T) {
|
||||||
"path": "/",
|
"path": "/",
|
||||||
"fstype": "ext4",
|
"fstype": "ext4",
|
||||||
"device": "sda",
|
"device": "sda",
|
||||||
|
"mode": "ro",
|
||||||
}
|
}
|
||||||
tags2 := map[string]string{
|
tags2 := map[string]string{
|
||||||
"path": "/home",
|
"path": "/home",
|
||||||
"fstype": "ext4",
|
"fstype": "ext4",
|
||||||
"device": "sdb",
|
"device": "sdb",
|
||||||
|
"mode": "rw",
|
||||||
}
|
}
|
||||||
|
|
||||||
fields1 := map[string]interface{}{
|
fields1 := map[string]interface{}{
|
||||||
|
|
Loading…
Reference in New Issue