2015-05-18 23:01:42 +00:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
"github.com/influxdb/telegraf/plugins/inputs"
|
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.
|
2015-11-05 01:21:42 +00:00
|
|
|
# Setting mountpoints will restrict the stats to the specified mountpoints.
|
2015-10-15 21:53:29 +00:00
|
|
|
# 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
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
func (s *DiskStats) Gather(acc inputs.Accumulator) error {
|
2015-05-18 23:01:42 +00:00
|
|
|
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
|
|
|
}
|
2015-12-11 20:07:32 +00:00
|
|
|
fields := map[string]interface{}{
|
|
|
|
"total": du.Total,
|
|
|
|
"free": du.Free,
|
|
|
|
"used": du.Total - du.Free,
|
|
|
|
"inodes_total": du.InodesTotal,
|
|
|
|
"inodes_free": du.InodesFree,
|
|
|
|
"inodes_used": du.InodesTotal - du.InodesFree,
|
|
|
|
}
|
|
|
|
acc.AddFields("disk", fields, tags)
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DiskIOStats struct {
|
|
|
|
ps PS
|
2015-11-05 01:21:42 +00:00
|
|
|
|
|
|
|
Devices []string
|
|
|
|
SkipSerialNumber bool
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *DiskIOStats) Description() string {
|
|
|
|
return "Read metrics about disk IO by device"
|
|
|
|
}
|
|
|
|
|
2015-11-05 01:21:42 +00:00
|
|
|
var diskIoSampleConfig = `
|
2015-12-02 19:44:16 +00:00
|
|
|
# By default, telegraf will gather stats for all devices including
|
2015-11-05 01:21:42 +00:00
|
|
|
# disk partitions.
|
|
|
|
# Setting devices will restrict the stats to the specified devcies.
|
2015-12-02 19:44:16 +00:00
|
|
|
# devices = ["sda","sdb"]
|
2015-11-05 01:21:42 +00:00
|
|
|
# Uncomment the following line if you do not need disk serial numbers.
|
2015-12-02 19:44:16 +00:00
|
|
|
# skip_serial_number = true
|
2015-11-05 01:21:42 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (_ *DiskIOStats) SampleConfig() string {
|
|
|
|
return diskIoSampleConfig
|
|
|
|
}
|
2015-05-18 23:01:42 +00:00
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
func (s *DiskIOStats) Gather(acc inputs.Accumulator) error {
|
2015-05-18 23:01:42 +00:00
|
|
|
diskio, err := s.ps.DiskIO()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error getting disk io info: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-11-05 01:21:42 +00:00
|
|
|
var restrictDevices bool
|
|
|
|
devices := make(map[string]bool)
|
|
|
|
if len(s.Devices) != 0 {
|
|
|
|
restrictDevices = true
|
|
|
|
for _, dev := range s.Devices {
|
|
|
|
devices[dev] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 23:01:42 +00:00
|
|
|
for _, io := range diskio {
|
2015-11-05 01:21:42 +00:00
|
|
|
_, member := devices[io.Name]
|
|
|
|
if restrictDevices && !member {
|
|
|
|
continue
|
|
|
|
}
|
2015-07-03 14:11:52 +00:00
|
|
|
tags := map[string]string{}
|
2015-12-02 19:44:16 +00:00
|
|
|
tags["name"] = io.Name
|
|
|
|
if !s.SkipSerialNumber {
|
|
|
|
if len(io.SerialNumber) != 0 {
|
|
|
|
tags["serial"] = io.SerialNumber
|
|
|
|
} else {
|
|
|
|
tags["serial"] = "unknown"
|
|
|
|
}
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 20:07:32 +00:00
|
|
|
fields := map[string]interface{}{
|
|
|
|
"reads": io.ReadCount,
|
|
|
|
"writes": io.WriteCount,
|
|
|
|
"read_bytes": io.ReadBytes,
|
|
|
|
"write_bytes": io.WriteBytes,
|
|
|
|
"read_time": io.ReadTime,
|
|
|
|
"write_time": io.WriteTime,
|
|
|
|
"io_time": io.IoTime,
|
|
|
|
}
|
|
|
|
acc.AddFields("diskio", fields, tags)
|
2015-05-18 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-01-07 20:39:43 +00:00
|
|
|
inputs.Add("disk", func() inputs.Input {
|
2015-05-18 23:01:42 +00:00
|
|
|
return &DiskStats{ps: &systemPS{}}
|
|
|
|
})
|
|
|
|
|
2016-01-07 20:39:43 +00:00
|
|
|
inputs.Add("diskio", func() inputs.Input {
|
2015-05-18 23:01:42 +00:00
|
|
|
return &DiskIOStats{ps: &systemPS{}}
|
|
|
|
})
|
|
|
|
}
|