diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index 6aefb015..9daa8995 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go @@ -33,6 +33,7 @@ import "C" const ( defIgnoredMountPoints = "^/(dev)($|/)" + MNT_RDONLY = 0x1 ) // Expose filesystem fullness. @@ -55,6 +56,11 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { device := C.GoString(&mnt[i].f_mntfromname[0]) fstype := C.GoString(&mnt[i].f_fstypename[0]) + var ro float64 + if mnt[i].f_flags & MNT_RDONLY { + ro = 1 + } + labelValues := []string{device, mountpoint, fstype} stats = append(stats, filesystemStats{ labelValues: labelValues, @@ -63,6 +69,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { avail: float64(mnt[i].f_bavail) * float64(mnt[i].f_bsize), files: float64(mnt[i].f_files), filesFree: float64(mnt[i].f_ffree), + ro: ro, }) } return stats, nil diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index 35536951..b92f2123 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -40,12 +40,12 @@ var ( type filesystemCollector struct { ignoredMountPointsPattern *regexp.Regexp sizeDesc, freeDesc, availDesc, - filesDesc, filesFreeDesc *prometheus.Desc + filesDesc, filesFreeDesc, roDesc *prometheus.Desc } type filesystemStats struct { - labelValues []string - size, free, avail, files, filesFree float64 + labelValues []string + size, free, avail, files, filesFree, ro float64 } func init() { @@ -88,6 +88,12 @@ func NewFilesystemCollector() (Collector, error) { filesystemLabelNames, nil, ) + roDesc := prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "readonly"), + "Filesystem read-only status.", + filesystemLabelNames, nil, + ) + return &filesystemCollector{ ignoredMountPointsPattern: pattern, sizeDesc: sizeDesc, @@ -95,6 +101,7 @@ func NewFilesystemCollector() (Collector, error) { availDesc: availDesc, filesDesc: filesDesc, filesFreeDesc: filesFreeDesc, + roDesc: roDesc, }, nil } @@ -124,6 +131,10 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) { c.filesFreeDesc, prometheus.GaugeValue, s.filesFree, s.labelValues..., ) + ch <- prometheus.MustNewConstMetric( + c.roDesc, prometheus.GaugeValue, + s.ro, s.labelValues..., + ) } return nil } diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 847cc5c6..7fafcfb2 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -26,6 +26,7 @@ import ( const ( defIgnoredMountPoints = "^/(sys|proc|dev)($|/)" + ST_RDONLY = 0x1 ) type filesystemDetails struct { @@ -54,6 +55,11 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { continue } + var ro float64 + if buf.Flags & ST_RDONLY != 0 { + ro = 1 + } + labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType} stats = append(stats, filesystemStats{ labelValues: labelValues, @@ -62,6 +68,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { avail: float64(buf.Bavail) * float64(buf.Bsize), files: float64(buf.Files), filesFree: float64(buf.Ffree), + ro: ro, }) } return stats, nil