Monitor DRBD state with bash shell script

I do monitor the state of my drbd discs with a simple shell script. If the state is not up to date i'll get informed by email. This is a good idea - the network connection can come down (i'd this issue several times in the last years).

Here is the output of my DRBD kernel module:

root@server:~# cat /proc/drbd
version: 8.2.6 (api:88/proto:86-88)
0: cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate C r---
ns:30607944 nr:0 dw:29555272 dr:16521929 al:29175 bm:274 lo:0 pe:0 ua:0 ap:0 oos:0
1: cs:Connected st:Secondary/Primary ds:UpToDate/UpToDate C r---
ns:0 nr:60660364 dw:60660364 dr:0 al:0 bm:160 lo:0 pe:0 ua:0 ap:0 oos:0

It's simple to grep out the state of the 2 discs and send a email. Run this as cronjob.


status=$(egrep "(Primary\/Secondary|Secondary\/Primary)" /proc/drbd | egrep -o UpToDate/UpToDate | wc -l)

if [ ! $status -eq 2 ] ; then
mutt -s "DRBD-state wrong - Cluster Node $(hostname)" info@domain.tld </dev/null


ZajkoĊ› said…
status=$(cat /proc/drbd | egrep -o UpToDate/UpToDate | wc -l)

Popular Posts