Created
December 14, 2022 19:30
-
-
Save jarilammi/6319b2eeb51e4b92d9f17d94db281417 to your computer and use it in GitHub Desktop.
Monitor web server latency with timestamps.
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/env python3 | |
import time | |
import requests | |
from datetime import datetime | |
# URL of the web server to monitor | |
server_url = 'https://innovation.lammi.zone' | |
while True: | |
# Send a request to the server | |
start_time = time.time() | |
response = requests.get(server_url) | |
# Calculate the latency | |
latency = time.time() - start_time | |
# Output the latency data with a timestamp | |
now = datetime.now() | |
timestamp = now.strftime('%Y-%m-%d %H:%M:%S') | |
print(f'[{timestamp}] Latency: {latency:.2f} seconds') | |
# Wait for 10 seconds before sending the next request | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment