2015-05-18 23:01:42 +00:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2015-05-22 23:45:14 +00:00
|
|
|
"github.com/influxdb/telegraf/plugins"
|
2015-05-18 23:01:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DiskStats struct {
|
|
|
|
ps PS
|
2015-10-07 21:42:11 +00:00
|
|
|
|
|
|
|
Mountpoints []string
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *DiskStats) Description() string {
|
|
|
|
return "Read metrics about disk usage by mount point"
|
|
|
|
}
|
|
|
|
|
2015-10-07 21:42:11 +00:00
|
|
|
var diskSampleConfig = `
|
2015-10-15 21:53:29 +00:00
|
|
|
# By default, telegraf gather stats for all mountpoints.
|
|
|
|
# Setting mountpoints will restrict the stats to the specified ones.
|
|
|
|
# mountpoints.
|
|
|
|
# Mountpoints=["/"]
|
2015-10-08 21:17:04 +00:00
|
|
|
`
|
2015-10-07 21:42:11 +00:00
|
|
|
|
2015-10-08 21:17:04 +00:00
|
|
|
func (_ *DiskStats) SampleConfig() string {
|
|
|
|
return diskSampleConfig
|
2015-10-07 21:42:11 +00:00
|
|
|
}
|
2015-05-18 23:01:42 +00:00
|
|
|
|
|
|
|
func (s *DiskStats) Gather(acc plugins.Accumulator) error {
|
|
|
|
disks, err := s.ps.DiskUsage()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error getting disk usage info: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-10-08 21:17:04 +00:00
|
|
|
var restrictMpoints bool
|
2015-10-07 21:42:11 +00:00
|
|
|
mPoints := make(map[string]bool)
|
2015-10-08 21:17:04 +00:00
|
|
|
if len(s.Mountpoints) != 0 {
|
|
|
|
restrictMpoints = true
|
|
|
|
for _, mp := range s.Mountpoints {
|
|
|
|
mPoints[mp] = true
|
|
|
|
}
|
2015-10-07 21:42:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 23:01:42 +00:00
|
|
|
for _, du := range disks {
|
2015-10-08 21:17:04 +00:00
|
|
|
_, member := mPoints[du.Path]
|
|
|
|
if restrictMpoints && !member {
|
2015-10-07 21:42:11 +00:00
|
|
|
continue
|
|
|
|
}
|
2015-05-18 23:01:42 +00:00
|
|
|
tags := map[string]string{
|
2015-08-10 19:43:15 +00:00
|
|
|
"path": du.Path,
|
|
|
|
"fstype": du.Fstype,
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
acc.Add("total", du.Total, tags)
|
|
|
|
acc.Add("free", du.Free, tags)
|
|
|
|
acc.Add("used", du.Total-du.Free, tags)
|
2015-10-08 21:17:04 +00:00
|
|
|
acc.Add("inodes_total", du.InodesTotal, tags)
|
|
|
|
acc.Add("inodes_free", du.InodesFree, tags)
|
|
|
|
acc.Add("inodes_used", du.InodesTotal-du.InodesFree, tags)
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DiskIOStats struct {
|
|
|
|
ps PS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *DiskIOStats) Description() string {
|
|
|
|
return "Read metrics about disk IO by device"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *DiskIOStats) SampleConfig() string { return "" }
|
|
|
|
|
|
|
|
func (s *DiskIOStats) Gather(acc plugins.Accumulator) error {
|
|
|
|
diskio, err := s.ps.DiskIO()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error getting disk io info: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, io := range diskio {
|
2015-07-03 14:11:52 +00:00
|
|
|
tags := map[string]string{}
|
|
|
|
if len(io.Name) != 0 {
|
|
|
|
tags["name"] = io.Name
|
|
|
|
}
|
|
|
|
if len(io.SerialNumber) != 0 {
|
|
|
|
tags["serial"] = io.SerialNumber
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
acc.Add("reads", io.ReadCount, tags)
|
|
|
|
acc.Add("writes", io.WriteCount, tags)
|
|
|
|
acc.Add("read_bytes", io.ReadBytes, tags)
|
|
|
|
acc.Add("write_bytes", io.WriteBytes, tags)
|
|
|
|
acc.Add("read_time", io.ReadTime, tags)
|
|
|
|
acc.Add("write_time", io.WriteTime, tags)
|
|
|
|
acc.Add("io_time", io.IoTime, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
plugins.Add("disk", func() plugins.Plugin {
|
|
|
|
return &DiskStats{ps: &systemPS{}}
|
|
|
|
})
|
|
|
|
|
|
|
|
plugins.Add("io", func() plugins.Plugin {
|
|
|
|
return &DiskIOStats{ps: &systemPS{}}
|
|
|
|
})
|
|
|
|
}
|