Add ignored fs types

This commit is contained in:
Dominik Schulz 2016-03-15 14:01:08 +01:00 committed by Sharif Nassar
parent df8dcd27e2
commit 3fe5e7f8fa
3 changed files with 21 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import "C"
const (
defIgnoredMountPoints = "^/(dev)($|/)"
defIgnoredFsTypes = "^devfs$"
MNT_RDONLY = 0x1
)
@ -55,6 +56,10 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
device := C.GoString(&mnt[i].f_mntfromname[0])
fstype := C.GoString(&mnt[i].f_fstypename[0])
if c.ignoredFsTypesPattern.MatchString(fstype) {
log.Debugf("Ignoring fs type: %s", fstype)
continue
}
var ro float64
if (mnt[i].f_flags & MNT_RDONLY) != 0 {

View File

@ -25,6 +25,7 @@ import (
// Arch-dependent implementation must define:
// * defIgnoredMountPoints
// * defIgnoredFsTypes
// * filesystemLabelNames
// * filesystemCollector.GetStats
@ -34,11 +35,17 @@ var (
defIgnoredMountPoints,
"Regexp of mount points to ignore for filesystem collector.")
ignoredFsTypes = flag.String(
"collector.filesystem.ignored-fs-types",
defIgnoredFsTypes,
"Regexp of filesystem types to ignore for filesystem collector.")
filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
)
type filesystemCollector struct {
ignoredMountPointsPattern *regexp.Regexp
ignoredFsTypesPattern *regexp.Regexp
sizeDesc, freeDesc, availDesc,
filesDesc, filesFreeDesc, roDesc *prometheus.Desc
}
@ -56,7 +63,8 @@ func init() {
// Filesystems stats.
func NewFilesystemCollector() (Collector, error) {
subsystem := "filesystem"
pattern := regexp.MustCompile(*ignoredMountPoints)
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
fsTypePatter := regexp.MustCompile(*ignoredFsTypes)
sizeDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "size"),
@ -95,7 +103,8 @@ func NewFilesystemCollector() (Collector, error) {
)
return &filesystemCollector{
ignoredMountPointsPattern: pattern,
ignoredMountPointsPattern: mountPointPattern,
ignoredFsTypesPattern: fsTypesPattern,
sizeDesc: sizeDesc,
freeDesc: freeDesc,
availDesc: availDesc,

View File

@ -26,6 +26,7 @@ import (
const (
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
defIgnoredFsTypes = "^(sys|proc)fs$"
ST_RDONLY = 0x1
)
@ -47,6 +48,10 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
log.Debugf("Ignoring mount point: %s", mpd.mountPoint)
continue
}
if c.ignoredFsTypesPatter.MatchString(mpd.fsType) {
log.Debugf("Ignoring fs type: %s", mpd.fsType)
continue
}
buf := new(syscall.Statfs_t)
err := syscall.Statfs(mpd.mountPoint, buf)
if err != nil {