prometheus/node_exporter · error
getifaddrs() failed
Error message
getifaddrs() failed
What it means
On BSD platforms the netdev collector enumerates network interfaces via the C getifaddrs() libc call. If getifaddrs returns -1 (it failed to allocate memory or could not read the kernel interface table), getNetDevStats returns this error immediately and the netdev scrape fails. It is a raw wrapper over the errno reported by the libc call.
Solutions
- Check the process sandbox: run outside a restricted jail or grant the needed privileges so getifaddrs can enumerate interfaces.
- Verify memory availability at scrape time (the call mallocs the full interface list); raise limits if the host has thousands of interfaces.
- Retry the scrape — if it's transient interface churn, the next scrape usually succeeds.
- If the platform genuinely blocks it (e.g. minimal sandbox image), disable the netdev collector via `--collector.disable-defaults` + selective enables.
Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight: ensure the process can enumerate interfaces before enabling netdev on BSD // (no direct Go pre-check; probe with a syscall-free check is not possible, but you can // verify sandbox allows lib libc getifaddrs by running `ifconfig -a` in the same sandbox) // shell: ifconfig -a >/dev/null 2>&1 || echo 'interface enumeration blocked'
Try / catch
stats, err := getNetDevStats(filter, logger)
if err != nil && strings.Contains(err.Error(), "getifaddrs() failed") {
// transient churn or sandbox restriction; back off and retry once
time.Sleep(100 * time.Millisecond)
if stats, err = getNetDevStats(filter, logger); err != nil {
logger.Warn("netdev scrape failed: getifaddrs unavailable", "err", err)
}
} Prevention
- Run the exporter outside restricted jails/sandboxes (capsicum, pledge) or grant needed privileges.
- Confirm `ifconfig -a` works as the same user in the same sandbox before deploying.
- Watch host memory: getifaddrs allocates the full interface list; huge interface counts need headroom.
- Treat single failed scrapes as transient; alert only on sustained netdev collector failures.
When it happens
Trigger: getNetDevStats invokes `C.getifaddrs(&ifap)` and it returns -1. This happens when the process cannot allocate memory for the interface list, the syscall is blocked (sandbox/seccomp/capability restrictions), or the kernel's network interface table cannot be read (e.g. during heavy interface churn or in restricted jails).
Common situations: Running node_exporter inside a jail/container on FreeBSD/OpenBSD with restricted sysctls; memory exhaustion at scrape time; hardened sandboxing (capsicum, pledge, seccomp-like filters) that blocks getifaddrs; transient kernel states on systems with thousands of interfaces being created/destroyed.
Related errors
- could not retrieve CPU times
- getdevs() failed
- calloc() failed
- devstat_getdevs failed
- getmntinfo() failed
AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07).
Data as JSON: /api/errors/4711a0bd1c623d3c.
Report an issue: GitHub.
Appendix: source
Thrown at collector/netdev_bsd.go:38
"log/slog"
)
/*
#cgo CFLAGS: -D_IFI_OQDROPS
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <net/if.h>
*/
import "C"
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
netDev := netDevStats{}
var ifap, ifa *C.struct_ifaddrs
if C.getifaddrs(&ifap) == -1 {
return nil, errors.New("getifaddrs() failed")
}
defer C.freeifaddrs(ifap)
for ifa = ifap; ifa != nil; ifa = ifa.ifa_next {
if ifa.ifa_addr.sa_family != C.AF_LINK {
continue
}
dev := C.GoString(ifa.ifa_name)
if filter.ignored(dev) {
logger.Debug("Ignoring device", "device", dev)
continue
}
data := (*C.struct_if_data)(ifa.ifa_data)
netDev[dev] = map[string]uint64{
"receive_packets": uint64(data.ifi_ipackets),View on GitHub (pinned to 17ddd77c59)