Add disk io stats
This commit is contained in:
parent
065e094121
commit
250074eecf
|
@ -43,3 +43,11 @@ func (m *MockPS) NetIO() ([]net.NetIOCountersStat, error) {
|
||||||
|
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
func (m *MockPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
|
||||||
|
ret := m.Called()
|
||||||
|
|
||||||
|
r0 := ret.Get(0).(map[string]disk.DiskIOCountersStat)
|
||||||
|
r1 := ret.Error(1)
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdb/tivan/plugins"
|
"github.com/influxdb/tivan/plugins"
|
||||||
|
"github.com/influxdb/tivan/plugins/system/ps/common"
|
||||||
"github.com/influxdb/tivan/plugins/system/ps/cpu"
|
"github.com/influxdb/tivan/plugins/system/ps/cpu"
|
||||||
"github.com/influxdb/tivan/plugins/system/ps/disk"
|
"github.com/influxdb/tivan/plugins/system/ps/disk"
|
||||||
"github.com/influxdb/tivan/plugins/system/ps/load"
|
"github.com/influxdb/tivan/plugins/system/ps/load"
|
||||||
|
@ -15,6 +16,7 @@ type PS interface {
|
||||||
CPUTimes() ([]cpu.CPUTimesStat, error)
|
CPUTimes() ([]cpu.CPUTimesStat, error)
|
||||||
DiskUsage() ([]*disk.DiskUsageStat, error)
|
DiskUsage() ([]*disk.DiskUsageStat, error)
|
||||||
NetIO() ([]net.NetIOCountersStat, error)
|
NetIO() ([]net.NetIOCountersStat, error)
|
||||||
|
DiskIO() (map[string]disk.DiskIOCountersStat, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemStats struct {
|
type SystemStats struct {
|
||||||
|
@ -74,6 +76,26 @@ func (s *SystemStats) Gather(acc plugins.Accumulator) error {
|
||||||
acc.Add("inodes_used", du.InodesTotal-du.InodesFree, tags)
|
acc.Add("inodes_used", du.InodesTotal-du.InodesFree, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diskio, err := s.ps.DiskIO()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, io := range diskio {
|
||||||
|
tags := map[string]string{
|
||||||
|
"name": io.Name,
|
||||||
|
"serial": io.SerialNumber,
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
netio, err := s.ps.NetIO()
|
netio, err := s.ps.NetIO()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -131,6 +153,15 @@ func (s *systemPS) NetIO() ([]net.NetIOCountersStat, error) {
|
||||||
return net.NetIOCounters(true)
|
return net.NetIOCounters(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
|
||||||
|
m, err := disk.DiskIOCounters()
|
||||||
|
if err == common.NotImplementedError {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugins.Add("system", func() plugins.Plugin {
|
plugins.Add("system", func() plugins.Plugin {
|
||||||
return &SystemStats{ps: &systemPS{}}
|
return &SystemStats{ps: &systemPS{}}
|
||||||
|
|
|
@ -56,6 +56,20 @@ func TestSystemStats_GenerateStats(t *testing.T) {
|
||||||
|
|
||||||
mps.On("DiskUsage").Return([]*disk.DiskUsageStat{du}, nil)
|
mps.On("DiskUsage").Return([]*disk.DiskUsageStat{du}, nil)
|
||||||
|
|
||||||
|
diskio := disk.DiskIOCountersStat{
|
||||||
|
ReadCount: 888,
|
||||||
|
WriteCount: 5341,
|
||||||
|
ReadBytes: 100000,
|
||||||
|
WriteBytes: 200000,
|
||||||
|
ReadTime: 7123,
|
||||||
|
WriteTime: 9087,
|
||||||
|
Name: "sda1",
|
||||||
|
IoTime: 123552,
|
||||||
|
SerialNumber: "ab-123-ad",
|
||||||
|
}
|
||||||
|
|
||||||
|
mps.On("DiskIO").Return(map[string]disk.DiskIOCountersStat{"sda1": diskio}, nil)
|
||||||
|
|
||||||
netio := net.NetIOCountersStat{
|
netio := net.NetIOCountersStat{
|
||||||
Name: "eth0",
|
Name: "eth0",
|
||||||
BytesSent: 1123,
|
BytesSent: 1123,
|
||||||
|
@ -112,4 +126,17 @@ func TestSystemStats_GenerateStats(t *testing.T) {
|
||||||
assert.True(t, acc.CheckTaggedValue("err_out", uint64(8), ntags))
|
assert.True(t, acc.CheckTaggedValue("err_out", uint64(8), ntags))
|
||||||
assert.True(t, acc.CheckTaggedValue("drop_in", uint64(7), ntags))
|
assert.True(t, acc.CheckTaggedValue("drop_in", uint64(7), ntags))
|
||||||
assert.True(t, acc.CheckTaggedValue("drop_out", uint64(1), ntags))
|
assert.True(t, acc.CheckTaggedValue("drop_out", uint64(1), ntags))
|
||||||
|
|
||||||
|
dtags := map[string]string{
|
||||||
|
"name": "sda1",
|
||||||
|
"serial": "ab-123-ad",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.True(t, acc.CheckTaggedValue("reads", uint64(888), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("writes", uint64(5341), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("read_bytes", uint64(100000), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("write_bytes", uint64(200000), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("read_time", uint64(7123), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("write_time", uint64(9087), dtags))
|
||||||
|
assert.True(t, acc.CheckTaggedValue("io_time", uint64(123552), dtags))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue