collector: Make udev data path optional

Instead of hard-coding the path to `/run/udev/data`, intoduce a
`--path.udev.data` flag that defaults to that value.

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
This commit is contained in:
Benoît Knecht 2022-06-14 20:04:59 +02:00 committed by Johannes 'fish' Ziemke
parent 75ceda8bb2
commit 833216dc9e
2 changed files with 9 additions and 4 deletions

View file

@ -349,7 +349,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
}
func udevDeviceInformation(major, minor uint32) (udevInfo, error) {
filename := fmt.Sprintf("/run/udev/data/b%d:%d", major, minor)
filename := udevDataFilePath(fmt.Sprintf("b%d:%d", major, minor))
data, err := os.Open(filename)
if err != nil {

View file

@ -23,9 +23,10 @@ import (
var (
// The path of the proc filesystem.
procPath = kingpin.Flag("path.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
sysPath = kingpin.Flag("path.sysfs", "sysfs mountpoint.").Default("/sys").String()
rootfsPath = kingpin.Flag("path.rootfs", "rootfs mountpoint.").Default("/").String()
procPath = kingpin.Flag("path.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
sysPath = kingpin.Flag("path.sysfs", "sysfs mountpoint.").Default("/sys").String()
rootfsPath = kingpin.Flag("path.rootfs", "rootfs mountpoint.").Default("/").String()
udevDataPath = kingpin.Flag("path.udev.data", "udev data path.").Default("/run/udev/data").String()
)
func procFilePath(name string) string {
@ -40,6 +41,10 @@ func rootfsFilePath(name string) string {
return filepath.Join(*rootfsPath, name)
}
func udevDataFilePath(name string) string {
return filepath.Join(*udevDataPath, name)
}
func rootfsStripPrefix(path string) string {
if *rootfsPath == "/" {
return path