{"record":{"id":"7fd149fca22c51f4","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-7fd149","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/nvme_linux.go","lineNumber":79,"sourceCode":"\n\tnvmeNamespaceUsedBytes = prometheus.NewDesc(\n\t\tprometheus.BuildFQName(namespace, \"nvme\", \"namespace_used_bytes\"),\n\t\t\"Used space of the NVMe namespace in bytes. Available in /sys/class/nvme/<device>/<namespace>/nuse\",\n\t\t[]string{\"device\", \"nsid\"}, nil,\n\t)\n\n\tnvmeNamespaceLogicalBlockSizeBytes = prometheus.NewDesc(\n\t\tprometheus.BuildFQName(namespace, \"nvme\", \"namespace_logical_block_size_bytes\"),\n\t\t\"Logical block size of the NVMe namespace in bytes. Usually 4Kb. Available in /sys/class/nvme/<device>/<namespace>/queue/logical_block_size\",\n\t\t[]string{\"device\", \"nsid\"}, nil,\n\t)\n)\n\n// NewNVMeCollector returns a new Collector exposing NVMe stats.\nfunc NewNVMeCollector(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\treturn &nvmeCollector{\n\t\tfs:     fs,\n\t\tlogger: logger,\n\t}, nil\n}\n\nfunc (c *nvmeCollector) Update(ch chan<- prometheus.Metric) error {\n\tdevices, err := c.fs.NVMeClass()\n\tif err != nil {\n\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\tc.logger.Debug(\"nvme statistics not found, skipping\")\n\t\t\treturn ErrNoData\n\t\t}\n\t\treturn fmt.Errorf(\"error obtaining NVMe class info: %w\", err)\n\t}\n\n\tfor _, device := range devices {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/nvme_linux.go#L61-L97","documentation":"NewNVMeCollector constructs the collector by calling sysfs.NewFS(*sysPath), which validates the sysfs mount point. If the path cannot be opened (missing directory, wrong --path.sysfs value, or not a valid sysfs), the constructor returns this wrapped error and node_exporter fails to start that collector. It is a startup-time configuration error, not a scrape error.","triggerScenarios":"Calling NewNVMeCollector when --path.sysfs points to a nonexistent or invalid directory, causing sysfs.NewFS to fail; also triggered when the sysfs mount is absent entirely (e.g. minimal containers, non-Linux builds are gated separately).","commonSituations":"Running node_exporter in a container without mounting the host's /sys and without --path.sysfs=/host/sys; typos in --path.sysfs; overriding sysPath for tests to a temp dir that was cleaned up.","solutions":["Point --path.sysfs at a valid sysfs mount (default /proc/sys... default is /sys): --path.sysfs=/sys.","In containers, mount the host sysfs read-only: -v /sys:/host/sys:ro and use --path.sysfs=/host/sys.","Verify the NVMe class dir exists: 'ls /sys/class/nvme'.","Check the wrapped cause (%w) to distinguish ENOENT from permission issues."],"exampleFix":"// before: sysfs not mounted in container\n//   docker run node-exporter --collector.nvme\n// after\n//   docker run -v /sys:/host/sys:ro node-exporter \\\n//     --path.sysfs=/host/sys --collector.nvme","handlingStrategy":"validation","validationCode":"// Go: validate sysfs path before constructing the collector\nif st, err := os.Stat(filepath.Join(*sysPath, \"class\")); err != nil || !st.IsDir() {\n    log.Fatalf(\"invalid --path.sysfs (%s): %v\", *sysPath, err)\n}","typeGuard":null,"tryCatchPattern":"// constructor error is fatal; wrap and surface the cause\nfs, err := sysfs.NewFS(*sysPath)\nif err != nil {\n    return nil, fmt.Errorf(\"failed to open sysfs: %w\", err)\n}","preventionTips":["Mount host /sys read-only in containers and set --path.sysfs=/host/sys.","Keep the default /sys unless you specifically remap sysfs.","Verify /sys/class/nvme exists when enabling --collector.nvme.","Smoke-test images with the full flag set before production rollout."],"tags":["linux","sysfs","nvme","startup","configuration"],"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"}