-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add system/raid metricset #5642
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-metricset-system-raid]] | ||
=== System raid metricset | ||
|
||
experimental[] | ||
|
||
include::../../../module/system/raid/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-system,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/system/raid/_meta/data.json[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"@timestamp": "2017-10-12T08:05:34.853Z", | ||
"beat": { | ||
"hostname": "host.example.com", | ||
"name": "host.example.com" | ||
}, | ||
"metricset": { | ||
"module": "system", | ||
"name": "raid", | ||
"rtt": 115 | ||
}, | ||
"system": { | ||
"raid": { | ||
"activity_state": "active", | ||
"blocks": { | ||
"synced": 5853468288, | ||
"total": 5853468288 | ||
}, | ||
"disks": { | ||
"active": 8, | ||
"total": 8 | ||
}, | ||
"name": "md3" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
=== system raid MetricSet | ||
|
||
This is the raid metricset of the module system. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
- name: raid | ||
type: group | ||
description: > | ||
raid | ||
release: experimental | ||
fields: | ||
- name: name | ||
type: keyword | ||
description: > | ||
Name of the device. | ||
- name: activity_state | ||
type: keyword | ||
description: > | ||
activity-state of the device. | ||
- name: disks.active | ||
type: long | ||
description: > | ||
Number of active disks. | ||
- name: disks.total | ||
type: long | ||
description: > | ||
Total number of disks the device consists of. | ||
- name: blocks.total | ||
type: long | ||
description: > | ||
Number of blocks the device holds. | ||
- name: blocks.synced | ||
type: long | ||
description: > | ||
Number of blocks on the device that are in sync. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Personalities : [raid0] [raid1] [linear] [multipath] [raid6] [raid5] [raid4] [raid10] | ||
md3 : active raid6 sda1[8] sdh1[7] sdg1[6] sdf1[5] sde1[11] sdd1[3] sdc1[10] sdb1[9] | ||
5853468288 blocks super 1.2 level 6, 64k chunk, algorithm 2 [8/8] [UUUUUUUU] | ||
|
||
md127 : active raid1 sdi2[0] sdj2[1] | ||
312319552 blocks [2/2] [UU] | ||
|
||
md0 : active raid1 sdk[2](S) sdi1[0] sdj1[1] | ||
248896 blocks [2/2] [UU] | ||
|
||
md4 : inactive raid1 sda3[0] sdb3[1] | ||
4883648 blocks [2/2] [UU] | ||
|
||
md6 : active raid1 sdb2[2] sda2[0] | ||
195310144 blocks [2/1] [U_] | ||
[=>...................] recovery = 8.5% (16775552/195310144) finish=17.0min speed=259783K/sec | ||
|
||
md8 : active raid1 sdb1[1] sda1[0] | ||
195310144 blocks [2/2] [UU] | ||
[=>...................] resync = 8.5% (16775552/195310144) finish=17.0min speed=259783K/sec | ||
|
||
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 | ||
|
||
unused devices: <none> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package raid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package raid | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/mb/parse" | ||
"github.com/elastic/beats/metricbeat/module/system" | ||
"github.com/elastic/procfs" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func init() { | ||
if err := mb.Registry.AddMetricSet("system", "raid", New, parse.EmptyHostParser); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// MetricSet contains proc fs data. | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
fs procfs.FS | ||
} | ||
|
||
// New creates a new instance of the raid metricset. | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
cfgwarn.Experimental("The system raid metricset is experimental") | ||
|
||
systemModule, ok := base.Module().(*system.Module) | ||
if !ok { | ||
return nil, errors.New("unexpected module type") | ||
} | ||
|
||
// Additional configuration options | ||
config := struct { | ||
MountPoint string `config:"raid.mount_point"` | ||
}{} | ||
|
||
if err := base.Module().UnpackConfig(&config); err != nil { | ||
return nil, err | ||
} | ||
|
||
if config.MountPoint == "" { | ||
config.MountPoint = systemModule.HostFS | ||
} | ||
|
||
mountPoint := filepath.Join(config.MountPoint, procfs.DefaultMountPoint) | ||
fs, err := procfs.NewFS(mountPoint) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
m := &MetricSet{ | ||
BaseMetricSet: base, | ||
fs: fs, | ||
} | ||
|
||
return m, nil | ||
} | ||
|
||
// Fetch fetches one event for each device | ||
func (m *MetricSet) Fetch() ([]common.MapStr, error) { | ||
|
||
stats, err := m.fs.ParseMDStat() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
events := make([]common.MapStr, 0, len(stats)) | ||
for _, stat := range stats { | ||
event := common.MapStr{ | ||
"name": stat.Name, | ||
"activity_state": stat.ActivityState, | ||
"disks": common.MapStr{ | ||
"active": stat.DisksActive, | ||
"total": stat.DisksTotal, | ||
}, | ||
"blocks": common.MapStr{ | ||
"synced": stat.BlocksSynced, | ||
"total": stat.BlocksTotal, | ||
}, | ||
} | ||
events = append(events, event) | ||
} | ||
|
||
return events, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package raid | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
mbtest "github.com/elastic/beats/metricbeat/mb/testing" | ||
) | ||
|
||
func TestData(t *testing.T) { | ||
f := mbtest.NewEventsFetcher(t, getConfig()) | ||
|
||
if err := mbtest.WriteEvents(f, t); err != nil { | ||
t.Fatal("write", err) | ||
} | ||
} | ||
|
||
func TestFetch(t *testing.T) { | ||
f := mbtest.NewEventsFetcher(t, getConfig()) | ||
data, err := f.Fetch() | ||
assert.NoError(t, err) | ||
assert.Equal(t, 7, len(data)) | ||
} | ||
|
||
func getConfig() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"module": "system", | ||
"metricsets": []string{"raid"}, | ||
"raid.mount_point": "./_meta/testdata", | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Usage question: How would I figure out how many available spares there are? Is
spares = total - active
? Or doestotal
include the number of failed disks still in the array?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.
@andrewkroh Based on https://raid.wiki.kernel.org/index.php/Mdstat I think what you state is correct.