mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	Add filesystem read-only metric node_filesystem_readonly
This is a boolean metric which is set to 1 when the filesystem is flagged as read-only.
This commit is contained in:
		
							parent
							
								
									7eb7917eea
								
							
						
					
					
						commit
						05539ee156
					
				|  | @ -33,6 +33,7 @@ import "C" | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	defIgnoredMountPoints = "^/(dev)($|/)" | 	defIgnoredMountPoints = "^/(dev)($|/)" | ||||||
|  | 	MNT_RDONLY            = 0x1 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Expose filesystem fullness.
 | // Expose filesystem fullness.
 | ||||||
|  | @ -55,6 +56,11 @@ 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]) | ||||||
| 
 | 
 | ||||||
|  | 		var ro float64 | ||||||
|  | 		if mnt[i].f_flags & MNT_RDONLY { | ||||||
|  | 			ro = 1 | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		labelValues := []string{device, mountpoint, fstype} | 		labelValues := []string{device, mountpoint, fstype} | ||||||
| 		stats = append(stats, filesystemStats{ | 		stats = append(stats, filesystemStats{ | ||||||
| 			labelValues: labelValues, | 			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), | 			avail:       float64(mnt[i].f_bavail) * float64(mnt[i].f_bsize), | ||||||
| 			files:       float64(mnt[i].f_files), | 			files:       float64(mnt[i].f_files), | ||||||
| 			filesFree:   float64(mnt[i].f_ffree), | 			filesFree:   float64(mnt[i].f_ffree), | ||||||
|  | 			ro:          ro, | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return stats, nil | 	return stats, nil | ||||||
|  |  | ||||||
|  | @ -40,12 +40,12 @@ var ( | ||||||
| type filesystemCollector struct { | type filesystemCollector struct { | ||||||
| 	ignoredMountPointsPattern *regexp.Regexp | 	ignoredMountPointsPattern *regexp.Regexp | ||||||
| 	sizeDesc, freeDesc, availDesc, | 	sizeDesc, freeDesc, availDesc, | ||||||
| 	filesDesc, filesFreeDesc *prometheus.Desc | 	filesDesc, filesFreeDesc, roDesc *prometheus.Desc | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type filesystemStats struct { | type filesystemStats struct { | ||||||
| 	labelValues                         []string | 	labelValues                             []string | ||||||
| 	size, free, avail, files, filesFree float64 | 	size, free, avail, files, filesFree, ro float64 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
|  | @ -88,6 +88,12 @@ func NewFilesystemCollector() (Collector, error) { | ||||||
| 		filesystemLabelNames, nil, | 		filesystemLabelNames, nil, | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
|  | 	roDesc := prometheus.NewDesc( | ||||||
|  | 		prometheus.BuildFQName(Namespace, subsystem, "readonly"), | ||||||
|  | 		"Filesystem read-only status.", | ||||||
|  | 		filesystemLabelNames, nil, | ||||||
|  | 	) | ||||||
|  | 
 | ||||||
| 	return &filesystemCollector{ | 	return &filesystemCollector{ | ||||||
| 		ignoredMountPointsPattern: pattern, | 		ignoredMountPointsPattern: pattern, | ||||||
| 		sizeDesc:                  sizeDesc, | 		sizeDesc:                  sizeDesc, | ||||||
|  | @ -95,6 +101,7 @@ func NewFilesystemCollector() (Collector, error) { | ||||||
| 		availDesc:                 availDesc, | 		availDesc:                 availDesc, | ||||||
| 		filesDesc:                 filesDesc, | 		filesDesc:                 filesDesc, | ||||||
| 		filesFreeDesc:             filesFreeDesc, | 		filesFreeDesc:             filesFreeDesc, | ||||||
|  | 		roDesc:                    roDesc, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -124,6 +131,10 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||||||
| 			c.filesFreeDesc, prometheus.GaugeValue, | 			c.filesFreeDesc, prometheus.GaugeValue, | ||||||
| 			s.filesFree, s.labelValues..., | 			s.filesFree, s.labelValues..., | ||||||
| 		) | 		) | ||||||
|  | 		ch <- prometheus.MustNewConstMetric( | ||||||
|  | 			c.roDesc, prometheus.GaugeValue, | ||||||
|  | 			s.ro, s.labelValues..., | ||||||
|  | 		) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -26,6 +26,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	defIgnoredMountPoints = "^/(sys|proc|dev)($|/)" | 	defIgnoredMountPoints = "^/(sys|proc|dev)($|/)" | ||||||
|  | 	ST_RDONLY             = 0x1 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type filesystemDetails struct { | type filesystemDetails struct { | ||||||
|  | @ -54,6 +55,11 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		var ro float64 | ||||||
|  | 		if buf.Flags & ST_RDONLY != 0 { | ||||||
|  | 			ro = 1 | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType} | 		labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType} | ||||||
| 		stats = append(stats, filesystemStats{ | 		stats = append(stats, filesystemStats{ | ||||||
| 			labelValues: labelValues, | 			labelValues: labelValues, | ||||||
|  | @ -62,6 +68,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { | ||||||
| 			avail:       float64(buf.Bavail) * float64(buf.Bsize), | 			avail:       float64(buf.Bavail) * float64(buf.Bsize), | ||||||
| 			files:       float64(buf.Files), | 			files:       float64(buf.Files), | ||||||
| 			filesFree:   float64(buf.Ffree), | 			filesFree:   float64(buf.Ffree), | ||||||
|  | 			ro:          ro, | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return stats, nil | 	return stats, nil | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue