Initial Adaptive Music v0.5.0 release
This commit is contained in:
commit
14f0d8c26b
114 files changed
+6907
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"""Explicitly invoked, read-only unauthenticated diagnostics; raw data stays private."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
return None
|
||||
|
||||
|
||||
def probe(base_url: str) -> list[dict]:
|
||||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
|
||||
results = []
|
||||
for path in ('/', '/info'):
|
||||
start = time.monotonic()
|
||||
result = {'path': path}
|
||||
try:
|
||||
req = urllib.request.Request(base_url.rstrip('/') + path, method='GET')
|
||||
with opener.open(req, timeout=5) as response:
|
||||
body = response.read(65536)
|
||||
result.update(status=response.status,
|
||||
content_type=response.headers.get('content-type'),
|
||||
bytes=len(body))
|
||||
# Deliberately do not log bodies, Location headers, URLs or exception text.
|
||||
except urllib.error.HTTPError as exc:
|
||||
result['status'] = exc.code
|
||||
except (OSError, urllib.error.URLError) as exc:
|
||||
result.update(error_type=type(exc).__name__,
|
||||
reason_type=type(getattr(exc, 'reason', None)).__name__)
|
||||
result['elapsed_seconds'] = round(time.monotonic() - start, 2)
|
||||
results.append(result)
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
config = json.loads((ROOT / '.local/environment.json').read_text())
|
||||
print(json.dumps(probe(config['ma_url']), indent=2))
|
||||
Reference in new issue
Block a user