mondogdserverip.com/_status url address provides a dictionary that contains status information of mongodb server. To monitor mongodb, this data is very useful and informative. To retrieve such valuable data, a few lines of code will be enough:
If the mongodb server doesn't require authentication, this data is directly accessed by opening an http process:
If the mongodb server doesn't require authentication, this data is directly accessed by opening an http process:
import urllib2, json
url = "http://ip.to.mongodb.server:28017/_status"
req = urllib2.Request(url)
handle = urllib2.urlopen(req)
raw = handle.read()
status = json.loads(raw)["serverStatus"]
Mongodb allows digest access in case of password login. When authetication is required, you can follow the procedure below:
import requests, json
from requests.auth import HTTPDigestAuth
url = "http://ip.to.mongodb.server:28017/_status"
response = requests.get(url, auth= HTTPDigestAuth(user, pwd))
obj = json.loads(response.content)
status = obj["serverStatus"]
Now, we have status data of mongodb server in python dictionary object format. Effective for the purpose of tuning and checking system health.
Comments
Post a Comment