Skip to content

Commit

Permalink
Filter relative mounts in system filesystem metricset
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 committed May 22, 2017
1 parent e66e185 commit 0169d56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 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
46 changes: 12 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,21 @@ 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)
}
}
fss.List = filtered

return fss.List, nil
}

Expand Down Expand Up @@ -54,26 +62,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 +77,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 0169d56

Please sign in to comment.