Rename `collector.filesystem` flags to match other collectors
Ref: #1743 Fixes: #1994 Signed-off-by: Frederic Hemberger <mail@frederic-hemberger.de>
This commit is contained in:
parent
1dfd858e4a
commit
39124626cd
|
@ -1,6 +1,6 @@
|
||||||
## master / unreleased
|
## master / unreleased
|
||||||
|
|
||||||
* [CHANGE]
|
* [CHANGE] Rename flags `collector.filesystem.ignored-mount-points` and `collector.filesystem.ignored-fs-types` to match other collectors
|
||||||
* [FEATURE]
|
* [FEATURE]
|
||||||
* [ENHANCEMENT]
|
* [ENHANCEMENT]
|
||||||
* [BUGFIX]
|
* [BUGFIX]
|
||||||
|
|
|
@ -32,9 +32,9 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(dev)($|/)"
|
defMountPointsExcluded = "^/(dev)($|/)"
|
||||||
defIgnoredFSTypes = "^devfs$"
|
defFSTypesExcluded = "^devfs$"
|
||||||
readOnly = 0x1 // MNT_RDONLY
|
readOnly = 0x1 // MNT_RDONLY
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose filesystem fullness.
|
// Expose filesystem fullness.
|
||||||
|
@ -49,14 +49,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
stats = []filesystemStats{}
|
stats = []filesystemStats{}
|
||||||
for i := 0; i < int(count); i++ {
|
for i := 0; i < int(count); i++ {
|
||||||
mountpoint := C.GoString(&mnt[i].f_mntonname[0])
|
mountpoint := C.GoString(&mnt[i].f_mntonname[0])
|
||||||
if c.ignoredMountPointsPattern.MatchString(mountpoint) {
|
if c.excludedMountPointsPattern.MatchString(mountpoint) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if c.excludedFSTypesPattern.MatchString(fstype) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
|
@ -26,27 +27,44 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Arch-dependent implementation must define:
|
// Arch-dependent implementation must define:
|
||||||
// * defIgnoredMountPoints
|
// * defMountPointsExcluded
|
||||||
// * defIgnoredFSTypes
|
// * defFSTypesExcluded
|
||||||
// * filesystemLabelNames
|
// * filesystemLabelNames
|
||||||
// * filesystemCollector.GetStats
|
// * filesystemCollector.GetStats
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ignoredMountPoints = kingpin.Flag(
|
mountPointsExcludeSet bool
|
||||||
|
mountPointsExclude = kingpin.Flag(
|
||||||
|
"collector.filesystem.mount-points-exclude",
|
||||||
|
"Regexp of mount points to exclude for filesystem collector.",
|
||||||
|
).Default(defMountPointsExcluded).PreAction(func(c *kingpin.ParseContext) error {
|
||||||
|
mountPointsExcludeSet = true
|
||||||
|
return nil
|
||||||
|
}).String()
|
||||||
|
oldMountPointsExcluded = kingpin.Flag(
|
||||||
"collector.filesystem.ignored-mount-points",
|
"collector.filesystem.ignored-mount-points",
|
||||||
"Regexp of mount points to ignore for filesystem collector.",
|
"Regexp of mount points to ignore for filesystem collector.",
|
||||||
).Default(defIgnoredMountPoints).String()
|
).Hidden().String()
|
||||||
ignoredFSTypes = kingpin.Flag(
|
|
||||||
|
fsTypesExcludeSet bool
|
||||||
|
fsTypesExclude = kingpin.Flag(
|
||||||
|
"collector.filesystem.fs-types-exclude",
|
||||||
|
"Regexp of filesystem types to exclude for filesystem collector.",
|
||||||
|
).Default(defFSTypesExcluded).PreAction(func(c *kingpin.ParseContext) error {
|
||||||
|
fsTypesExcludeSet = true
|
||||||
|
return nil
|
||||||
|
}).String()
|
||||||
|
oldFSTypesExcluded = kingpin.Flag(
|
||||||
"collector.filesystem.ignored-fs-types",
|
"collector.filesystem.ignored-fs-types",
|
||||||
"Regexp of filesystem types to ignore for filesystem collector.",
|
"Regexp of filesystem types to ignore for filesystem collector.",
|
||||||
).Default(defIgnoredFSTypes).String()
|
).Hidden().String()
|
||||||
|
|
||||||
filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
|
filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
|
||||||
)
|
)
|
||||||
|
|
||||||
type filesystemCollector struct {
|
type filesystemCollector struct {
|
||||||
ignoredMountPointsPattern *regexp.Regexp
|
excludedMountPointsPattern *regexp.Regexp
|
||||||
ignoredFSTypesPattern *regexp.Regexp
|
excludedFSTypesPattern *regexp.Regexp
|
||||||
sizeDesc, freeDesc, availDesc *prometheus.Desc
|
sizeDesc, freeDesc, availDesc *prometheus.Desc
|
||||||
filesDesc, filesFreeDesc *prometheus.Desc
|
filesDesc, filesFreeDesc *prometheus.Desc
|
||||||
roDesc, deviceErrorDesc *prometheus.Desc
|
roDesc, deviceErrorDesc *prometheus.Desc
|
||||||
|
@ -70,11 +88,29 @@ func init() {
|
||||||
|
|
||||||
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
|
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
|
||||||
func NewFilesystemCollector(logger log.Logger) (Collector, error) {
|
func NewFilesystemCollector(logger log.Logger) (Collector, error) {
|
||||||
|
if *oldMountPointsExcluded != "" {
|
||||||
|
if !mountPointsExcludeSet {
|
||||||
|
level.Warn(logger).Log("msg", "--collector.filesystem.ignored-mount-points is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.mount-points-exclude")
|
||||||
|
*mountPointsExclude = *oldMountPointsExcluded
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("--collector.filesystem.ignored-mount-points and --collector.filesystem.mount-points-exclude are mutually exclusive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if *oldFSTypesExcluded != "" {
|
||||||
|
if !fsTypesExcludeSet {
|
||||||
|
level.Warn(logger).Log("msg", "--collector.filesystem.ignored-fs-types is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.fs-types-exclude")
|
||||||
|
*fsTypesExclude = *oldFSTypesExcluded
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("--collector.filesystem.ignored-fs-types and --collector.filesystem.fs-types-exclude are mutually exclusive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
subsystem := "filesystem"
|
subsystem := "filesystem"
|
||||||
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.ignored-mount-points", "flag", *ignoredMountPoints)
|
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.mount-points-exclude", "flag", *mountPointsExclude)
|
||||||
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
|
mountPointPattern := regexp.MustCompile(*mountPointsExclude)
|
||||||
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.ignored-fs-types", "flag", *ignoredFSTypes)
|
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *fsTypesExclude)
|
||||||
filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes)
|
filesystemsTypesPattern := regexp.MustCompile(*fsTypesExclude)
|
||||||
|
|
||||||
sizeDesc := prometheus.NewDesc(
|
sizeDesc := prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, subsystem, "size_bytes"),
|
prometheus.BuildFQName(namespace, subsystem, "size_bytes"),
|
||||||
|
@ -119,16 +155,16 @@ func NewFilesystemCollector(logger log.Logger) (Collector, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
return &filesystemCollector{
|
return &filesystemCollector{
|
||||||
ignoredMountPointsPattern: mountPointPattern,
|
excludedMountPointsPattern: mountPointPattern,
|
||||||
ignoredFSTypesPattern: filesystemsTypesPattern,
|
excludedFSTypesPattern: filesystemsTypesPattern,
|
||||||
sizeDesc: sizeDesc,
|
sizeDesc: sizeDesc,
|
||||||
freeDesc: freeDesc,
|
freeDesc: freeDesc,
|
||||||
availDesc: availDesc,
|
availDesc: availDesc,
|
||||||
filesDesc: filesDesc,
|
filesDesc: filesDesc,
|
||||||
filesFreeDesc: filesFreeDesc,
|
filesFreeDesc: filesFreeDesc,
|
||||||
roDesc: roDesc,
|
roDesc: roDesc,
|
||||||
deviceErrorDesc: deviceErrorDesc,
|
deviceErrorDesc: deviceErrorDesc,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(dev)($|/)"
|
defMountPointsExcluded = "^/(dev)($|/)"
|
||||||
defIgnoredFSTypes = "^devfs$"
|
defFSTypesExcluded = "^devfs$"
|
||||||
readOnly = 0x1 // MNT_RDONLY
|
readOnly = 0x1 // MNT_RDONLY
|
||||||
noWait = 0x2 // MNT_NOWAIT
|
noWait = 0x2 // MNT_NOWAIT
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose filesystem fullness.
|
// Expose filesystem fullness.
|
||||||
|
@ -41,14 +41,14 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
|
||||||
stats := []filesystemStats{}
|
stats := []filesystemStats{}
|
||||||
for _, fs := range buf {
|
for _, fs := range buf {
|
||||||
mountpoint := bytesToString(fs.Mntonname[:])
|
mountpoint := bytesToString(fs.Mntonname[:])
|
||||||
if c.ignoredMountPointsPattern.MatchString(mountpoint) {
|
if c.excludedMountPointsPattern.MatchString(mountpoint) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
device := bytesToString(fs.Mntfromname[:])
|
device := bytesToString(fs.Mntfromname[:])
|
||||||
fstype := bytesToString(fs.Fstypename[:])
|
fstype := bytesToString(fs.Fstypename[:])
|
||||||
if c.ignoredFSTypesPattern.MatchString(fstype) {
|
if c.excludedFSTypesPattern.MatchString(fstype) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(dev|proc|sys|var/lib/docker/.+)($|/)"
|
defMountPointsExcluded = "^/(dev|proc|sys|var/lib/docker/.+)($|/)"
|
||||||
defIgnoredFSTypes = "^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$"
|
defFSTypesExcluded = "^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mountTimeout = kingpin.Flag("collector.filesystem.mount-timeout",
|
var mountTimeout = kingpin.Flag("collector.filesystem.mount-timeout",
|
||||||
|
@ -50,11 +50,11 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
|
||||||
}
|
}
|
||||||
stats := []filesystemStats{}
|
stats := []filesystemStats{}
|
||||||
for _, labels := range mps {
|
for _, labels := range mps {
|
||||||
if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) {
|
if c.excludedMountPointsPattern.MatchString(labels.mountPoint) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", labels.mountPoint)
|
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", labels.mountPoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c.ignoredFSTypesPattern.MatchString(labels.fsType) {
|
if c.excludedFSTypesPattern.MatchString(labels.fsType) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring fs", "type", labels.fsType)
|
level.Debug(c.logger).Log("msg", "Ignoring fs", "type", labels.fsType)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(dev)($|/)"
|
defMountPointsExcluded = "^/(dev)($|/)"
|
||||||
defIgnoredFSTypes = "^devfs$"
|
defFSTypesExcluded = "^devfs$"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose filesystem fullness.
|
// Expose filesystem fullness.
|
||||||
|
@ -42,14 +42,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
stats = []filesystemStats{}
|
stats = []filesystemStats{}
|
||||||
for _, v := range mnt {
|
for _, v := range mnt {
|
||||||
mountpoint := int8ToString(v.F_mntonname[:])
|
mountpoint := int8ToString(v.F_mntonname[:])
|
||||||
if c.ignoredMountPointsPattern.MatchString(mountpoint) {
|
if c.excludedMountPointsPattern.MatchString(mountpoint) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
device := int8ToString(v.F_mntfromname[:])
|
device := int8ToString(v.F_mntfromname[:])
|
||||||
fstype := int8ToString(v.F_fstypename[:])
|
fstype := int8ToString(v.F_fstypename[:])
|
||||||
if c.ignoredFSTypesPattern.MatchString(fstype) {
|
if c.excludedFSTypesPattern.MatchString(fstype) {
|
||||||
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue