Skip to content
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

Filter relative mounts in system filesystem metricset #4370

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d
- Fix a debug statement that said a module wrapper had stopped when it hadn't. {pull}4264[4264]
- Use MemAvailable value from /proc/meminfo on Linux 3.14. {pull}4316[4316]
- Fix panic when events were dropped by filters. {issue}4327[4327]
- Add filtering to system filesystem metricset to remove relative mountpoints like those
from Linux network namespaces. {pull}4370[4370]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
)

var debugf = logp.MakeDebug("system-filesystem")
var debugf = logp.MakeDebug("system.filesystem")

func init() {
if err := mb.Registry.AddMetricSet("system", "filesystem", New, parse.EmptyHostParser); err != nil {
Expand Down
48 changes: 14 additions & 34 deletions metricbeat/module/system/filesystem/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package filesystem

import (
"path/filepath"
"time"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/module/system"
sigar "github.com/elastic/gosigar"
)
Expand All @@ -20,13 +20,23 @@ type FileSystemStat struct {
}

func GetFileSystemList() ([]sigar.FileSystem, error) {

fss := sigar.FileSystemList{}
err := fss.Get()
if err != nil {
if err := fss.Get(); err != nil {
return nil, err
}

// Ignore relative mount points, which are present for example
// in /proc/mounts on Linux with network namespaces.
filtered := fss.List[:0]
for _, fs := range fss.List {
if filepath.IsAbs(fs.DirName) {
filtered = append(filtered, fs)
continue
}
debugf("Filtering filesystem with relative mountpoint %+v", fs)
}
fss.List = filtered

return fss.List, nil
}

Expand Down Expand Up @@ -54,26 +64,6 @@ func AddFileSystemUsedPercentage(f *FileSystemStat) {
f.UsedPercent = system.Round(perc, .5, 4)
}

func CollectFileSystemStats(fss []sigar.FileSystem) []common.MapStr {
events := make([]common.MapStr, 0, len(fss))
for _, fs := range fss {
fsStat, err := GetFileSystemStat(fs)
if err != nil {
logp.Debug("system", "Skip filesystem %d: %v", fsStat, err)
continue
}
AddFileSystemUsedPercentage(fsStat)

event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "filesystem",
"fs": GetFilesystemEvent(fsStat),
}
events = append(events, event)
}
return events
}

func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr {
return common.MapStr{
"device_name": fsStat.DevName,
Expand All @@ -89,13 +79,3 @@ func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr {
},
}
}

func GetFileSystemStats() ([]common.MapStr, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not used anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, not used anywhere.

fss, err := GetFileSystemList()
if err != nil {
logp.Warn("Getting filesystem list: %v", err)
return nil, err
}

return CollectFileSystemStats(fss), nil
}