{"record":{"id":"415bdc9fd8214b49","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-415bdc","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/cpufreq_linux.go","lineNumber":41,"sourceCode":"\t\"github.com/prometheus/client_golang/prometheus\"\n\t\"github.com/prometheus/procfs/sysfs\"\n)\n\ntype cpuFreqCollector struct {\n\tfs     sysfs.FS\n\tdescs  cpuFreqDescs\n\tlogger *slog.Logger\n}\n\nfunc init() {\n\tregisterCollector(\"cpufreq\", defaultEnabled, NewCPUFreqCollector)\n}\n\n// NewCPUFreqCollector returns a new Collector exposing kernel/system statistics.\nfunc NewCPUFreqCollector(logger *slog.Logger) (Collector, error) {\n\tfs, err := sysfs.NewFS(*sysPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n\t}\n\n\treturn &cpuFreqCollector{\n\t\tfs:     fs,\n\t\tdescs:  newCPUFreqDescs(),\n\t\tlogger: logger,\n\t}, nil\n}\n\n// Update implements Collector and exposes cpu related metrics from /proc/stat and /sys/.../cpu/.\nfunc (c *cpuFreqCollector) Update(ch chan<- prometheus.Metric) error {\n\tcpuFreqs, err := c.fs.SystemCpufreq()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// sysfs cpufreq values are kHz, thus multiply by 1000 to export base units (hz).\n\t// See https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/cpufreq_linux.go#L23-L59","documentation":"NewCPUFreqCollector builds the collector by opening the sysfs filesystem via sysfs.NewFS(*sysPath) (default /sys). If the sysfs root cannot be opened/validated, construction fails and the error is wrapped as \"failed to open sysfs: %w\", so the cpufreq collector is never registered.","triggerScenarios":"Calling NewCPUFreqCollector (directly or via node_exporter startup with --collector.cpufreq) when sysfs.NewFS fails: the --path.sysfs flag points to a nonexistent or non-directory path, or an fs.Stat/permission error occurs while validating the mount.","commonSituations":"Typo or wrong value for --path.sysfs; running inside a container without /sys mounted; running node_exporter on a system where /sys is restricted; unit tests passing a bad sysPath fixture path.","solutions":["Verify the sysfs path: ls -d /sys (or the value passed to --path.sysfs) exists and is a directory.","If running in a container, mount /sys (e.g. -v /sys:/sys:ro).","Correct the --path.sysfs flag value to the real sysfs mount point.","Check the wrapped cause (%w) for permission errors and run with sufficient filesystem access.","Exclude the cpufreq collector (--no-collector.cpufreq) if frequency metrics are not needed."],"exampleFix":"// before\nnode_exporter --path.sysfs=/wrong/sys\n// after\nnode_exporter --path.sysfs=/sys","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(sysPath); err != nil || !fi.IsDir() {\n    // bad --path.sysfs; fix the flag before starting the collector\n}","typeGuard":null,"tryCatchPattern":"if _, err := NewCPUFreqCollector(logger); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Fatalf(\"sysfs path invalid: %v\", perr)\n    }\n    log.Fatalf(\"cpufreq init failed: %v\", err)\n}","preventionTips":["Always pass an explicit, verified --path.sysfs value in containerized deployments.","Mount /sys:ro whenever node_exporter runs in a container.","Smoke-test collector construction at deploy time instead of discovering at scrape time.","Disable collectors whose backing filesystem is unavailable."],"tags":["linux","sysfs","cpufreq","collector"],"backgroundTag":"file-open-failed","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"}