-
Notifications
You must be signed in to change notification settings - Fork 305
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
Support parse raid type for mdstat #505
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ var ( | |
type MDStat struct { | ||
// Name of the device. | ||
Name string | ||
// raid type of the device. | ||
Type string | ||
// activity-state of the device. | ||
ActivityState string | ||
// Number of active disks. | ||
|
@@ -95,6 +97,13 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { | |
mdName := deviceFields[0] // mdx | ||
state := deviceFields[2] // active or inactive | ||
|
||
mdType := "unknown" | ||
if len(deviceFields) > 3 && isRaidType(deviceFields[3]) { | ||
mdType = deviceFields[3] // raid1, raid5, etc. | ||
} else if len(deviceFields) > 4 && isRaidType(deviceFields[4]) { | ||
mdType = deviceFields[4] | ||
} | ||
|
||
if len(lines) <= i+3 { | ||
return nil, fmt.Errorf("error parsing %q: too few lines for md device", mdName) | ||
} | ||
|
@@ -147,6 +156,7 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { | |
|
||
mdStats = append(mdStats, MDStat{ | ||
Name: mdName, | ||
Type: mdType, | ||
ActivityState: state, | ||
DisksActive: active, | ||
DisksFailed: fail, | ||
|
@@ -165,6 +175,10 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { | |
return mdStats, nil | ||
} | ||
|
||
func isRaidType(mdType string) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ewww hah.. |
||
return strings.HasPrefix(mdType, "raid") || mdType == "linear" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think this is going to work. Like I said, there are a whole bunch of other types other than |
||
} | ||
|
||
func evalStatusLine(deviceLine, statusLine string) (active, total, down, size int64, err error) { | ||
statusFields := strings.Fields(statusLine) | ||
if len(statusFields) < 1 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you move this to after
if len(lines) <= i+3 {
you can reduce the word checking to just the check for(...)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe this whole piece should be moved to the
evalStatusLine()
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len(lines) <= i+3
is the guard for lines not the fields in first line, so the move won't be helpful