@ -24,6 +24,12 @@ var (
ignoredMountPoints = flag . String ( "collector.filesystem.ignored-mount-points" , "^/(sys|proc|dev)($|/)" , "Regexp of mount points to ignore for filesystem collector." )
ignoredMountPoints = flag . String ( "collector.filesystem.ignored-mount-points" , "^/(sys|proc|dev)($|/)" , "Regexp of mount points to ignore for filesystem collector." )
)
)
type filesystemDetails struct {
device string
mountPoint string
fsType string
}
type filesystemCollector struct {
type filesystemCollector struct {
ignoredMountPointsPattern * regexp . Regexp
ignoredMountPointsPattern * regexp . Regexp
@ -37,7 +43,7 @@ func init() {
// Takes a prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// network device filesystems.
// network device filesystems.
func NewFilesystemCollector ( ) ( Collector , error ) {
func NewFilesystemCollector ( ) ( Collector , error ) {
var filesystemLabelNames = [ ] string { " filesystem"}
var filesystemLabelNames = [ ] string { " device", " filesystem", "fstype "}
return & filesystemCollector {
return & filesystemCollector {
ignoredMountPointsPattern : regexp . MustCompile ( * ignoredMountPoints ) ,
ignoredMountPointsPattern : regexp . MustCompile ( * ignoredMountPoints ) ,
@ -91,25 +97,26 @@ func NewFilesystemCollector() (Collector, error) {
// Expose filesystem fullness.
// Expose filesystem fullness.
func ( c * filesystemCollector ) Update ( ch chan <- prometheus . Metric ) ( err error ) {
func ( c * filesystemCollector ) Update ( ch chan <- prometheus . Metric ) ( err error ) {
mp s, err := mountPoint s( )
mp d s, err := mountPoint Detail s( )
if err != nil {
if err != nil {
return err
return err
}
}
for _ , mp := range mp s {
for _ , mp d := range mp d s {
if c . ignoredMountPointsPattern . MatchString ( mp ) {
if c . ignoredMountPointsPattern . MatchString ( mp d. mountPoint ) {
log . Debugf ( "Ignoring mount point: %s" , mp )
log . Debugf ( "Ignoring mount point: %s" , mp d. mountPoint )
continue
continue
}
}
buf := new ( syscall . Statfs_t )
buf := new ( syscall . Statfs_t )
err := syscall . Statfs ( mp , buf )
err := syscall . Statfs ( mp d. mountPoint , buf )
if err != nil {
if err != nil {
return fmt . Errorf ( "Statfs on %s returned %s" , mp , err )
return fmt . Errorf ( "Statfs on %s returned %s" , mp d. mountPoint , err )
}
}
c . size . WithLabelValues ( mp ) . Set ( float64 ( buf . Blocks ) * float64 ( buf . Bsize ) )
c . free . WithLabelValues ( mp ) . Set ( float64 ( buf . Bfree ) * float64 ( buf . Bsize ) )
c . size . WithLabelValues ( mpd . device , mpd . mountPoint , mpd . fsType ) . Set ( float64 ( buf . Blocks ) * float64 ( buf . Bsize ) )
c . avail . WithLabelValues ( mp ) . Set ( float64 ( buf . Bavail ) * float64 ( buf . Bsize ) )
c . free . WithLabelValues ( mpd . device , mpd . mountPoint , mpd . fsType ) . Set ( float64 ( buf . Bfree ) * float64 ( buf . Bsize ) )
c . files . WithLabelValues ( mp ) . Set ( float64 ( buf . Files ) )
c . avail . WithLabelValues ( mpd . device , mpd . mountPoint , mpd . fsType ) . Set ( float64 ( buf . Bavail ) * float64 ( buf . Bsize ) )
c . filesFree . WithLabelValues ( mp ) . Set ( float64 ( buf . Ffree ) )
c . files . WithLabelValues ( mpd . device , mpd . mountPoint , mpd . fsType ) . Set ( float64 ( buf . Files ) )
c . filesFree . WithLabelValues ( mpd . device , mpd . mountPoint , mpd . fsType ) . Set ( float64 ( buf . Ffree ) )
}
}
c . size . Collect ( ch )
c . size . Collect ( ch )
c . free . Collect ( ch )
c . free . Collect ( ch )
@ -119,18 +126,19 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
return err
return err
}
}
func mountPoint s( ) ( [ ] string , error ) {
func mountPoint Detail s( ) ( [ ] filesystemDetails , error ) {
file , err := os . Open ( procMounts )
file , err := os . Open ( procMounts )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
defer file . Close ( )
defer file . Close ( )
mountPoints := [ ] string { }
filesystems := [ ] filesystemDetails { }
scanner := bufio . NewScanner ( file )
scanner := bufio . NewScanner ( file )
for scanner . Scan ( ) {
for scanner . Scan ( ) {
parts := strings . Fields ( scanner . Text ( ) )
parts := strings . Fields ( scanner . Text ( ) )
mountPoints = append ( mountPoints , parts [ 1 ] )
filesystems = append ( filesystems , filesystemDetails { parts [ 0 ] , parts [ 1 ] , parts [ 2 ] } )
}
}
return mountPoint s, nil
return filesystem s, nil
}
}