Collectd's `ping` ignores DNS names

I have setup collectd to keep track of ping reachability&latency for a few hosts, and I see that this works only for those hosts that I designated with an IP address rather than with a DNS name.

If I change the list and hit "save&apply", then suddenly the DNS-named hosts start showing up on the "ping" graphs, but not after a normal reboot.
I strongly suspect that it's due to the fact that when my machine reboots, it takes a little while before the DSL and PPPoE establish a connection with my provider, so the ping service fails to get an IP address for those DNS-named hosts at boot because the resolver is basically not working yet at that point.

Is this a known bug/limitation? Any known solution/workaround?

Sounds like a race condition?

sleep 60 and start the service manually in /etc/rc.local ?

Yes, at least to insiders, unfortunately :slight_smile: Because of the sequence of service starts, and the fact, that there is no assurance, that a certain service is started only, after another required service
is fully up. In your case, dnsmasq can not do DNS resolution soon enough.
Thus, it might help, but not always solve your issue, by modifying the priority of the start of collectd. I.e. by editing /etc/init.d/collectd.
Best would be, like already stated, to disable collectd service, and start in /etc/rc.local. But not using a fixed timer ("Last help for a desparate programmer") but to have a loop, checking for successful ping of a well known domain, before starting collectd.
I.e.
while [ TRUE ]; do
ping -4 google.com -q -c 2 > /dev/null
#Success only, in case network up and DNS works
if [ $? -eq 0 ]; then break ; fi
sleep 2
COUNT=$((COUNT+1))
if [ $COUNT -ge 30 ]; then
logger 'Çould not start collectd during 60s'
break
fi
done
/etc/init.d/collectd start

2 Likes

Is there some more "event driven" solution, like some script that's run when the DNS info changes (like I used to use /etc/resolvconf/update.d/ in Debian) or when the PPPoE interface goes up?
Also, is there some open issue for it?

have a look at https://openwrt.org/docs/guide-user/base-system/hotplug

1 Like