Keepalived Monitoring – How to View Current State of Keepalived

backupkeepalivedload balancing

Is there a way to view the current state (Master/Backup) using a command line inside a server instance?

Cheers

Best Answer

You could use the notify command to write out a state file.

       # for ANY state transition.
       # "notify" script is called AFTER the
       # notify_* script(s) and is executed
       # with 3 arguments provided by keepalived
       # (ie don’t include parameters in the notify line).
       # arguments
       # $1 = "GROUP"|"INSTANCE"
       # $2 = name of group or instance
       # $3 = target state of transition
       #     ("MASTER"|"BACKUP"|"FAULT")
       notify /path/notify.sh

The create a notify script like:

#!/bin/bash
# notify.sh

echo $1 $2 is in $3 state > /var/run/keepalive.$1.$2.state

And a get state script like:

#!/bin/bash
# getstate.sh

cat /var/run/keepalive.*.*.state