Here is a nagios script we use to check that 2 couch dbs match between machines
Mike. On 09/09/2016 09:40, Kristian Rink wrote:
Folks; I want to use some monitoring to check whether continuous replication between two couchdb nodes works as desired. Setting up continuous replication via REST API or admin UI works well, and in the admin UI I do have http://<host>:5984/_utils/status.html to check the status of all replication processes running. Is this information exposed via JSON, too, so I can evaluate this from, say, an external nagios script? TIA and all the best, Kristian
#!/usr/local/bin/bash # nagios check script to make sure 2 couch servers are the same # # ie: have same dbs # have same number of documents in each db # # ./check_couch_dbs 192.168.6.20 192.168.8.12 # # Needs fdescfs for bash redirects # # Needs npm - as root: 'pkg install npm' # Needs json - as root: 'npm install -g json' # https://github.com/zpoley/json-command # # # check_couch_dbs command definition example # # define command{ # command_name check_couch_dbs # command_line $USER1$/check_couch_dbs $ARG1$ $ARG2$ # } # host1=$1 host2=$2 difference_threashold=10 dbs1=`curl -s http://$host1:5984/_all_dbs | json -ga | grep -v -E '_replicator|_users|articles|feeds|fluent' | sort` dbs2=`curl -s http://$host2:5984/_all_dbs | json -ga | grep -v -E '_replicator|_users|articles|feeds|fluent' | sort` dif=`diff -y --suppress-common-lines -b -s <(echo "$dbs1") <(echo "$dbs2")` err="" msg="" exitcode=0 if [[ "$dif" == *identical* ]]; then msg+="Couchdbs lists match" fi if [[ "$dif" == *\<* ]]; then err+="ERROR - db missing from $host2 \n" exitcode=2 fi if [[ "$dif" == *\>* ]]; then err+="ERROR - db missing from $host1 \n" exitcode=2 fi if [[ $exitcode -gt 0 ]]; then echo -e -n $err echo "$dif" err="" # exit $exitcode fi dbs=`echo -e "$dbs1\n$dbs2" | sort | uniq` #echo "$dbs" for db in $dbs; do count1=`curl -s http://$host1:5984/$db | json doc_count` if [ -z "$count1" ]; then continue; fi #no db count2=`curl -s http://$host2:5984/$db | json doc_count` if [ -z "$count2" ]; then continue; fi #no db if [ "$count1" -ne "$count2" ]; then if [ "$count1" -gt "$count2" ]; then difference=$(($count1 - $count2)) else difference=$(($count2 - $count1)) fi if [[ $difference -gt $difference_threashold ]]; then err+="ERROR - $db count difference $host1: $count1 != $host2: $count2 - difference: $difference\n" exitcode=2 else err+="WARNING - $db count difference $host1: $count1 != $host2: $count2 - difference: $difference\n" if [[ $exitcode -lt 1 ]]; then exitcode=1 fi fi fi done if [[ $exitcode -gt 0 ]]; then echo -e -n $err $msg exit $exitcode else echo -e "OK - $msg - doc_count match" exit $exitcode fi
