Last active
December 15, 2015 23:49
-
-
Save keiya/5342889 to your computer and use it in GitHub Desktop.
this script checks the health status of the http server periodically. health report will be write out as csv format: ISO-8601,HTTP_STATUS_CODE,RESPONSE_TIME_MICROSEC USAGE:
$ python3 -u http_heartbeat.py | tee ~/hb.log
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
| #!/usr/bin/python | |
| import pprint,http.client,sys | |
| from datetime import datetime | |
| from time import sleep | |
| if (len(sys.argv) != 2) : | |
| print ( "Usage: python3 {0} host" .format(sys.argv[0]) ) | |
| quit() | |
| while 1: | |
| conn = http.client.HTTPConnection( sys.argv[1] ) | |
| start = datetime.now() | |
| conn.request("GET","/") | |
| res = conn.getresponse() | |
| end = datetime.now() | |
| duration = (end-start).microseconds | |
| timestamp = start.strftime("%Y-%m-%dT%H:%M:%S") | |
| if res.status == 200 : | |
| print (timestamp + "," + str(res.status) + "," + str(duration)) | |
| else : | |
| print (timestamp + "," + str(res.status) + "," + str(duration)) | |
| conn.close | |
| sleep(60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment