mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-01-20 07:19:01 +01:00
Remove unnecessarily named return variables
Named return variables should only be used to describe the returned type further, e.g. `err error` doesn't add any new information and is just stutter.
This commit is contained in:
parent
084e585c2a
commit
922e74d58f
@ -51,7 +51,7 @@ func NewBondingCollector() (Collector, error) {
|
||||
}
|
||||
|
||||
// Update reads and exposes bonding states, implements Collector interface. Caution: This works only on linux.
|
||||
func (c *bondingCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
bondingStats, err := readBondingStats(sysFilePath("class/net"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -49,7 +49,7 @@ func NewBuddyinfoCollector() (Collector, error) {
|
||||
|
||||
// Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific
|
||||
// buddyinfo metrics.
|
||||
func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open procfs: %v", err)
|
||||
|
@ -32,7 +32,7 @@ func warnDeprecated(collector string) {
|
||||
// Collector is the interface a collector has to implement.
|
||||
type Collector interface {
|
||||
// Get new metrics and expose them via prometheus registry.
|
||||
Update(ch chan<- prometheus.Metric) (err error)
|
||||
Update(ch chan<- prometheus.Metric) error
|
||||
}
|
||||
|
||||
type typedDesc struct {
|
||||
|
@ -44,7 +44,7 @@ func NewConntrackCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
value, err := readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_count"))
|
||||
if err != nil {
|
||||
// Conntrack probably not loaded into the kernel.
|
||||
|
@ -107,7 +107,7 @@ func NewStatCollector() (Collector, error) {
|
||||
}
|
||||
|
||||
// Expose CPU stats using sysctl.
|
||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
// We want time spent per-cpu per CPUSTATE.
|
||||
// CPUSTATES (number of CPUSTATES) is defined as 5U.
|
||||
// Order: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR
|
||||
|
@ -155,7 +155,7 @@ func newDRBDCollector() (Collector, error) {
|
||||
return &drbdCollector{}, nil
|
||||
}
|
||||
|
||||
func (c *drbdCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
statsFile := procFilePath("drbd")
|
||||
file, err := os.Open(statsFile)
|
||||
if err != nil {
|
||||
|
@ -78,7 +78,7 @@ func NewEdacCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *edacCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *edacCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
memControllers, err := filepath.Glob(sysFilePath("devices/system/edac/mc/mc[0-9]*"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -40,7 +40,7 @@ func NewEntropyCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *entropyCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
value, err := readUintFromFile(procFilePath("sys/kernel/random/entropy_avail"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get entropy_avail: %s", err)
|
||||
|
@ -124,7 +124,7 @@ func NewFilesystemCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
stats, err := c.GetStats()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -40,7 +40,7 @@ func gostring(b []int8) string {
|
||||
}
|
||||
|
||||
// Expose filesystem fullness.
|
||||
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||
func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
|
||||
buf := make([]unix.Statfs_t, 16)
|
||||
for {
|
||||
n, err := unix.Getfsstat(buf, noWait)
|
||||
@ -53,7 +53,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||
}
|
||||
buf = make([]unix.Statfs_t, len(buf)*2)
|
||||
}
|
||||
stats = []filesystemStats{}
|
||||
stats := []filesystemStats{}
|
||||
for _, fs := range buf {
|
||||
mountpoint := gostring(fs.Mntonname[:])
|
||||
if c.ignoredMountPointsPattern.MatchString(mountpoint) {
|
||||
|
@ -31,12 +31,12 @@ const (
|
||||
)
|
||||
|
||||
// GetStats returns filesystem stats.
|
||||
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||
func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
|
||||
mps, err := mountPointDetails()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stats = []filesystemStats{}
|
||||
stats := []filesystemStats{}
|
||||
for _, labels := range mps {
|
||||
if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) {
|
||||
log.Debugf("Ignoring mount point: %s", labels.mountPoint)
|
||||
|
@ -56,7 +56,7 @@ func NewGmondCollector() (Collector, error) {
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
conn, err := net.Dial(gangliaProto, gangliaAddress)
|
||||
log.Debugf("gmondCollector Update")
|
||||
if err != nil {
|
||||
|
@ -20,7 +20,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func splitToInts(str string, sep string) (ints []int, err error) {
|
||||
func splitToInts(str, sep string) ([]int, error) {
|
||||
var ints []int
|
||||
for _, part := range strings.Split(str, sep) {
|
||||
i, err := strconv.Atoi(part)
|
||||
if err != nil {
|
||||
|
@ -392,7 +392,7 @@ func (c *hwMonCollector) hwmonHumanReadableChipName(dir string) (string, error)
|
||||
return "", errors.New("Could not derive a human-readable chip type for " + dir)
|
||||
}
|
||||
|
||||
func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
// Step 1: scan /sys/class/hwmon, resolve all symlinks and call
|
||||
// updatesHwmon for each folder
|
||||
|
||||
|
@ -128,7 +128,7 @@ func readMetric(directory, metricFile string) (uint64, error) {
|
||||
return metric, nil
|
||||
}
|
||||
|
||||
func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
devices, err := infinibandDevices(sysFilePath(infinibandPath))
|
||||
|
||||
// If no devices are found or another error is raised while attempting to find devices,
|
||||
|
@ -60,7 +60,7 @@ func NewKsmdCollector() (Collector, error) {
|
||||
}
|
||||
|
||||
// Update implements Collector and exposes kernel and system statistics.
|
||||
func (c *ksmdCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *ksmdCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
for _, n := range ksmdFiles {
|
||||
val, err := readUintFromFile(sysFilePath(path.Join("kernel/mm/ksm", n)))
|
||||
if err != nil {
|
||||
|
@ -42,7 +42,7 @@ func NewLoadavgCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
loads, err := getLoad()
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get load: %s", err)
|
||||
|
@ -274,17 +274,15 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
statusfile := procFilePath("mdstat")
|
||||
// take care we don't crash on non-existent statusfiles
|
||||
_, err = os.Stat(statusfile)
|
||||
if os.IsNotExist(err) {
|
||||
// no such file or directory, nothing to do, just return
|
||||
log.Debugf("Not collecting mdstat, file does not exist: %s", statusfile)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil { // now things get weird, better to return
|
||||
if _, err := os.Stat(statusfile); err != nil {
|
||||
// Take care we don't crash on non-existent statusfiles.
|
||||
if os.IsNotExist(err) {
|
||||
// no such file or directory, nothing to do, just return
|
||||
log.Debugf("Not collecting mdstat, file does not exist: %s", statusfile)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -71,16 +71,17 @@ func NewMegaCliCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *megaCliCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
err = c.updateAdapter()
|
||||
if err != nil {
|
||||
func (c *megaCliCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
if err := c.updateAdapter(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.updateDisks(); err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.updateDisks()
|
||||
c.driveTemperature.Collect(ch)
|
||||
c.driveCounters.Collect(ch)
|
||||
c.drivePresence.Collect(ch)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseMegaCliDisks(r io.Reader) (map[int]map[int]map[string]string, error) {
|
||||
|
@ -40,7 +40,7 @@ func NewMeminfoCollector() (Collector, error) {
|
||||
|
||||
// Update calls (*meminfoCollector).getMemInfo to get the platform specific
|
||||
// memory metrics.
|
||||
func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
memInfo, err := c.getMemInfo()
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get meminfo: %s", err)
|
||||
|
@ -57,7 +57,7 @@ func NewMeminfoNumaCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
metrics, err := getMemInfoNuma()
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get NUMA meminfo: %s", err)
|
||||
|
@ -51,7 +51,7 @@ func NewNetDevCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *netDevCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
netDev, err := getNetDevStats(c.ignoredDevicesPattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get netstats: %s", err)
|
||||
|
@ -42,7 +42,7 @@ func NewNetStatCollector() (Collector, error) {
|
||||
return &netStatCollector{}, nil
|
||||
}
|
||||
|
||||
func (c *netStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
netStats, err := getNetStats(procFilePath("net/netstat"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get netstats: %s", err)
|
||||
|
@ -116,12 +116,12 @@ func NewNfsCollector() (Collector, error) {
|
||||
return &nfsCollector{}, nil
|
||||
}
|
||||
|
||||
func (c *nfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
statsFile := procFilePath("net/rpc/nfs")
|
||||
content, err := ioutil.ReadFile(statsFile)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Debugf("Not collecting NFS statistics, as %s does not exist: %s", statsFile)
|
||||
log.Debugf("Not collecting NFS statistics, as %q does not exist", statsFile)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -62,7 +62,7 @@ func NewNtpCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *ntpCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
resp, err := ntp.Query(*ntpServer, *ntpProtocolVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get NTP drift: %s", err)
|
||||
|
@ -44,7 +44,7 @@ func NewSockStatCollector() (Collector, error) {
|
||||
return &sockStatCollector{}, nil
|
||||
}
|
||||
|
||||
func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
sockStats, err := getSockStats(procFilePath("net/sockstat"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get sockstats: %s", err)
|
||||
|
@ -84,7 +84,7 @@ func NewStatCollector() (Collector, error) {
|
||||
}
|
||||
|
||||
// Expose kernel and system statistics.
|
||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
file, err := os.Open(procFilePath("stat"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -75,7 +75,7 @@ func NewSystemdCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *systemdCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
units, err := c.listUnits()
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get units states: %s", err)
|
||||
|
@ -73,7 +73,7 @@ func NewTCPStatCollector() (Collector, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
tcpStats, err := getTCPStats(procFilePath("net/tcp"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get tcpstats: %s", err)
|
||||
|
@ -66,7 +66,7 @@ func NewTextFileCollector() (Collector, error) {
|
||||
}
|
||||
|
||||
// Update implements the Collector interface.
|
||||
func (c *textFileCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ func NewvmStatCollector() (Collector, error) {
|
||||
return &vmStatCollector{}, nil
|
||||
}
|
||||
|
||||
func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
file, err := os.Open(procFilePath("vmstat"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -26,16 +26,16 @@ import (
|
||||
"github.com/prometheus/common/log"
|
||||
)
|
||||
|
||||
func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
|
||||
file, err = os.Open(procFilePath(path))
|
||||
func (c *zfsCollector) openProcFile(path string) (*os.File, error) {
|
||||
file, err := os.Open(procFilePath(path))
|
||||
if err != nil {
|
||||
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(path))
|
||||
err = errZFSNotAvailable
|
||||
return nil, errZFSNotAvailable
|
||||
}
|
||||
return
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) updateZfsStats(subsystem string, ch chan<- prometheus.Metric) (err error) {
|
||||
func (c *zfsCollector) updateZfsStats(subsystem string, ch chan<- prometheus.Metric) error {
|
||||
file, err := c.openProcFile(filepath.Join(c.linuxProcpathBase, c.linuxPathMap[subsystem]))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -76,12 +76,11 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) (err error)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler func(zfsSysctl, int)) (err error) {
|
||||
func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler func(zfsSysctl, int)) error {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
parseLine := false
|
||||
for scanner.Scan() {
|
||||
|
||||
parts := strings.Fields(scanner.Text())
|
||||
|
||||
if !parseLine && len(parts) == 3 && parts[0] == "name" && parts[1] == "type" && parts[2] == "data" {
|
||||
@ -110,13 +109,12 @@ func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler
|
||||
return scanner.Err()
|
||||
}
|
||||
|
||||
func (c *zfsCollector) parsePoolProcfsFile(reader io.Reader, zpoolPath string, handler func(string, zfsSysctl, int)) (err error) {
|
||||
func (c *zfsCollector) parsePoolProcfsFile(reader io.Reader, zpoolPath string, handler func(string, zfsSysctl, int)) error {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
parseLine := false
|
||||
var fields []string
|
||||
for scanner.Scan() {
|
||||
|
||||
line := strings.Fields(scanner.Text())
|
||||
|
||||
if !parseLine && len(line) >= 12 && line[0] == "nread" {
|
||||
|
Loading…
Reference in New Issue
Block a user