{"record":{"id":"da8032c4a254b1e8","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-da8032","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/cpu_linux.go","lineNumber":82,"sourceCode":"\tflagsInclude         = kingpin.Flag(\"collector.cpu.info.flags-include\", \"Filter the `flags` field in cpuInfo with a value that must be a regular expression\").String()\n\tbugsInclude          = kingpin.Flag(\"collector.cpu.info.bugs-include\", \"Filter the `bugs` field in cpuInfo with a value that must be a regular expression\").String()\n\tjumpBackDebugMessage = fmt.Sprintf(\"CPU Idle counter jumped backwards more than %f seconds, possible hotplug event, resetting CPU stats\", jumpBackSeconds)\n)\n\nfunc init() {\n\tregisterCollector(\"cpu\", defaultEnabled, NewCPUCollector)\n}\n\n// NewCPUCollector returns a new Collector exposing kernel/system statistics.\nfunc NewCPUCollector(logger *slog.Logger) (Collector, error) {\n\tpfs, err := procfs.NewFS(*procPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\tsfs, err := sysfs.NewFS(*sysPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n\t}\n\n\tisolcpus, err := sfs.IsolatedCPUs()\n\tif err != nil {\n\t\tif !os.IsNotExist(err) {\n\t\t\treturn nil, fmt.Errorf(\"unable to get isolated cpus: %w\", err)\n\t\t}\n\t\tlogger.Debug(\"couldn't open isolated file\", \"error\", err)\n\t}\n\n\tc := &cpuCollector{\n\t\tprocfs: pfs,\n\t\tsysfs:  sfs,\n\t\tcpu:    nodeCPUSecondsDesc,\n\t\tcpuInfo: prometheus.NewDesc(\n\t\t\tprometheus.BuildFQName(namespace, cpuCollectorSubsystem, \"info\"),\n\t\t\t\"CPU information from /proc/cpuinfo.\",\n\t\t\t[]string{\"package\", \"core\", \"cpu\", \"vendor\", \"family\", \"model\", \"model_name\", \"microcode\", \"stepping\", \"cachesize\"}, nil,","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/cpu_linux.go#L64-L100","documentation":"NewCPUCollector opens a sysfs handle at --path.sysfs (needed e.g. for CPU frequency and isolated-CPU info) and returns this wrapped error if that filesystem cannot be opened. Like the procfs failure it aborts collector construction at startup.","triggerScenarios":"sysfs.NewFS(*sysPath) errors: --path.sysfs does not exist, is not sysfs, or is unreadable.","commonSituations":"Containers that do not mount /sys (or mount it elsewhere, e.g. /host/sys) without adjusting --path.sysfs; running the Linux exporter build outside Linux; restrictive mount namespaces.","solutions":["Mount /sys (read-only) into the container or set --path.sysfs to the correct location","Verify the target directory is a real sysfs mount and readable","Run the platform-correct exporter binary if not on Linux"],"exampleFix":"// before\ndocker run node_exporter  # no /sys mounted\n// after\ndocker run -v /sys:/host/sys:ro node_exporter --path.sysfs=/host/sys","handlingStrategy":"validation","validationCode":"// Go: pre-flight sysfs availability\nif fi, err := os.Stat(filepath.Join(*sysPath, \"devices/system/cpu\")); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"--path.sysfs %q lacks /sys/devices/system/cpu\", *sysPath)\n}","typeGuard":null,"tryCatchPattern":"if _, err := NewCPUCollector(logger); err != nil {\n    if strings.Contains(err.Error(), \"failed to open sysfs\") {\n        return fmt.Errorf(\"fix --path.sysfs (default /sys): %w\", err)\n    }\n    return err\n}","preventionTips":["Bind-mount /sys read-only in containers alongside --path.sysfs=/host/sys","Confirm the mount namespace of the exporter can see /sys","Test collector startup flags on a staging host"],"tags":["sysfs","cpu","linux"],"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"}