{"record":{"id":"b3b7b337a96c8b33","repo":"henrygd/beszel","slug":"size-field-not-found-in-arcstats","errorCode":null,"errorMessage":"size field not found in arcstats","messagePattern":"size field not found in arcstats","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent/zfs/zfs_linux.go","lineNumber":33,"sourceCode":"\tfile, err := os.Open(\"/proc/spl/kstat/zfs/arcstats\")\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer file.Close()\n\n\tscanner := bufio.NewScanner(file)\n\tfor scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif strings.HasPrefix(line, \"size\") {\n\t\t\tfields := strings.Fields(line)\n\t\t\tif len(fields) < 3 {\n\t\t\t\treturn 0, fmt.Errorf(\"unexpected arcstats size format: %s\", line)\n\t\t\t}\n\t\t\treturn strconv.ParseUint(fields[2], 10, 64)\n\t\t}\n\t}\n\n\treturn 0, fmt.Errorf(\"size field not found in arcstats\")\n}\n","sourceCodeStart":15,"sourceCodeEnd":35,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/zfs/zfs_linux.go#L15-L35","documentation":"ARCSize scans arcstats for a line prefixed with `size`; if the whole file is scanned without finding one, it returns this error. It means the ZFS ARC statistics file exists but exposes no `size` kstat entry.","triggerScenarios":"The opened path exists but is not a populated arcstats file (empty or filtered procfs), or a ZFS build where the `size` kstat was renamed/removed, or /proc/spl not properly mounted.","commonSituations":"ZFS userspace tools present but kernel module not loaded (empty stats); OpenZFS variants that moved stats to a different kstat file; containers where procfs is restricted.","solutions":["Confirm `grep size /proc/spl/kstat/zfs/arcstats` returns a line; if not, check `lsmod | grep zfs` and load the ZFS kernel module.","On newer OpenZFS, check for renamed/moved stats files and point the reader at the correct path.","Inside a container, ensure /proc/spl is mounted/visible from the host.","Gracefully degrade: treat missing ARC stats as metric-unavailable if ZFS is not installed."],"exampleFix":"// before\nreturn 0, fmt.Errorf(\"size field not found in arcstats\")\n// after\nif _, err := os.Stat(\"/proc/spl/kstat/zfs/arcstats\"); err != nil {\n\treturn 0, nil // ZFS not present — metric unavailable\n}\nreturn 0, fmt.Errorf(\"size field not found in arcstats\")","handlingStrategy":"fallback","validationCode":"if data, err := os.ReadFile(\"/proc/spl/kstat/zfs/arcstats\"); err != nil || !strings.Contains(string(data), \"\\nsize \") {\n\t// ZFS stats unavailable — skip ARC metric entirely\n}","typeGuard":"func arcstatsHasSize(data []byte) bool {\n\tfor _, line := range strings.Split(string(data), \"\\n\") {\n\t\tif strings.HasPrefix(line, \"size\") { return true }\n\t}\n\treturn false\n}","tryCatchPattern":"size, err := zfs.ARCSize()\nif err != nil {\n\tlog.Printf(\"ARC size unavailable, reporting 0: %v\", err)\n\tsize = 0\n}","preventionTips":["Feature-detect /proc/spl/kstat/zfs/arcstats before enabling ZFS metrics.","Handle renamed kstat entries across OpenZFS versions.","Distinguish 'ZFS not installed' from 'stats malformed' in logs.","Degrade to zero/absent metric rather than failing collection."],"tags":["go","zfs","procfs","missing-field"],"backgroundTag":"unexpected-file-format","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}