From deebf0aa4922e158000988a4514ef939ea9a3fa5 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Mon, 19 Dec 2016 11:48:32 +0100 Subject: [PATCH] Add node_filesystem_device_errors_total metric This metric is the total number of errors occurred when getting stats for the given device. --- collector/filesystem_common.go | 8 ++++++++ collector/filesystem_linux.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index cdca1883..30e2b8a6 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -48,6 +48,7 @@ type filesystemCollector struct { ignoredFSTypesPattern *regexp.Regexp sizeDesc, freeDesc, availDesc, filesDesc, filesFreeDesc, roDesc *prometheus.Desc + devErrors *prometheus.CounterVec } type filesystemStats struct { @@ -102,6 +103,11 @@ func NewFilesystemCollector() (Collector, error) { filesystemLabelNames, nil, ) + devErrors := prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: prometheus.BuildFQName(Namespace, subsystem, "device_errors_total"), + Help: "Total number of errors occurred when getting stats for device", + }, filesystemLabelNames) + return &filesystemCollector{ ignoredMountPointsPattern: mountPointPattern, ignoredFSTypesPattern: filesystemsTypesPattern, @@ -111,6 +117,7 @@ func NewFilesystemCollector() (Collector, error) { filesDesc: filesDesc, filesFreeDesc: filesFreeDesc, roDesc: roDesc, + devErrors: devErrors, }, nil } @@ -145,5 +152,6 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) { s.ro, s.labelValues..., ) } + c.devErrors.Collect(ch) return nil } diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index ceb99fa7..9e0cff0f 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -52,9 +52,11 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { log.Debugf("Ignoring fs type: %s", mpd.fsType) continue } + labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType} buf := new(syscall.Statfs_t) err := syscall.Statfs(mpd.mountPoint, buf) if err != nil { + c.devErrors.WithLabelValues(labelValues...).Inc() log.Debugf("Statfs on %s returned %s", mpd.mountPoint, err) continue @@ -65,7 +67,6 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { ro = 1 } - labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType} stats = append(stats, filesystemStats{ labelValues: labelValues, size: float64(buf.Blocks) * float64(buf.Bsize),