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 ( const (
defIgnoredMountPoints = "^/(dev)($|/)" defIgnoredMountPoints = "^/(dev)($|/)"
defIgnoredFsTypes = "^devfs$"
MNT_RDONLY = 0x1 MNT_RDONLY = 0x1
) )
@ -55,6 +56,10 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
device := C.GoString(&mnt[i].f_mntfromname[0]) device := C.GoString(&mnt[i].f_mntfromname[0])
fstype := C.GoString(&mnt[i].f_fstypename[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 var ro float64
if (mnt[i].f_flags & MNT_RDONLY) != 0 { if (mnt[i].f_flags & MNT_RDONLY) != 0 {

View File

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

View File

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