forked from mackerelio/mackerel-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem.go
47 lines (39 loc) · 1.23 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
// +build windows
package windows
import (
"regexp"
"github.com/mackerelio/golib/logging"
"github.com/mackerelio/mackerel-agent/metrics"
"github.com/mackerelio/mackerel-agent/util"
"github.com/mackerelio/mackerel-agent/util/windows"
)
// FilesystemGenerator XXX
type FilesystemGenerator struct {
IgnoreRegexp *regexp.Regexp
}
// NewFilesystemGenerator XXX
func NewFilesystemGenerator(ignoreReg *regexp.Regexp) (*FilesystemGenerator, error) {
return &FilesystemGenerator{IgnoreRegexp: ignoreReg}, nil
}
var logger = logging.GetLogger("metrics.filesystem")
var driveLetterReg = regexp.MustCompile(`^(.*):`)
// Generate the metrics of filesystems
func (g *FilesystemGenerator) Generate() (metrics.Values, error) {
filesystems, err := windows.CollectFilesystemValues()
if err != nil {
return nil, err
}
ret := metrics.Values{}
for name, values := range filesystems {
if g.IgnoreRegexp != nil && g.IgnoreRegexp.MatchString(name) {
continue
}
if matches := driveLetterReg.FindStringSubmatch(name); matches != nil {
device := util.SanitizeMetricKey(matches[1])
ret["filesystem."+device+".size"] = values.KbSize * 1024
ret["filesystem."+device+".used"] = values.KbUsed * 1024
}
}
logger.Debugf("%q", ret)
return ret, nil
}