{"record":{"id":"6547a8b13352b2df","repo":"prometheus/node_exporter","slug":"sysctl-s-has-d-keys-but-only-d-defined-in-f-lag","errorCode":null,"errorMessage":"sysctl %s has %d keys but only %d defined in f lag","messagePattern":"sysctl (.+?) has (.+?) keys but only (.+?) defined in f lag","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/sysctl_linux.go","lineNumber":124,"sourceCode":"\t}\n\n\tswitch length {\n\tcase 0:\n\t\treturn nil, fmt.Errorf(\"sysctl %s has no values\", s.name)\n\tcase 1:\n\t\tif len(s.keys) > 0 {\n\t\t\treturn nil, fmt.Errorf(\"sysctl %s has only one value, but expected %v\", s.name, s.keys)\n\t\t}\n\t\treturn []prometheus.Metric{s.newConstMetric(values)}, nil\n\n\tdefault:\n\n\t\tif len(s.keys) == 0 {\n\t\t\treturn s.newIndexedMetrics(values), nil\n\t\t}\n\n\t\tif length != len(s.keys) {\n\t\t\treturn nil, fmt.Errorf(\"sysctl %s has %d keys but only %d defined in f lag\", s.name, length, len(s.keys))\n\t\t}\n\n\t\treturn s.newMappedMetrics(values)\n\t}\n}\n\ntype sysctl struct {\n\tnumeric bool\n\tname    string\n\tkeys    []string\n}\n\nfunc newSysctl(include string, numeric bool) (*sysctl, error) {\n\tparts := strings.SplitN(include, \":\", 2)\n\ts := &sysctl{\n\t\tnumeric: numeric,\n\t\tname:    parts[0],\n\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/sysctl_linux.go#L106-L142","documentation":"The sysctl returned `length` values but the user defined a different number of keys in the flag; the mapping from value index to label key is impossible. Note the message's 'f lag' typo is upstream. newMetrics aborts that sysctl's collection.","triggerScenarios":"--collector.sysctl.include='name:k1,k2' where the underlying file has 3 (or 1) values; kernel version changed the value count of a multi-value sysctl.","commonSituations":"Config written for an older kernel whose multi-value sysctl later gained/lost fields; off-by-one in the comma-separated key list.","solutions":["Count the values with `cat /proc/sys/<name>` and supply exactly that many keys","Update the include filter to match the current kernel's layout","Use the indexed form (no keys) to export values by index instead of names"],"exampleFix":"// before\n--collector.sysctl.include='kernel.sched:cpu1,cpu2'\n// after (3 values present)\n--collector.sysctl.include='kernel.sched:cpu1,cpu2,cpu3'","handlingStrategy":"validation","validationCode":"values := strings.Fields(string(data))\nif len(values) != len(keys) { return fmt.Errorf(\"want %d keys, sysctl has %d\", len(keys), len(values)) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"keys but only\") { /* realign key list with current kernel layout */ }","preventionTips":["Diff value counts across kernel versions you deploy on","Prefer indexed (key-less) export when key counts are unstable","Keep one include-list config per kernel version"],"tags":["linux","sysctl","configuration","cli-flags"],"backgroundTag":"invalid-argument-value","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"}