I have a redis sentinel cluster configured with 5 nodes with the following IPs:
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
I wish to find a simple way to determine if any server has gone offline from its own point of view.
On server 192.168.1.1 I tail the sentinel log file via: tail -f /var/log/redis/sentinel-6379.log
I pull the network cable from the 192.168.1.1 server and I see the following messages in the log file on server 192.168.1.1:
1567:X 21 Apr 2021 15:56:31.189 # +sdown master mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown slave 192.168.1.3:6379 192.168.1.3 6379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown slave 192.168.1.4:6379 192.168.1.4 6379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown slave 192.168.1.5:6379 192.168.1.5 6379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.214 # +sdown sentinel 88c16ee0855100cf25919c9113e97e83290965b0 192.168.1.2 26379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown sentinel 97d7e4885a56a90144bd312f395e1d96788f1ebe 192.168.1.3 26379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown sentinel f61240ca198c318e156a7d87f382728316b22a8e 192.168.1.4 26379 @ mymaster 192.168.1.2 6379
1567:X 21 Apr 2021 15:57:09.273 # +sdown sentinel f8c43aa0ffe4141ee5b09c1c78d253ae04e0d8bb 192.168.1.5 26379 @ mymaster 192.168.1.2 6379
I am also using redis-py https://pypi.org/project/redis/ in my python project to subscribe to the above +sdown messages like so:
r = redis.Redis(host='localhost', port=26379, username='myusername', password='mypassword')
p = r.pubsub()
p.psubscribe('+sdown')
p.psubscribe('-sdown')
p.psubscribe('+switch-master')
p.subscribe('+sentinel')
while True:
message = p.get_message()
if message:
print(message)
My question is how can I use these messages to determine that my server has gone OFFLINE as in when a network cable is pulled out?
Do I simply determine that all my +sdowns are received at the exact same time for example? Is there another better way to do this?