Add flag to change the location of the procfs.

Remove all hardcoded references to `/proc`. For all collectors that do
not use `github.com/prometheus/procfs` yet, provide a wrapper to
generate the full paths.

Reformulate help strings, errors and comments to remove absolute
references to `/proc`.

This is a breaking change: the `-collector.ipvs.procfs` flag is removed
in favor of the general flag. Since it only affected that collector it
was only useful for development, so this should not cause many issues.
This commit is contained in:
Matthias Rampke 2015-09-26 14:53:46 +02:00
commit 20b551ab2b
15 changed files with 57 additions and 67 deletions

View file

@ -4,6 +4,7 @@ package collector
import (
"bufio"
"errors"
"fmt"
"io"
"os"
@ -13,10 +14,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
const (
procInterrupts = "/proc/interrupts"
)
type interruptsCollector struct {
metric *prometheus.CounterVec
}
@ -33,7 +30,7 @@ func NewInterruptsCollector() (Collector, error) {
prometheus.CounterOpts{
Namespace: Namespace,
Name: "interrupts",
Help: "Interrupt details from /proc/interrupts.",
Help: "Interrupt details.",
},
[]string{"CPU", "type", "info", "devices"},
),
@ -71,7 +68,7 @@ type interrupt struct {
}
func getInterrupts() (map[string]interrupt, error) {
file, err := os.Open(procInterrupts)
file, err := os.Open(procFilePath("interrupts"))
if err != nil {
return nil, err
}
@ -87,7 +84,7 @@ func parseInterrupts(r io.Reader) (map[string]interrupt, error) {
)
if !scanner.Scan() {
return nil, fmt.Errorf("%s empty", procInterrupts)
return nil, errors.New("interrupts empty")
}
cpuNum := len(strings.Fields(string(scanner.Text()))) // one header per cpu