forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
filesystem.go
54 lines (44 loc) · 1.32 KB
/
filesystem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// +build darwin freebsd linux openbsd windows
package filesystem
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
"github.com/pkg/errors"
)
var debugf = logp.MakeDebug("system-filesystem")
func init() {
if err := mb.Registry.AddMetricSet("system", "filesystem", New, parse.EmptyHostParser); err != nil {
panic(err)
}
}
// MetricSet for fetching filesystem metrics.
type MetricSet struct {
mb.BaseMetricSet
}
// New creates and returns a new instance of MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{
BaseMetricSet: base,
}, nil
}
// Fetch fetches filesystem metrics for all mounted filesystems and returns
// an event for each mount point.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
fss, err := GetFileSystemList()
if err != nil {
return nil, errors.Wrap(err, "filesystem list")
}
filesSystems := make([]common.MapStr, 0, len(fss))
for _, fs := range fss {
fsStat, err := GetFileSystemStat(fs)
if err != nil {
debugf("error getting filesystem stats for '%s': %v", fs.DirName, err)
continue
}
AddFileSystemUsedPercentage(fsStat)
filesSystems = append(filesSystems, GetFilesystemEvent(fsStat))
}
return filesSystems, nil
}