mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-23 20:36:21 +01:00
properly strip path.rootfs from mountpoint labels (#1421)
Change-type: patch Connects-to: #1418 Signed-off-by: dt-rush <nickp@balena.io>
This commit is contained in:
parent
d8e47a9f9f
commit
5d3e2ce2ef
@ -17,6 +17,7 @@
|
||||
* [ENHANCEMENT] Include additional XFS runtime statistics. #1423
|
||||
* [BUGFIX] Renamed label `state` to `name` on `node_systemd_service_restart_total`. #1393
|
||||
* [BUGFIX] Fix netdev nil reference on Darwin #1414
|
||||
* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
|
||||
|
||||
## 0.18.1 / 2019-06-04
|
||||
|
||||
|
@ -69,7 +69,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||
stats = append(stats, filesystemStats{
|
||||
labels: filesystemLabels{
|
||||
device: device,
|
||||
mountPoint: mountpoint,
|
||||
mountPoint: rootfsStripPrefix(mountpoint),
|
||||
fsType: fstype,
|
||||
},
|
||||
size: float64(mnt[i].f_blocks) * float64(mnt[i].f_bsize),
|
||||
|
@ -73,7 +73,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
|
||||
stats = append(stats, filesystemStats{
|
||||
labels: filesystemLabels{
|
||||
device: device,
|
||||
mountPoint: mountpoint,
|
||||
mountPoint: rootfsStripPrefix(mountpoint),
|
||||
fsType: fstype,
|
||||
},
|
||||
size: float64(fs.Blocks) * float64(fs.Bsize),
|
||||
|
@ -165,7 +165,7 @@ func parseFilesystemLabels(r io.Reader) ([]filesystemLabels, error) {
|
||||
|
||||
filesystems = append(filesystems, filesystemLabels{
|
||||
device: parts[0],
|
||||
mountPoint: parts[1],
|
||||
mountPoint: rootfsStripPrefix(parts[1]),
|
||||
fsType: parts[2],
|
||||
options: parts[3],
|
||||
})
|
||||
|
@ -112,3 +112,30 @@ func TestMountsFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathRootfs(t *testing.T) {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "./fixtures_bindmount/proc", "--path.rootfs", "/host"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := map[string]string{
|
||||
// should modify these mountpoints (removes /host, see fixture proc file)
|
||||
"/media/volume1": "",
|
||||
"/media/volume2": "",
|
||||
// should not modify these mountpoints
|
||||
"/dev/shm": "",
|
||||
"/run/lock": "",
|
||||
"/sys/fs/cgroup": "",
|
||||
}
|
||||
|
||||
filesystems, err := mountPointDetails()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
for _, fs := range filesystems {
|
||||
if _, ok := expected[fs.mountPoint]; !ok {
|
||||
t.Errorf("Got unexpected %s", fs.mountPoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
collector/fixtures_bindmount/proc/mounts
Normal file
5
collector/fixtures_bindmount/proc/mounts
Normal file
@ -0,0 +1,5 @@
|
||||
/dev/nvme1n1 /host/media/volume1 ext4 rw,seclabel,relatime,data=ordered 0 0
|
||||
/dev/nvme1n2 /host/media/volume2 ext4 rw,seclabel,relatime,data=ordered 0 0
|
||||
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
|
||||
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
|
||||
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
|
@ -15,6 +15,7 @@ package collector
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
@ -38,3 +39,10 @@ func sysFilePath(name string) string {
|
||||
func rootfsFilePath(name string) string {
|
||||
return filepath.Join(*rootfsPath, name)
|
||||
}
|
||||
|
||||
func rootfsStripPrefix(path string) string {
|
||||
if *rootfsPath == "/" {
|
||||
return path
|
||||
}
|
||||
return strings.TrimPrefix(path, *rootfsPath)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user