mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-03-05 21:00:12 -08:00
Signed-off-by: Li Ling <liiling@google.com>
This commit is contained in:
parent
a26ffaf4f8
commit
875f437fcc
|
@ -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 err
|
|
||||||
}
|
}
|
||||||
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 err
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue