{"record":{"id":"aa9fcf69ff7e3e55","repo":"prometheus/node_exporter","slug":"couldn-t-get-swap-information-w","errorCode":null,"errorMessage":"couldn't get swap information: %w","messagePattern":"couldn't get swap information: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/swap_linux.go","lineNumber":81,"sourceCode":"\tswaps, err := c.fs.Swaps()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"couldn't get proc/swap information: %w\", err)\n\t}\n\n\tmetrics := make([]SwapsEntry, 0, len(swaps))\n\n\tfor _, swap := range swaps {\n\t\tmetrics = append(metrics, SwapsEntry{Device: swap.Filename, Type: swap.Type,\n\t\t\tPriority: swap.Priority, Size: swap.Size, Used: swap.Used})\n\t}\n\n\treturn metrics, nil\n}\n\nfunc (c *swapCollector) Update(ch chan<- prometheus.Metric) error {\n\tswaps, err := c.getSwapInfo()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get swap information: %w\", err)\n\t}\n\n\tfor _, swap := range swaps {\n\t\tswapLabelValues := []string{swap.Device, swap.Type}\n\n\t\t// Export swap size in bytes\n\t\tch <- prometheus.MustNewConstMetric(\n\t\t\tprometheus.NewDesc(\n\t\t\t\tprometheus.BuildFQName(namespace, swapSubsystem, \"size_bytes\"),\n\t\t\t\t\"Swap device size in bytes.\",\n\t\t\t\t[]string{\"device\", \"swap_type\"}, nil,\n\t\t\t),\n\t\t\tprometheus.GaugeValue,\n\t\t\t// Size is provided in kbytes (not bytes), translate to bytes\n\t\t\t// see https://github.com/torvalds/linux/blob/fd94619c43360eb44d28bd3ef326a4f85c600a07/mm/swapfile.c#L3079-L3080\n\t\t\tfloat64(swap.Size*1024),\n\t\t\tswapLabelValues...,\n\t\t)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/swap_linux.go#L63-L99","documentation":"Update wrapped a failure from getSwapInfo (itself a procfs /proc/swaps read/parse failure) while gathering swap metrics. The whole swap scrape fails for the cycle; the root cause is in the underlying /proc/swaps access.","triggerScenarios":"Thrown at collector/swap_linux.go:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check /proc/swaps readability and format as for the underlying error.","Retry the scrape; transient read failures clear on the next cycle.","Disable the swap collector if the host has no swap support in its kernel."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}