Site monitoring using python multi-processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from multiprocessing import Pool | |
import time | |
def monitor(server_sites): | |
start_time = time.time() | |
pool = Pool(processes=10) | |
results = [] | |
for server, sites in server_sites.items(): | |
for site in sites: | |
print "queuing {0}".format(site) | |
results.append(pool.apply_async(_get_status, args=(site,))) | |
output = [p.get() for p in results] | |
print '***Done' | |
print "--- %s seconds ---" % round(time.time() - start_time) | |
def _get_status(site): | |
if site.endswith(".erpnext.com"): | |
site = "https://{0}/login".format(site) | |
else: | |
site = "http://{0}/login".format(site) | |
r = requests.head(site) | |
if r.status_code!=200: | |
print site, "is down -----" | |
else: | |
print site, "is up" | |
server_sites = {"someserver.example.com": ["site1.example.com", "site2.example.com"]} | |
monitor(server_sites) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment