Skip to content

Commit

Permalink
Move RO status before error return
Browse files Browse the repository at this point in the history
Signed-off-by: Metbog <metbog@gmail.com>
  • Loading branch information
metbog committed Sep 19, 2023
1 parent f34aaa6 commit 9ec9172
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 5 additions & 4 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
c.deviceErrorDesc, prometheus.GaugeValue,
s.deviceError, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
ch <- prometheus.MustNewConstMetric(
c.roDesc, prometheus.GaugeValue,
s.ro, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)

if s.deviceError > 0 {
continue
}
Expand All @@ -210,10 +215,6 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
c.filesFreeDesc, prometheus.GaugeValue,
s.filesFree, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
ch <- prometheus.MustNewConstMetric(
c.roDesc, prometheus.GaugeValue,
s.ro, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
}
return nil
}
16 changes: 9 additions & 7 deletions collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,23 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta
}
stuckMountsMtx.Unlock()

var ro float64
for _, option := range strings.Split(labels.options, ",") {
if option == "ro" {
ro = 1
break
}
}

if err != nil {
level.Debug(c.logger).Log("msg", "Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err)
return filesystemStats{
labels: labels,
deviceError: 1,
ro: ro,
}
}

var ro float64
for _, option := range strings.Split(labels.options, ",") {
if option == "ro" {
ro = 1
break
}
}
return filesystemStats{
labels: labels,
size: float64(buf.Blocks) * float64(buf.Bsize),
Expand Down

0 comments on commit 9ec9172

Please sign in to comment.