fix: freebsd plugin counters size mismatch - #23044
Conversation
Fix incorrect data types for FreeBSD `vm.stats.*` counters. All `vm.stats.` counters are defined as `counter_u64_t` (64-bit) in the FreeBSD kernel, but the Netdata FreeBSD plugin was reading them as `u_int` (32-bit). This work was sponsored by [OVHcloud](https://www.ovhcloud.com).
There was a problem hiding this comment.
Pull request overview
This PR fixes FreeBSD vm.stats.* sysctl counter reads in freebsd.plugin by using 64-bit types so they match the kernel’s 64-bit counter storage and avoid size-mismatch failures/inaccurate readings.
Changes:
- Read
vm.stats.sys.v_intr,vm.stats.sys.v_soft,vm.stats.sys.v_swtch, andvm.stats.vm.v_forksintouint64_tinstead ofu_int. - Preserve existing chart update logic while allowing these counters to be fetched with the correct sysctl value size.
Comments suppressed due to low confidence (2)
src/collectors/freebsd.plugin/freebsd_sysctl.c:690
- The error message for the v_soft sysctl failure disables the wrong chart name. This function creates the
system.soft_intrchart, but the error message currently sayssystem.dev_intr, which is misleading during troubleshooting.
uint64_t soft_intr_number;
if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_soft", mib, soft_intr_number))) {
collector_error("DISABLED: system.dev_intr chart");
collector_error("DISABLED: vm.stats.sys.v_soft module");
src/collectors/freebsd.plugin/freebsd_sysctl.c:772
- The module name in this error message doesn't match the sysctl being read. On failure of
vm.stats.vm.v_forks, it currently reportsvm.stats.sys.v_swtch, which makes logs misleading.
uint64_t forks_number;
if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_forks", mib, forks_number))) {
collector_error("DISABLED: system.forks chart");
collector_error("DISABLED: vm.stats.sys.v_swtch module");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@DavidMarec, thanks! See the CLA. We'll need it to be signed before we can merge the PR. |
it's signed for. |
|



Summary
Fix incorrect data types for FreeBSD
vm.stats.*counters. Allvm.stats.counters are defined ascounter_u64_t(64-bit) in the FreeBSD kernel, but the Netdata FreeBSD plugin was reading them asu_int(32-bit).Test Plan
NetData outputs tested on one FreeBSD 15 machine.
Additional Information
This work was sponsored by OVHcloud.
Summary by cubic
Read FreeBSD
vm.stats.*counters as 64-bit (uint64_t) in the plugin to match kernelcounter_u64_t. Fixes truncation and inaccurate values for interrupts (v_intr), soft interrupts (v_soft), context switches (v_swtch), and forks (v_forks).Written for commit 2defc73. Summary will update on new commits.