keepalived-exporter icon indicating copy to clipboard operation
keepalived-exporter copied to clipboard

Exporter not working when keepalived container init doesn't handle keepalived signals

Open sbienkow opened this issue 3 years ago • 0 comments

Currently, if docker mode is enabled, this exporter first checks signal numbers, by executing command in container: docker exec "${container-name}" keepalived --signum [STATS|DATA]. Related lines: https://github.com/cafebazaar/keepalived-exporter/blob/master/internal/types/container/keepalived_container_collector_host.go#L76-L104

It then uses those signal numbers to send them through docker to process with PID1 inside the container `docker kill : https://github.com/cafebazaar/keepalived-exporter/blob/master/internal/types/container/keepalived_container_collector_host.go#L106-L117

This unfortunately fails with osixia keepalived docker image, because it's init script doesn't relay these signals to keepalived instances it spawns https://github.com/osixia/docker-keepalived/issues/50. While I believe this should be fixed in the keepalived image itself, maybe it could be considered to be handled in the exporter. I've chosen to use that docker image, because it seems most up to date.

The fix for this seems relatively simple - instead of running docker kill --signal 12 keepalived, one could run docker exec keepalived sh -c 'kill -12 "$( cat /var/run/keepalived.pid )"'. Of course this assumes that sh exists, so would probably require it to be a separate command line argument to switch between these 2 behaviors.

sbienkow avatar Apr 13 '21 16:04 sbienkow