Initial commit
This commit is contained in:
commit
fb4589a696
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
*.swp
|
||||||
|
venv/*
|
||||||
|
*.pyc
|
||||||
|
__pycache__/*
|
||||||
|
__pycache__
|
||||||
|
*.wpr
|
||||||
|
.idea/
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
ADD requirements.txt /app/
|
||||||
|
WORKDIR /app/
|
||||||
|
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
ADD app.py /app/
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]
|
57
reporter.py
Normal file
57
reporter.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
import requests
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||||
|
|
||||||
|
|
||||||
|
def run_report_task(hostname: str, test_urls: list, report_urls:list):
|
||||||
|
for test_url in test_urls:
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
try:
|
||||||
|
r = requests.get(test_url, timeout=10)
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
print(test_url, "Timed out")
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
latency_s = time.time() - start_time
|
||||||
|
|
||||||
|
if r.status_code != 204:
|
||||||
|
print(test_url, "Wrong response")
|
||||||
|
continue
|
||||||
|
|
||||||
|
report = {
|
||||||
|
"client": hostname,
|
||||||
|
"cloud": test_url,
|
||||||
|
"measurements": {
|
||||||
|
"latency": latency_s * 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for report_url in report_urls:
|
||||||
|
r = requests.post(report_url, json=report)
|
||||||
|
|
||||||
|
if r.status_code != 201:
|
||||||
|
print(report_url, "Wrong response")
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
test_urls = os.environ.get("TEST_URLS", "").split(';')
|
||||||
|
report_urls = os.environ.get("REPORT_URLS", "").split(';')
|
||||||
|
frequency = float(os.environ.get("FREQUENCY", 15))
|
||||||
|
|
||||||
|
if (not test_urls) or (not report_urls):
|
||||||
|
print("No urls defined")
|
||||||
|
return
|
||||||
|
|
||||||
|
hostname = os.environ['HOSTNAME']
|
||||||
|
|
||||||
|
scheduler = BlockingScheduler()
|
||||||
|
scheduler.add_job(lambda: run_report_task(hostname, test_urls, report_urls), trigger='interval', seconds=frequency)
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
requests
|
||||||
|
apscheduler
|
Loading…
Reference in New Issue
Block a user