aboutsummaryrefslogtreecommitdiff
path: root/collector/filesystem_linux.go
diff options
context:
space:
mode:
authorMartín Ferrari <tincho@debian.org>2015-09-15 12:17:15 +0000
committerMartín Ferrari <tincho@debian.org>2015-09-15 12:17:15 +0000
commit8c2316e8a9b4ee2fd702a6b4efbcc2b7264a3e1e (patch)
treeb80ee31c1a5df6ffdba4f3cf2bf06c6166515c47 /collector/filesystem_linux.go
parente180b882d6f623800567a4503748c2bfd5d7f6fd (diff)
downloadprometheus_node_collector-8c2316e8a9b4ee2fd702a6b4efbcc2b7264a3e1e.tar.bz2
prometheus_node_collector-8c2316e8a9b4ee2fd702a6b4efbcc2b7264a3e1e.tar.xz
prometheus_node_collector-8c2316e8a9b4ee2fd702a6b4efbcc2b7264a3e1e.zip
Revamp the filesystem collector to use throw-away ConstMetrics.
Diffstat (limited to 'collector/filesystem_linux.go')
-rw-r--r--collector/filesystem_linux.go146
1 files changed, 79 insertions, 67 deletions
diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go
index dc7724f..6c2929f 100644
--- a/collector/filesystem_linux.go
+++ b/collector/filesystem_linux.go
@@ -16,12 +16,15 @@ import (
16) 16)
17 17
18const ( 18const (
19 procMounts = "/proc/mounts" 19 procMounts = "/proc/mounts"
20 filesystemSubsystem = "filesystem" 20 subsystem = "filesystem"
21) 21)
22 22
23var ( 23var (
24 ignoredMountPoints = flag.String("collector.filesystem.ignored-mount-points", "^/(sys|proc|dev)($|/)", "Regexp of mount points to ignore for filesystem collector.") 24 ignoredMountPoints = flag.String(
25 "collector.filesystem.ignored-mount-points",
26 "^/(sys|proc|dev)($|/)",
27 "Regexp of mount points to ignore for filesystem collector.")
25) 28)
26 29
27type filesystemDetails struct { 30type filesystemDetails struct {
@@ -32,69 +35,53 @@ type filesystemDetails struct {
32 35
33type filesystemCollector struct { 36type filesystemCollector struct {
34 ignoredMountPointsPattern *regexp.Regexp 37 ignoredMountPointsPattern *regexp.Regexp
35
36 size, free, avail, files, filesFree *prometheus.GaugeVec
37} 38}
38 39
39func init() { 40func init() {
40 Factories["filesystem"] = NewFilesystemCollector 41 Factories["filesystem"] = NewFilesystemCollector
41} 42}
42 43
43// Takes a prometheus registry and returns a new Collector exposing
44// network device filesystems.
45func NewFilesystemCollector() (Collector, error) { 44func NewFilesystemCollector() (Collector, error) {
46 var filesystemLabelNames = []string{"device", "mountpoint", "fstype"} 45 pattern := regexp.MustCompile(*ignoredMountPoints)
47
48 return &filesystemCollector{ 46 return &filesystemCollector{
49 ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints), 47 ignoredMountPointsPattern: pattern,
50 size: prometheus.NewGaugeVec(
51 prometheus.GaugeOpts{
52 Namespace: Namespace,
53 Subsystem: filesystemSubsystem,
54 Name: "size",
55 Help: "Filesystem size in bytes.",
56 },
57 filesystemLabelNames,
58 ),
59 free: prometheus.NewGaugeVec(
60 prometheus.GaugeOpts{
61 Namespace: Namespace,
62 Subsystem: filesystemSubsystem,
63 Name: "free",
64 Help: "Filesystem free space in bytes.",
65 },
66 filesystemLabelNames,
67 ),
68 avail: prometheus.NewGaugeVec(
69 prometheus.GaugeOpts{
70 Namespace: Namespace,
71 Subsystem: filesystemSubsystem,
72 Name: "avail",
73 Help: "Filesystem space available to non-root users in bytes.",
74 },
75 filesystemLabelNames,
76 ),
77 files: prometheus.NewGaugeVec(
78 prometheus.GaugeOpts{
79 Namespace: Namespace,
80 Subsystem: filesystemSubsystem,
81 Name: "files",
82 Help: "Filesystem total file nodes.",
83 },
84 filesystemLabelNames,
85 ),
86 filesFree: prometheus.NewGaugeVec(
87 prometheus.GaugeOpts{
88 Namespace: Namespace,
89 Subsystem: filesystemSubsystem,
90 Name: "files_free",
91 Help: "Filesystem total free file nodes.",
92 },
93 filesystemLabelNames,
94 ),
95 }, nil 48 }, nil
96} 49}
97 50
51var (
52 filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
53
54 sizeDesc = prometheus.NewDesc(
55 prometheus.BuildFQName(Namespace, subsystem, "size"),
56 "Filesystem size in bytes.",
57 filesystemLabelNames, nil,
58 )
59
60 freeDesc = prometheus.NewDesc(
61 prometheus.BuildFQName(Namespace, subsystem, "free"),
62 "Filesystem free space in bytes.",
63 filesystemLabelNames, nil,
64 )
65
66 availDesc = prometheus.NewDesc(
67 prometheus.BuildFQName(Namespace, subsystem, "avail"),
68 "Filesystem space available to non-root users in bytes.",
69 filesystemLabelNames, nil,
70 )
71
72 filesDesc = prometheus.NewDesc(
73 prometheus.BuildFQName(Namespace, subsystem, "files"),
74 "Filesystem total file nodes.",
75 filesystemLabelNames, nil,
76 )
77
78 filesFreeDesc = prometheus.NewDesc(
79 prometheus.BuildFQName(Namespace, subsystem, "files_free"),
80 "Filesystem total free file nodes.",
81 filesystemLabelNames, nil,
82 )
83)
84
98// Expose filesystem fullness. 85// Expose filesystem fullness.
99func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) { 86func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
100 mpds, err := mountPointDetails() 87 mpds, err := mountPointDetails()
@@ -109,21 +96,46 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
109 buf := new(syscall.Statfs_t) 96 buf := new(syscall.Statfs_t)
110 err := syscall.Statfs(mpd.mountPoint, buf) 97 err := syscall.Statfs(mpd.mountPoint, buf)
111 if err != nil { 98 if err != nil {
112 return fmt.Errorf("Statfs on %s returned %s", mpd.mountPoint, err) 99 return fmt.Errorf("Statfs on %s returned %s",
100 mpd.mountPoint, err)
113 } 101 }
114 102
115 c.size.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Blocks) * float64(buf.Bsize)) 103 ch <- prometheus.MustNewConstMetric(
116 c.free.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Bfree) * float64(buf.Bsize)) 104 sizeDesc,
117 c.avail.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Bavail) * float64(buf.Bsize)) 105 prometheus.GaugeValue,
118 c.files.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Files)) 106 float64(buf.Blocks) * float64(buf.Bsize),
119 c.filesFree.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Ffree)) 107 mpd.device, mpd.mountPoint, mpd.fsType,
108 )
109
110 ch <- prometheus.MustNewConstMetric(
111 freeDesc,
112 prometheus.GaugeValue,
113 float64(buf.Bfree) * float64(buf.Bsize),
114 mpd.device, mpd.mountPoint, mpd.fsType,
115 )
116
117 ch <- prometheus.MustNewConstMetric(
118 availDesc,
119 prometheus.GaugeValue,
120 float64(buf.Bavail) * float64(buf.Bsize),
121 mpd.device, mpd.mountPoint, mpd.fsType,
122 )
123
124 ch <- prometheus.MustNewConstMetric(
125 filesDesc,
126 prometheus.GaugeValue,
127 float64(buf.Files),
128 mpd.device, mpd.mountPoint, mpd.fsType,
129 )
130
131 ch <- prometheus.MustNewConstMetric(
132 filesFreeDesc,
133 prometheus.GaugeValue,
134 float64(buf.Ffree),
135 mpd.device, mpd.mountPoint, mpd.fsType,
136 )
120 } 137 }
121 c.size.Collect(ch) 138 return nil
122 c.free.Collect(ch)
123 c.avail.Collect(ch)
124 c.files.Collect(ch)
125 c.filesFree.Collect(ch)
126 return err
127} 139}
128 140
129func mountPointDetails() ([]filesystemDetails, error) { 141func mountPointDetails() ([]filesystemDetails, error) {