Skip to content

Commit

Permalink
prometheus#219 - add fixes for @samzhang111 super token
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdan committed Nov 16, 2016
1 parent 8d756ca commit 1f6b5ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ node_load5 0.37
# HELP node_md_blocks Total number of blocks on device.
# TYPE node_md_blocks gauge
node_md_blocks{device="md0"} 248896
node_md_blocks{device="md00"} 4.186624e+06
node_md_blocks{device="md10"} 3.14159265e+08
node_md_blocks{device="md11"} 4.190208e+06
node_md_blocks{device="md12"} 3.886394368e+09
Expand All @@ -727,6 +728,7 @@ 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
node_md_blocks_synced{device="md00"} 4.186624e+06
node_md_blocks_synced{device="md10"} 3.14159265e+08
node_md_blocks_synced{device="md11"} 4.190208e+06
node_md_blocks_synced{device="md12"} 3.886394368e+09
Expand All @@ -741,6 +743,7 @@ 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
node_md_disks{device="md00"} 1
node_md_disks{device="md10"} 2
node_md_disks{device="md11"} 2
node_md_disks{device="md12"} 2
Expand All @@ -755,6 +758,7 @@ 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
node_md_disks_active{device="md00"} 1
node_md_disks_active{device="md10"} 2
node_md_disks_active{device="md11"} 2
node_md_disks_active{device="md12"} 2
Expand All @@ -769,6 +773,7 @@ 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
node_md_is_active{device="md00"} 1
node_md_is_active{device="md10"} 1
node_md_is_active{device="md11"} 1
node_md_is_active{device="md12"} 1
Expand Down
3 changes: 3 additions & 0 deletions collector/fixtures/proc/mdstat
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ md12 : active raid0 sdc2[0] sdd2[1]
md219 : inactive sdb[2](S) sdc[1](S) sda[0](S)
7932 blocks super external:imsm

md00 : active raid0 xvdb[0]
4186624 blocks super 1.2 256k chunks

unused devices: <none>
9 changes: 5 additions & 4 deletions collector/mdadm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
)

var (
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
raid0lineRE = regexp.MustCompile(`(\d+) blocks .*\d+k chunks`)
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
raid0lineRE = regexp.MustCompile(`(\d+) blocks( super ([0-9\.])*)? \d+k chunks`)
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
unknownPersonalityLine = regexp.MustCompile(`(\d+) blocks (.*)`)
raidPersonalityRE = regexp.MustCompile(`raid[0-9]+`)
)
Expand Down Expand Up @@ -82,7 +82,7 @@ func evalStatusline(statusline string) (active, total, size int64, err error) {
func evalRaid0line(statusline string) (size int64, err error) {
matches := raid0lineRE.FindStringSubmatch(statusline)

if len(matches) != 2 {
if len(matches) < 2 {
return 0, fmt.Errorf("invalid raid0 status line: %s", statusline)
}

Expand Down Expand Up @@ -179,6 +179,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
for _, possiblePersonality := range mainLine {
if raidPersonalityRE.MatchString(possiblePersonality) {
personality = possiblePersonality
// break
}
}

Expand Down
2 changes: 2 additions & 0 deletions collector/mdadm_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestMdadm(t *testing.T) {
}

refs := map[string]mdStatus{
// { "<name>", <active?>, <numDisksActive>, <totalNumDisks>, <amountSynced>, <totalSize>}
"md3": {"md3", true, 8, 8, 5853468288, 5853468288},
"md127": {"md127", true, 2, 2, 312319552, 312319552},
"md0": {"md0", true, 2, 2, 248896, 248896},
Expand All @@ -37,6 +38,7 @@ func TestMdadm(t *testing.T) {
"md11": {"md11", true, 2, 2, 4190208, 4190208},
"md12": {"md12", true, 2, 2, 3886394368, 3886394368},
"md219": {"md219", false, 2, 2, 7932, 7932},
"md00": {"md00", true, 1, 1, 4186624, 4186624},
}

for _, md := range mdStates {
Expand Down

0 comments on commit 1f6b5ae

Please sign in to comment.