From 64b82596ef2e99fac5fad43c596f1899096e7c9f Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Sun, 18 Sep 2016 08:17:00 +0200 Subject: [PATCH] Fix mdadm collector for resync=PENDING. Add fix for mdadm devices in state `resync=PENDING`. * Update test and fixture. --- collector/fixtures/e2e-output.txt | 5 +++++ collector/fixtures/proc/mdstat | 4 ++++ collector/mdadm_linux.go | 2 +- collector/mdadm_linux_test.go | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index a07ca3ad..9956940e 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -500,6 +500,7 @@ node_load5 0.37 # TYPE node_md_blocks gauge node_md_blocks{device="md0"} 248896 node_md_blocks{device="md10"} 3.14159265e+08 +node_md_blocks{device="md11"} 4.190208e+06 node_md_blocks{device="md127"} 3.12319552e+08 node_md_blocks{device="md3"} 5.853468288e+09 node_md_blocks{device="md4"} 4.883648e+06 @@ -511,6 +512,7 @@ node_md_blocks{device="md9"} 523968 # TYPE node_md_blocks_synced gauge node_md_blocks_synced{device="md0"} 248896 node_md_blocks_synced{device="md10"} 3.14159265e+08 +node_md_blocks_synced{device="md11"} 4.190208e+06 node_md_blocks_synced{device="md127"} 3.12319552e+08 node_md_blocks_synced{device="md3"} 5.853468288e+09 node_md_blocks_synced{device="md4"} 4.883648e+06 @@ -522,6 +524,7 @@ node_md_blocks_synced{device="md9"} 523968 # TYPE node_md_disks gauge node_md_disks{device="md0"} 2 node_md_disks{device="md10"} 2 +node_md_disks{device="md11"} 2 node_md_disks{device="md127"} 2 node_md_disks{device="md3"} 8 node_md_disks{device="md4"} 2 @@ -533,6 +536,7 @@ node_md_disks{device="md9"} 4 # TYPE node_md_disks_active gauge node_md_disks_active{device="md0"} 2 node_md_disks_active{device="md10"} 2 +node_md_disks_active{device="md11"} 2 node_md_disks_active{device="md127"} 2 node_md_disks_active{device="md3"} 8 node_md_disks_active{device="md4"} 2 @@ -544,6 +548,7 @@ node_md_disks_active{device="md9"} 4 # TYPE node_md_is_active gauge node_md_is_active{device="md0"} 1 node_md_is_active{device="md10"} 1 +node_md_is_active{device="md11"} 1 node_md_is_active{device="md127"} 1 node_md_is_active{device="md3"} 1 node_md_is_active{device="md4"} 0 diff --git a/collector/fixtures/proc/mdstat b/collector/fixtures/proc/mdstat index 8f01be7f..de5f121e 100644 --- a/collector/fixtures/proc/mdstat +++ b/collector/fixtures/proc/mdstat @@ -30,4 +30,8 @@ md9 : active raid1 sdc2[2] sdd2[3] sdb2[1] sda2[0] md10 : active raid0 sda1[0] sdb1[1] 314159265 blocks 64k chunks +md11 : active (auto-read-only) raid1 sdb2[0] sdc2[1] + 4190208 blocks super 1.2 [2/2] [UU] + resync=PENDING + unused devices: diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index 0a66066d..537d16fa 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go @@ -190,7 +190,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) { // If device is syncing at the moment, get the number of currently synced bytes, // otherwise that number equals the size of the device. - if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") && !strings.Contains(lines[j], "resync=DELAYED") { + if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") && !strings.Contains(lines[j], "resync=DELAYED") && !strings.Contains(lines[j], "resync=PENDING") { syncedBlocks, err = evalBuildline(lines[j]) if err != nil { return mdStates, fmt.Errorf("error parsing mdstat: %s", err) diff --git a/collector/mdadm_linux_test.go b/collector/mdadm_linux_test.go index ee74af03..9289576f 100644 --- a/collector/mdadm_linux_test.go +++ b/collector/mdadm_linux_test.go @@ -34,6 +34,7 @@ func TestMdadm(t *testing.T) { "md7": {"md7", true, 3, 4, 7813735424, 7813735424}, "md9": {"md9", true, 4, 4, 523968, 523968}, "md10": {"md10", true, 2, 2, 314159265, 314159265}, + "md11": {"md11", true, 2, 2, 4190208, 4190208}, } for _, md := range mdStates {