Skip to content

Instantly share code, notes, and snippets.

@jarilammi
Created December 14, 2022 19:30
Show Gist options
  • Save jarilammi/6319b2eeb51e4b92d9f17d94db281417 to your computer and use it in GitHub Desktop.
Save jarilammi/6319b2eeb51e4b92d9f17d94db281417 to your computer and use it in GitHub Desktop.
Monitor web server latency with timestamps.
#!/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