forked from prometheus/node_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request prometheus#117 from TheTincho/forget-old-filesystems
Revamp the filesystem collector to use throw-away ConstMetrics.
- Loading branch information
Showing
3 changed files
with
147 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// +build !nofilesystem | ||
// +build linux freebsd | ||
|
||
package collector | ||
|
||
import ( | ||
"flag" | ||
"regexp" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Arch-dependent implementation must define: | ||
// * defIgnoredMountPoints | ||
// * filesystemLabelNames | ||
// * filesystemCollector.GetStats | ||
|
||
var ( | ||
ignoredMountPoints = flag.String( | ||
"collector.filesystem.ignored-mount-points", | ||
defIgnoredMountPoints, | ||
"Regexp of mount points to ignore for filesystem collector.") | ||
) | ||
|
||
type filesystemCollector struct { | ||
ignoredMountPointsPattern *regexp.Regexp | ||
sizeDesc, freeDesc, availDesc, | ||
filesDesc, filesFreeDesc *prometheus.Desc | ||
} | ||
|
||
type filesystemStats struct { | ||
labelValues []string | ||
size, free, avail, files, filesFree float64 | ||
} | ||
|
||
func init() { | ||
Factories["filesystem"] = NewFilesystemCollector | ||
} | ||
|
||
// Takes a prometheus registry and returns a new Collector exposing | ||
// Filesystems stats. | ||
func NewFilesystemCollector() (Collector, error) { | ||
subsystem := "filesystem" | ||
pattern := regexp.MustCompile(*ignoredMountPoints) | ||
|
||
sizeDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, subsystem, "size"), | ||
"Filesystem size in bytes.", | ||
filesystemLabelNames, nil, | ||
) | ||
|
||
freeDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, subsystem, "free"), | ||
"Filesystem free space in bytes.", | ||
filesystemLabelNames, nil, | ||
) | ||
|
||
availDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, subsystem, "avail"), | ||
"Filesystem space available to non-root users in bytes.", | ||
filesystemLabelNames, nil, | ||
) | ||
|
||
filesDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, subsystem, "files"), | ||
"Filesystem total file nodes.", | ||
filesystemLabelNames, nil, | ||
) | ||
|
||
filesFreeDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, subsystem, "files_free"), | ||
"Filesystem total free file nodes.", | ||
filesystemLabelNames, nil, | ||
) | ||
|
||
return &filesystemCollector{ | ||
ignoredMountPointsPattern: pattern, | ||
sizeDesc: sizeDesc, | ||
freeDesc: freeDesc, | ||
availDesc: availDesc, | ||
filesDesc: filesDesc, | ||
filesFreeDesc: filesFreeDesc, | ||
}, nil | ||
} | ||
|
||
func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||
stats, err := c.GetStats() | ||
if err != nil { | ||
return err | ||
} | ||
for _, s := range stats { | ||
ch <- prometheus.MustNewConstMetric( | ||
c.sizeDesc, prometheus.GaugeValue, | ||
s.size, s.labelValues..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.freeDesc, prometheus.GaugeValue, | ||
s.free, s.labelValues..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.availDesc, prometheus.GaugeValue, | ||
s.avail, s.labelValues..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.filesDesc, prometheus.GaugeValue, | ||
s.files, s.labelValues..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.filesFreeDesc, prometheus.GaugeValue, | ||
s.filesFree, s.labelValues..., | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters