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 ( | ||||
| 	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 | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue