Browse Source

Merge pull request #1816 from liiling/master

Fix node_scrape_collector_success behaviour
pull/1940/head
Ben Kochie 4 years ago committed by GitHub
parent
commit
40ce993d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      collector/conntrack_linux.go
  2. 7
      collector/pressure_linux.go
  3. 12
      collector/rapl_linux.go
  4. 8
      collector/zfs.go

18
collector/conntrack_linux.go

@ -16,7 +16,12 @@
package collector package collector
import ( import (
"errors"
"fmt"
"os"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
@ -50,18 +55,25 @@ func NewConntrackCollector(logger log.Logger) (Collector, error) {
func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error { func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error {
value, err := readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_count")) value, err := readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_count"))
if err != nil { if err != nil {
// Conntrack probably not loaded into the kernel. return c.handleErr(err)
return nil
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.current, prometheus.GaugeValue, float64(value)) c.current, prometheus.GaugeValue, float64(value))
value, err = readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_max")) value, err = readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_max"))
if err != nil { if err != nil {
return nil return c.handleErr(err)
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.limit, prometheus.GaugeValue, float64(value)) c.limit, prometheus.GaugeValue, float64(value))
return nil return nil
} }
func (c *conntrackCollector) handleErr(err error) error {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "conntrack probably not loaded")
return ErrNoData
}
return fmt.Errorf("failed to retrieve conntrack stats: %w", err)
}

7
collector/pressure_linux.go

@ -16,7 +16,9 @@
package collector package collector
import ( import (
"errors"
"fmt" "fmt"
"os"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level" "github.com/go-kit/kit/log/level"
@ -88,8 +90,11 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
level.Debug(c.logger).Log("msg", "collecting statistics for resource", "resource", res) level.Debug(c.logger).Log("msg", "collecting statistics for resource", "resource", res)
vals, err := c.fs.PSIStatsForResource(res) vals, err := c.fs.PSIStatsForResource(res)
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
return nil return ErrNoData
}
return fmt.Errorf("failed to retrieve pressure stats: %w", err)
} }
switch res { switch res {
case "cpu": case "cpu":

12
collector/rapl_linux.go

@ -16,15 +16,20 @@
package collector package collector
import ( import (
"errors"
"fmt"
"os"
"strconv" "strconv"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs" "github.com/prometheus/procfs/sysfs"
) )
type raplCollector struct { type raplCollector struct {
fs sysfs.FS fs sysfs.FS
logger log.Logger
} }
func init() { func init() {
@ -41,6 +46,7 @@ func NewRaplCollector(logger log.Logger) (Collector, error) {
collector := raplCollector{ collector := raplCollector{
fs: fs, fs: fs,
logger: logger,
} }
return &collector, nil return &collector, nil
} }
@ -50,7 +56,11 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error {
// nil zones are fine when platform doesn't have powercap files present. // nil zones are fine when platform doesn't have powercap files present.
zones, err := sysfs.GetRaplZones(c.fs) zones, err := sysfs.GetRaplZones(c.fs)
if err != nil { if err != nil {
return nil if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "Platform doesn't have powercap files present", "err", err)
return ErrNoData
}
return fmt.Errorf("failed to retrieve rapl stats: %w", err)
} }
for _, rz := range zones { for _, rz := range zones {

8
collector/zfs.go

@ -67,6 +67,14 @@ func NewZFSCollector(logger log.Logger) (Collector, error) {
} }
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
if _, err := c.openProcFile(c.linuxProcpathBase); err != nil {
if err == errZFSNotAvailable {
level.Debug(c.logger).Log("err", err)
return ErrNoData
}
}
for subsystem := range c.linuxPathMap { for subsystem := range c.linuxPathMap {
if err := c.updateZfsStats(subsystem, ch); err != nil { if err := c.updateZfsStats(subsystem, ch); err != nil {
if err == errZFSNotAvailable { if err == errZFSNotAvailable {

Loading…
Cancel
Save