Skip to content

Commit

Permalink
Filter relative mounts in system filesystem metricset (#4370)
Browse files Browse the repository at this point in the history
Add filtering to system filesystem metricset to remove relative mountpoints like those from Linux network namespaces.
  • Loading branch information
andrewkroh authored and ruflin committed May 22, 2017
1 parent a3054ae commit e39b347
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
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) {
fss, err := GetFileSystemList()
if err != nil {
logp.Warn("Getting filesystem list: %v", err)
return nil, err
}

return CollectFileSystemStats(fss), nil
}

0 comments on commit e39b347

Please sign in to comment.