Skip to content

Instantly share code, notes, and snippets.

Created February 24, 2016 07:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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(""):
site = "https://{0}/login".format(site)
site = "http://{0}/login".format(site)
r = requests.head(site)
if r.status_code!=200:
print site, "is down -----"
print site, "is up"
server_sites = {"": ["", ""]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment