{"record":{"id":"9af3b508940e0d83","repo":"prometheus/node_exporter","slug":"failed-to-open-sysfs-w-9af3b5","errorCode":null,"errorMessage":"failed to open sysfs: %w","messagePattern":"failed to open sysfs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/pcidevice_linux.go","lineNumber":165,"sourceCode":"\tlogger        *slog.Logger\n\tpciVendors    map[string]string\n\tpciDevices    map[string]map[string]string\n\tpciSubsystems map[string]map[string]string\n\tpciClasses    map[string]string\n\tpciSubclasses map[string]string\n\tpciProgIfs    map[string]string\n\tpciNames      bool\n}\n\nfunc init() {\n\tregisterCollector(\"pcidevice\", defaultDisabled, NewPcideviceCollector)\n}\n\n// NewPcideviceCollector returns a new Collector exposing PCI devices stats.\nfunc NewPcideviceCollector(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\t// Initialize PCI ID maps\n\tc := &pcideviceCollector{\n\t\tfs:       fs,\n\t\tlogger:   logger,\n\t\tpciNames: *pciNames,\n\t}\n\n\t// Build label names based on whether name resolution is enabled\n\tlabelNames := append(pcideviceLabelNames,\n\t\t[]string{\"parent_segment\", \"parent_bus\", \"parent_device\", \"parent_function\",\n\t\t\t\"class_id\", \"vendor_id\", \"device_id\", \"subsystem_vendor_id\", \"subsystem_device_id\", \"revision\"}...)\n\n\tif c.pciNames {\n\t\tc.loadPCIIds()\n\t\t// Add name labels when name resolution is enabled\n\t\tlabelNames = append(labelNames, \"vendor_name\", \"device_name\", \"subsystem_vendor_name\", \"subsystem_device_name\", \"class_name\")","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/pcidevice_linux.go#L147-L183","documentation":"NewPcideviceCollector builds a collector exposing PCI device stats from sysfs. It calls sysfs.NewFS(*sysPath) using the --path.sysfs flag and wraps any failure in \"failed to open sysfs\". sysfs.NewFS validates that the path is an accessible filesystem, so construction fails when the sysfs root is missing or unusable.","triggerScenarios":"NewPcideviceCollector returns this when sysfs.NewFS(*sysPath) errors: --path.sysfs does not exist, /sys is not mounted (containers, chroots), or the sysfs root passed by the caller (e.g. TestPCICollectorWithNameResolution fixtures) is invalid.","commonSituations":"Wrong --path.sysfs flag value; container images without sysfs mounted; test fixtures not unpacked (make test unpacks sys.ttar); running on non-Linux where sysfs does not exist.","solutions":["Ensure /sys exists and is mounted (mount -t sysfs sysfs /sys)","Correct the --path.sysfs flag to an existing sysfs root","For tests, unpack fixtures via `make test` so collector/fixtures/sys exists","Bind-mount host /sys into the container read-only when running in Docker"],"exampleFix":"// before\nmount -t proc proc /proc   # sysfs never mounted\n// after\nmount -t sysfs sysfs /sys  # then start node_exporter --collector.pcidevice","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(*sysPath); err != nil { return fmt.Errorf(\"sysfs path %q missing: %w\", *sysPath, err) }","typeGuard":"func sysfsReady(path string) bool { st, err := os.Stat(path); return err == nil && st.IsDir() }","tryCatchPattern":"c, err := collector.NewPcideviceCollector(logger)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to open sysfs\") {\n        logger.Warn(\"PCI collector disabled: sysfs unavailable\", \"err\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Mount sysfs in containers/chroots before enabling PCI collection","Validate --path.sysfs at deployment time with a pre-start check","Unpack sysfs fixtures before running unit tests (make test)","Use read-only bind mounts of /sys in Docker (--read-only friendly)"],"tags":["linux","sysfs","pci","collector-init"],"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"}