Browse Source

Conntrack update: differentiate ErrNoData and other errors (#1323, #1723)

Signed-off-by: Li Ling <liiling@google.com>
pull/1816/head
Li Ling 4 years ago
parent
commit
875f437fcc
  1. 18
      collector/conntrack_linux.go

18
collector/conntrack_linux.go

@ -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"
)
@ -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 err
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 err
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)
}

Loading…
Cancel
Save