{"record":{"id":"2aabdbb1f4302bb0","repo":"prometheus/node_exporter","slug":"offset-tolerance-must-be-non-negative","errorCode":null,"errorMessage":"offset tolerance must be non-negative","messagePattern":"offset tolerance must be non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/ntp.go","lineNumber":74,"sourceCode":"\tregisterCollector(\"ntp\", defaultDisabled, NewNtpCollector)\n}\n\n// NewNtpCollector returns a new Collector exposing sanity of local NTP server.\n// Default definition of \"local\" is:\n// - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on)\n// - the server is reachable with outgoing IP_TTL = 1\nfunc NewNtpCollector(logger *slog.Logger) (Collector, error) {\n\tipaddr := net.ParseIP(*ntpServer)\n\tif !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) {\n\t\treturn nil, fmt.Errorf(\"only IP address of local NTP server is valid for --collector.ntp.server\")\n\t}\n\n\tif *ntpProtocolVersion < 2 || *ntpProtocolVersion > 4 {\n\t\treturn nil, fmt.Errorf(\"invalid NTP protocol version %d; must be 2, 3, or 4\", *ntpProtocolVersion)\n\t}\n\n\tif *ntpOffsetTolerance < 0 {\n\t\treturn nil, fmt.Errorf(\"offset tolerance must be non-negative\")\n\t}\n\n\tif *ntpServerPort < 1 || *ntpServerPort > 65535 {\n\t\treturn nil, fmt.Errorf(\"invalid NTP port number %d; must be between 1 and 65535 inclusive\", *ntpServerPort)\n\t}\n\n\tlogger.Warn(\"This collector is deprecated and will be removed in the next major version release.\")\n\treturn &ntpCollector{\n\t\tstratum: typedDesc{prometheus.NewDesc(\n\t\t\tprometheus.BuildFQName(namespace, ntpSubsystem, \"stratum\"),\n\t\t\t\"NTPD stratum.\",\n\t\t\tnil, nil,\n\t\t), prometheus.GaugeValue},\n\t\tleap: typedDesc{prometheus.NewDesc(\n\t\t\tprometheus.BuildFQName(namespace, ntpSubsystem, \"leap\"),\n\t\t\t\"NTPD leap second indicator, 2 bits.\",\n\t\t\tnil, nil,\n\t\t), prometheus.GaugeValue},","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/ntp.go#L56-L92","documentation":"NewNtpCollector requires --collector.ntp.offset-tolerance to be non-negative. The tolerance is used to judge measured clock offset against the local clock; a negative value is meaningless for this check, so the constructor rejects it with this error at startup.","triggerScenarios":"Starting node_exporter with --collector.ntp.offset-tolerance set to a negative number, e.g. --collector.ntp.offset-tolerance=-1ms or -0.5 (the flag parses as a time duration, so any negative duration triggers this).","commonSituations":"Typos where a leading '-' sneaks into the flag value; templated configs where a variable meant to be positive is empty or sign-flipped; misunderstanding the flag as an allowable signed offset rather than a non-negative threshold.","solutions":["Set a non-negative duration, e.g. --collector.ntp.offset-tolerance=1ms (the default).","Search your systemd unit/Docker args/config management for a negative value on this flag.","If you intended to alert on offset in either direction, the collector already reports signed offset; keep tolerance as the magnitude threshold.","Fix templates so the value cannot expand to a negative duration."],"exampleFix":"// before\n//   --collector.ntp.offset-tolerance=-1ms\n// after\n//   --collector.ntp.offset-tolerance=1ms","handlingStrategy":"validation","validationCode":"# shell: ensure offset tolerance is a non-negative duration\ncase \"$NTP_TOL\" in -*) echo \"offset-tolerance must be non-negative\"; exit 1;; esac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the default (1ms) unless you have a measured reason to change it.","Guard templates so variables cannot expand to negative durations.","Understand the flag is a threshold magnitude, not a signed offset.","Review rendered CLI args in systemd units after config changes."],"tags":["ntp","configuration","cli-flag","validation"],"backgroundTag":"invalid-flag-value","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}