From 1d03daf616f92fc05a75261c15ae910f4ab16c64 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Fri, 22 Jan 2021 18:16:25 +0100 Subject: [PATCH] Handle EPERM for syscall in timex collector Handle case where Adjtimex syscall gets a permission denined error. Fixes: https://github.com/prometheus/node_exporter/issues/1934 Signed-off-by: Ben Kochie --- CHANGELOG.md | 1 + collector/timex.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb8fd13..c857ddc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [ENHANCEMENT] Include TCP OutRsts in netstat metrics * [ENHANCEMENT] Added XFS inode operations to XFS metrics * [ENHANCEMENT] Remove CGO dependencies for OpenBSD amd64 +* [BUGFIX] Handle EPERM for syscall in timex collector * [BUGFIX] ## 1.0.1 / 2020-06-15 diff --git a/collector/timex.go b/collector/timex.go index 4dc4d6c3..3b978ec5 100644 --- a/collector/timex.go +++ b/collector/timex.go @@ -17,9 +17,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" "golang.org/x/sys/unix" ) @@ -163,6 +166,10 @@ func (c *timexCollector) Update(ch chan<- prometheus.Metric) error { status, err := unix.Adjtimex(timex) if err != nil { + if errors.Is(err, os.ErrPermission) { + level.Debug(c.logger).Log("msg", "Not collecting timex metrics", "err", err) + return ErrNoData + } return fmt.Errorf("failed to retrieve adjtimex stats: %w", err) }