Last active
October 2, 2018 05:51
-
-
Save cobookman/424670df4c1dca6e5c75a8df7b62e760 to your computer and use it in GitHub Desktop.
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
while true | |
do | |
./test.py >> log.txt | |
done |
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
#!/usr/bin/python3 | |
import requests | |
import datetime | |
import time | |
import sys | |
from google.cloud import bigquery | |
ZONE = "us-central1-a" | |
ENDPOINTS = [ | |
"http://snap-tests-217018.appspot.com/hello", | |
"http://snap-tests-217018.appspot.com/file", | |
] | |
BQ = bigquery.Client() | |
TABLE_REF = BQ.dataset("latency").table("measures") | |
TABLE = BQ.get_table(TABLE_REF) # API request | |
def load_test(endpoint): | |
"""Times latency to hit endpoint & logs into BQ.""" | |
response = requests.get(endpoint) | |
rows = [( | |
ZONE, | |
datetime.datetime.utcnow().isoformat(), | |
response.elapsed.total_seconds(), | |
endpoint)] | |
errors = BQ.insert_rows(TABLE, rows) | |
if len(errors) != 0: | |
print(errors, file=sys.stderr) | |
else: | |
print("probe: %s - %s - %f - %s" % (rows[0][0], rows[0][1], rows[0][2], rows[0][3])) | |
def main(): | |
while True: | |
for endpoint in ENDPOINTS: | |
load_test(endpoint) | |
sys.stdout.flush() | |
sys.stderr.flush() | |
time.sleep(1) | |
if __name__ == "__main__": | |
main() |
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
sudo apt-get update \ | |
&& sudo apt-get upgrade -y \ | |
&& sudo apt-get dist-upgrade \ | |
&& sudo apt-get install python3-pip -y \ | |
&& pip3 install google-cloud-bigquery \ | |
&& wget https://gist.githubusercontent.com/cobookman/424670df4c1dca6e5c75a8df7b62e760/raw/eba0bfec3871089446ce6f31efbf066b83ed150f/forever.sh \ | |
&& wget https://gist.githubusercontent.com/cobookman/424670df4c1dca6e5c75a8df7b62e760/raw/eba0bfec3871089446ce6f31efbf066b83ed150f/test.py \ | |
&& chmod +x * \ | |
&& sudo reboot -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment