scripts/couchdb_check_replication
changeset 10 5183f2628cd2
equal deleted inserted replaced
9:8c143dccc517 10:5183f2628cd2
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: latin1 -*-
       
     3 
       
     4 """
       
     5 CouchDB replication status checker.
       
     6 
       
     7 Checks output of curl _active_tasks and returns number of running replication tasks.
       
     8 Invocation:
       
     9 
       
    10     curl -s -X GET http://localhost:5984/_active_tasks | ./check_replication
       
    11 
       
    12 """
       
    13 
       
    14 import re
       
    15 import simplejson as json
       
    16 import sys
       
    17 
       
    18 try:
       
    19     d = json.load(sys.stdin)
       
    20     cnt = 0
       
    21     for e in d:
       
    22         if e["type"] == "Replication" and re.search("Processed source update", e["status"]):
       
    23             cnt += 1
       
    24     print cnt
       
    25 except Exception:
       
    26     print 0
       
    27 
       
    28 # vim: et:ts=4:sw=4