Skip to content

Instantly share code, notes, and snippets.

@anandpdoshi
Created February 24, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandpdoshi/ff00e8aad5aa7ef3b6b6 to your computer and use it in GitHub Desktop.
Save anandpdoshi/ff00e8aad5aa7ef3b6b6 to your computer and use it in GitHub Desktop.
Site monitoring using python multi-processing
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