Source File
mdstat.go
Belonging Package
github.com/prometheus/procfs
package procfs
import (
)
var (
statusLineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
recoveryLineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
)
func ( []byte) ([]MDStat, error) {
:= []MDStat{}
:= strings.Split(string(), "\n")
for , := range {
if strings.TrimSpace() == "" || [0] == ' ' ||
strings.HasPrefix(, "Personalities") ||
strings.HasPrefix(, "unused") {
continue
}
:= strings.Fields()
if len() < 3 {
return nil, fmt.Errorf("not enough fields in mdline (expected at least 3): %s", )
}
:= [0] // mdx
:= [2] // active or inactive
if len() <= +3 {
return nil, fmt.Errorf(
"error parsing %s: too few lines for md device",
,
)
}
if || {
if {
= "recovering"
} else {
= "resyncing"
}
if strings.Contains([], "PENDING") ||
strings.Contains([], "DELAYED") {
= 0
} else {
, = evalRecoveryLine([])
if != nil {
return nil, fmt.Errorf("error parsing sync line in md device %s: %s", , )
}
}
}
= append(, MDStat{
Name: ,
ActivityState: ,
DisksActive: ,
DisksFailed: ,
DisksSpare: ,
DisksTotal: ,
BlocksTotal: ,
BlocksSynced: ,
})
}
return , nil
}
func (, string) (, , int64, error) {
:= strings.Fields()[0]
, = strconv.ParseInt(, 10, 64)
if != nil {
return 0, 0, 0, fmt.Errorf("unexpected statusLine %s: %s", , )
}
= int64(strings.Count(, "["))
return , , , nil
}
if strings.Contains(, "inactive") {
return 0, 0, , nil
}
:= statusLineRE.FindStringSubmatch()
if len() != 4 {
return 0, 0, 0, fmt.Errorf("couldn't find all the substring matches: %s", )
}
, = strconv.ParseInt([2], 10, 64)
if != nil {
return 0, 0, 0, fmt.Errorf("unexpected statusLine %s: %s", , )
}
, = strconv.ParseInt([3], 10, 64)
if != nil {
return 0, 0, 0, fmt.Errorf("unexpected statusLine %s: %s", , )
}
return , , , nil
}
func ( string) ( int64, error) {
:= recoveryLineRE.FindStringSubmatch()
if len() != 2 {
return 0, fmt.Errorf("unexpected recoveryLine: %s", )
}
, = strconv.ParseInt([1], 10, 64)
if != nil {
return 0, fmt.Errorf("%s in recoveryLine: %s", , )
}
return , nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |