Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node_scrape_collector_success behaviour #1816

Merged
merged 4 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions collector/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
package collector

import (
"errors"
"fmt"
"os"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -50,18 +55,25 @@ func NewConntrackCollector(logger log.Logger) (Collector, 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.
return nil
return c.handleErr(err)
}
ch <- prometheus.MustNewConstMetric(
c.current, prometheus.GaugeValue, float64(value))

value, err = readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_max"))
if err != nil {
return nil
return c.handleErr(err)
}
ch <- prometheus.MustNewConstMetric(
c.limit, prometheus.GaugeValue, float64(value))

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)
}
9 changes: 7 additions & 2 deletions collector/pressure_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package collector

import (
"errors"
"fmt"
"os"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
Expand Down Expand Up @@ -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)
vals, err := c.fs.PSIStatsForResource(res)
if err != nil {
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
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")
return ErrNoData
}
return fmt.Errorf("failed to retrieve pressure stats: %w", err)
}
switch res {
case "cpu":
Expand Down
16 changes: 13 additions & 3 deletions collector/rapl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
package collector

import (
"errors"
"fmt"
"os"
"strconv"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)

type raplCollector struct {
fs sysfs.FS
fs sysfs.FS
logger log.Logger
}

func init() {
Expand All @@ -40,7 +45,8 @@ func NewRaplCollector(logger log.Logger) (Collector, error) {
}

collector := raplCollector{
fs: fs,
fs: fs,
logger: logger,
}
return &collector, nil
}
Expand All @@ -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.
zones, err := sysfs.GetRaplZones(c.fs)
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 {
Expand Down
8 changes: 8 additions & 0 deletions collector/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func NewZFSCollector(logger log.Logger) (Collector, error) {
}

func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {

if _, err := c.openProcFile(c.linuxProcpathBase); err != nil {
SuperQ marked this conversation as resolved.
Show resolved Hide resolved
if err == errZFSNotAvailable {
level.Debug(c.logger).Log("err", err)
return ErrNoData
}
}

for subsystem := range c.linuxPathMap {
if err := c.updateZfsStats(subsystem, ch); err != nil {
if err == errZFSNotAvailable {
Expand Down