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

Add device name as a tag in disk stats #1807

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update system/disk tests to include new partition stat return value f…
…rom disk usage method calls
  • Loading branch information
mediocretes committed Sep 28, 2016
commit c5889275b3eaac60c7f310e4281f2385b7be2433
32 changes: 29 additions & 3 deletions plugins/inputs/system/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,33 @@ func TestDiskStats(t *testing.T) {
},
}

mps.On("DiskUsage", []string(nil), []string(nil)).Return(duAll, nil)
mps.On("DiskUsage", []string{"/", "/dev"}, []string(nil)).Return(duFiltered, nil)
mps.On("DiskUsage", []string{"/", "/home"}, []string(nil)).Return(duAll, nil)
psAll := []*disk.PartitionStat{
{
Device: "/dev/sda",
Mountpoint: "/",
Fstype: "ext4",
Opts: "",
},
{
Device: "/dev/sdb",
Mountpoint: "/home",
Fstype: "ext4",
Opts: "",
},
}

psFiltered := []*disk.PartitionStat{
{
Device: "/dev/sda",
Mountpoint: "/",
Fstype: "ext4",
Opts: "",
},
}

mps.On("DiskUsage", []string(nil), []string(nil)).Return(duAll, psAll, nil)
mps.On("DiskUsage", []string{"/", "/dev"}, []string(nil)).Return(duFiltered, psFiltered, nil)
mps.On("DiskUsage", []string{"/", "/home"}, []string(nil)).Return(duAll, psAll, nil)

err = (&DiskStats{ps: &mps}).Gather(&acc)
require.NoError(t, err)
Expand All @@ -64,10 +88,12 @@ func TestDiskStats(t *testing.T) {
tags1 := map[string]string{
"path": "/",
"fstype": "ext4",
"device": "sda",
}
tags2 := map[string]string{
"path": "/home",
"fstype": "ext4",
"device": "sdb",
}

fields1 := map[string]interface{}{
Expand Down
7 changes: 4 additions & 3 deletions plugins/inputs/system/mock_PS.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ func (m *MockPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
return r0, r1
}

func (m *MockPS) DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, error) {
func (m *MockPS) DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
ret := m.Called(mountPointFilter, fstypeExclude)

r0 := ret.Get(0).([]*disk.UsageStat)
r1 := ret.Error(1)
r1 := ret.Get(1).([]*disk.PartitionStat)
r2 := ret.Error(2)

return r0, r1
return r0, r1, r2
}

func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
Expand Down