Overview
The FreeBSD Operating System provides the sysctl system call and utility to get and set system state at runtime. The kernel exposes available parameters for sysctl as objects in a Management Information Base (MIB). Today, FreeBSD includes thousands of sysctl parameters. Moreover, parameters can be added or removed dynamically.
Each computer likely builds a different MIB depending on:
- OS version
- Running kernel
- Built configuration
- Loaded kernel modules
- Hardware
Therefore, the kernel must provide additional features for exploring the MIB and retrieving extra information about each object (name, description, format, etc.). WebSysctl retrieves parameters and their associated properties from the MIBs loaded in the Update page and incrementally stores them in a database. Currently, only FreeBSD committers are authorized to upload MIBs, ensuring that all data originates from trusted sources.
Further reading and additional resources:
- Manuals: coding sysctl(3), utility sysctl(8), adding/removing parameters and retrieving info sysctl(9).
- Handbook: The sysctl utility.
- Utilities: CLI sysutils/nsysctl, TUI sysutils/sysctltui, GUI deskutils/sysctlview, HTML sysctl-mib-html.
- Coding: devel/libsysctlmibinfo2, sysutils/sysctlinfo-kmod.
Frequently Asked Questions
- Where are Flags, Types, Formats, and Label documented?
-
Flags and Types: see the
"CONTROL FLAGS"
section in the sysctl(9) manual.
Formats: see the "format" paragraph in the "DESCRIPTION OF ARGUMENTS" section of the same manual.
Label: see the prometheus_sysctl_exporter(8) manual and "label" in DESCRIPTION OF ARGUMENTS in the sysctl(9) manual. - What is the Handler?
-
sysctl looks up the node's OID in the MIB, then calls its associated handler
- a function (in kernel space).
Usually, the handler accesses a variable, but that's not mandatory.
A node might not have a handler at all (it' s NULL).
So knowing whether a node has a handler helps determine if it performs an action.
Typically, internal nodes and those with type "node" have an "Undefined" handler,
while leaves have a "Defined" handler.
Let's analyze two cases where a MIB leaf is of type "node":
Suppose your kernel has a leaf dev.subsystemFOO (a node without children), and its type is "node" with an "Undefined" handler. Why? Because it's the root of a hardware subtree that hasn't been instantiated (e.g., no device is present). So it's a "node" with no "Defined" handler - that makes sense.
Now, consider a more interesting case: a "node" type with a "Defined" handler. This is also the example in the sysctl(3) manual, it calls sysctl from kern.proc.pid.0 to kern.proc.pid.99, but:- kern.proc.pid is a leaf in the MIB (it has no children).
- It's of type "node" and has a "Defined" handler.
- kern.proc.pid.[0-99] are not in the MIB!
- Is there a tutorial for sysctl?
- Yes, check out the nsysctl tutorial. It explains all the features of sysctl step by step and how to use the information provided on this site.
- How can I get parameter info (like shown on this site) for the kernel running on my machine?
-
Use the -D option of nsysctl:
% nsysctl -D kern.ostype
1.1: kern.ostype: : Operating system type: string: A: RD MPSAFE CAPRD: "Defined": FreeBSD
The -p option makes the output more human-readable:
% nsysctl -Dp kern.ostype
[OID]: 1.1: [NAME]: kern.ostype: [LABEL]: : [DESCRIPTION]: Operating system type: [TYPE]: string: [FORMAT]: A: [FLAGS]: RD MPSAFE CAPRD: [HANDLER]: "Defined": [VALUE]: FreeBSD
See the nsysctl(8) manual for all available options. - How is the data shown on this site generated?
-
By running the following commands on FreeBSD:
% echo "<!---" >> mib.xml ; nsysctl -e kern.osrelease kern.osreldate >> mib.xml ; echo "-->" >> mib.xml ; nsysctl --libxo=xml,pretty -r MIB -DNkISa >> mib.xml
- Is there a GUI for sysctl?
-
Yes, it's sysctlview.
From the menu: View, you can choose which nodes and properties to display.
- Is there a TUI for sysctl?
-
Yes, it's sysctltui.
- How is the MIB implemented in the kernel?
- Refer to the sysctlinfo README: Introduction.
- Are there coding resources?
-
Get/Set a value: sysctl(3)
Add/Remove a node: sysctl(9)
Explore the MIB and get node properties: sysctlmibinfo2(3) and sysctlinfo(4) - Is WebSysctl open source?
- WebSysctl is released under the 2-Clause BSD License. It will definitely be open source in the future. Currently, it's still under development and resides in a private repository.