diff options
author | dt-rush <nick.eightfold.hunter@gmail.com> | 2019-07-19 14:51:17 +0000 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2019-07-19 16:51:17 +0200 |
commit | 5d3e2ce2ef927eeb44fc409d3cd1fbba884571f3 (patch) | |
tree | 759e318512762f4b461c6f5c3a2313f3e853af59 /collector | |
parent | d8e47a9f9fb9bc3e8101c4bc6e8bd8c7a30663f5 (diff) | |
download | prometheus_node_collector-5d3e2ce2ef927eeb44fc409d3cd1fbba884571f3.tar.bz2 prometheus_node_collector-5d3e2ce2ef927eeb44fc409d3cd1fbba884571f3.tar.xz prometheus_node_collector-5d3e2ce2ef927eeb44fc409d3cd1fbba884571f3.zip |
properly strip path.rootfs from mountpoint labels (#1421)
Change-type: patch
Connects-to: #1418
Signed-off-by: dt-rush <nickp@balena.io>
Diffstat (limited to 'collector')
-rw-r--r-- | collector/filesystem_bsd.go | 2 | ||||
-rw-r--r-- | collector/filesystem_freebsd.go | 2 | ||||
-rw-r--r-- | collector/filesystem_linux.go | 2 | ||||
-rw-r--r-- | collector/filesystem_linux_test.go | 27 | ||||
-rw-r--r-- | collector/fixtures_bindmount/proc/mounts | 5 | ||||
-rw-r--r-- | collector/paths.go | 8 |
6 files changed, 43 insertions, 3 deletions
diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index 9f20ec0..b9aa1cc 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go | |||
@@ -69,7 +69,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { | |||
69 | stats = append(stats, filesystemStats{ | 69 | stats = append(stats, filesystemStats{ |
70 | labels: filesystemLabels{ | 70 | labels: filesystemLabels{ |
71 | device: device, | 71 | device: device, |
72 | mountPoint: mountpoint, | 72 | mountPoint: rootfsStripPrefix(mountpoint), |
73 | fsType: fstype, | 73 | fsType: fstype, |
74 | }, | 74 | }, |
75 | size: float64(mnt[i].f_blocks) * float64(mnt[i].f_bsize), | 75 | size: float64(mnt[i].f_blocks) * float64(mnt[i].f_bsize), |
diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index 4df17d7..47c4833 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go | |||
@@ -73,7 +73,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
73 | stats = append(stats, filesystemStats{ | 73 | stats = append(stats, filesystemStats{ |
74 | labels: filesystemLabels{ | 74 | labels: filesystemLabels{ |
75 | device: device, | 75 | device: device, |
76 | mountPoint: mountpoint, | 76 | mountPoint: rootfsStripPrefix(mountpoint), |
77 | fsType: fstype, | 77 | fsType: fstype, |
78 | }, | 78 | }, |
79 | size: float64(fs.Blocks) * float64(fs.Bsize), | 79 | size: float64(fs.Blocks) * float64(fs.Bsize), |
diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index f76aeaa..5ba4fe1 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go | |||
@@ -165,7 +165,7 @@ func parseFilesystemLabels(r io.Reader) ([]filesystemLabels, error) { | |||
165 | 165 | ||
166 | filesystems = append(filesystems, filesystemLabels{ | 166 | filesystems = append(filesystems, filesystemLabels{ |
167 | device: parts[0], | 167 | device: parts[0], |
168 | mountPoint: parts[1], | 168 | mountPoint: rootfsStripPrefix(parts[1]), |
169 | fsType: parts[2], | 169 | fsType: parts[2], |
170 | options: parts[3], | 170 | options: parts[3], |
171 | }) | 171 | }) |
diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index ebc6659..267ad06 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go | |||
@@ -112,3 +112,30 @@ func TestMountsFallback(t *testing.T) { | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | } | 114 | } |
115 | |||
116 | func TestPathRootfs(t *testing.T) { | ||
117 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "./fixtures_bindmount/proc", "--path.rootfs", "/host"}); err != nil { | ||
118 | t.Fatal(err) | ||
119 | } | ||
120 | |||
121 | expected := map[string]string{ | ||
122 | // should modify these mountpoints (removes /host, see fixture proc file) | ||
123 | "/media/volume1": "", | ||
124 | "/media/volume2": "", | ||
125 | // should not modify these mountpoints | ||
126 | "/dev/shm": "", | ||
127 | "/run/lock": "", | ||
128 | "/sys/fs/cgroup": "", | ||
129 | } | ||
130 | |||
131 | filesystems, err := mountPointDetails() | ||
132 | if err != nil { | ||
133 | t.Log(err) | ||
134 | } | ||
135 | |||
136 | for _, fs := range filesystems { | ||
137 | if _, ok := expected[fs.mountPoint]; !ok { | ||
138 | t.Errorf("Got unexpected %s", fs.mountPoint) | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/collector/fixtures_bindmount/proc/mounts b/collector/fixtures_bindmount/proc/mounts new file mode 100644 index 0000000..2ef6401 --- /dev/null +++ b/collector/fixtures_bindmount/proc/mounts | |||
@@ -0,0 +1,5 @@ | |||
1 | /dev/nvme1n1 /host/media/volume1 ext4 rw,seclabel,relatime,data=ordered 0 0 | ||
2 | /dev/nvme1n2 /host/media/volume2 ext4 rw,seclabel,relatime,data=ordered 0 0 | ||
3 | tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 | ||
4 | tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0 | ||
5 | tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0 | ||
diff --git a/collector/paths.go b/collector/paths.go index 5057f75..6150600 100644 --- a/collector/paths.go +++ b/collector/paths.go | |||
@@ -15,6 +15,7 @@ package collector | |||
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "path/filepath" | 17 | "path/filepath" |
18 | "strings" | ||
18 | 19 | ||
19 | "github.com/prometheus/procfs" | 20 | "github.com/prometheus/procfs" |
20 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 21 | kingpin "gopkg.in/alecthomas/kingpin.v2" |
@@ -38,3 +39,10 @@ func sysFilePath(name string) string { | |||
38 | func rootfsFilePath(name string) string { | 39 | func rootfsFilePath(name string) string { |
39 | return filepath.Join(*rootfsPath, name) | 40 | return filepath.Join(*rootfsPath, name) |
40 | } | 41 | } |
42 | |||
43 | func rootfsStripPrefix(path string) string { | ||
44 | if *rootfsPath == "/" { | ||
45 | return path | ||
46 | } | ||
47 | return strings.TrimPrefix(path, *rootfsPath) | ||
48 | } | ||