From 00e1db52bb4733253e126b0536bd22d25bbed1a0 Mon Sep 17 00:00:00 2001 From: afefelov Date: Tue, 24 Nov 2015 14:42:56 +0500 Subject: [PATCH] Fix mdstat for devices in delayed resync state In some raid configurations resync will be delayed for devices allocated on the same physiclal units. Fixes #170. --- collector/fixtures/e2e-output.txt | 5 +++++ collector/fixtures/proc/mdstat | 5 +++++ collector/mdadm.go | 2 +- collector/mdadm_test.go | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 20bf834a..94b9b547 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -462,6 +462,7 @@ node_md_blocks{device="md4"} 4.883648e+06 node_md_blocks{device="md6"} 1.95310144e+08 node_md_blocks{device="md7"} 7.813735424e+09 node_md_blocks{device="md8"} 1.95310144e+08 +node_md_blocks{device="md9"} 523968 # HELP node_md_blocks_synced Number of blocks synced on device. # TYPE node_md_blocks_synced gauge node_md_blocks_synced{device="md0"} 248896 @@ -471,6 +472,7 @@ node_md_blocks_synced{device="md4"} 4.883648e+06 node_md_blocks_synced{device="md6"} 1.6775552e+07 node_md_blocks_synced{device="md7"} 7.813735424e+09 node_md_blocks_synced{device="md8"} 1.6775552e+07 +node_md_blocks_synced{device="md9"} 523968 # HELP node_md_disks Total number of disks of device. # TYPE node_md_disks gauge node_md_disks{device="md0"} 2 @@ -480,6 +482,7 @@ node_md_disks{device="md4"} 2 node_md_disks{device="md6"} 2 node_md_disks{device="md7"} 4 node_md_disks{device="md8"} 2 +node_md_disks{device="md9"} 4 # HELP node_md_disks_active Number of active disks of device. # TYPE node_md_disks_active gauge node_md_disks_active{device="md0"} 2 @@ -489,6 +492,7 @@ node_md_disks_active{device="md4"} 2 node_md_disks_active{device="md6"} 1 node_md_disks_active{device="md7"} 3 node_md_disks_active{device="md8"} 2 +node_md_disks_active{device="md9"} 4 # HELP node_md_is_active Indicator whether the md-device is active or not. # TYPE node_md_is_active gauge node_md_is_active{device="md0"} 1 @@ -498,6 +502,7 @@ node_md_is_active{device="md4"} 0 node_md_is_active{device="md6"} 1 node_md_is_active{device="md7"} 1 node_md_is_active{device="md8"} 1 +node_md_is_active{device="md9"} 1 # HELP node_megacli_drive_count megacli: drive error and event counters # TYPE node_megacli_drive_count counter node_megacli_drive_count{enclosure="32",slot="0",type="Media Error Count"} 0 diff --git a/collector/fixtures/proc/mdstat b/collector/fixtures/proc/mdstat index da5c691c..b17f3fb2 100644 --- a/collector/fixtures/proc/mdstat +++ b/collector/fixtures/proc/mdstat @@ -23,4 +23,9 @@ md7 : active raid6 sdb1[0] sde1[3] sdd1[2] sdc1[1] 7813735424 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/3] [U_UU] bitmap: 0/30 pages [0KB], 65536KB chunk +md9 : active raid1 sdc2[2] sdd2[3] sdb2[1] sda2[0] + 523968 blocks super 1.2 [4/4] [UUUU] + resync=DELAYED + + unused devices: diff --git a/collector/mdadm.go b/collector/mdadm.go index aa6a739d..d13f4de4 100644 --- a/collector/mdadm.go +++ b/collector/mdadm.go @@ -162,7 +162,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") { + if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") && ! strings.Contains(lines[j], "resync=DELAYED") { syncedBlocks, err = evalBuildline(lines[j]) if err != nil { return mdStates, fmt.Errorf("error parsing mdstat: %s", err) diff --git a/collector/mdadm_test.go b/collector/mdadm_test.go index 7a90364a..120dc6d1 100644 --- a/collector/mdadm_test.go +++ b/collector/mdadm_test.go @@ -32,6 +32,7 @@ func TestMdadm(t *testing.T) { "md6": {"md6", true, 1, 2, 195310144, 16775552}, "md8": {"md8", true, 2, 2, 195310144, 16775552}, "md7": {"md7", true, 3, 4, 7813735424, 7813735424}, + "md9": {"md9", true, 4, 4, 523968, 523968}, } for _, md := range mdStates {