From 76c99bd568115d155e03dcc795aa78767bc3cbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sun, 4 Sep 2022 09:01:22 +0300 Subject: [PATCH] Report user agent --- camtiler.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/camtiler.py b/camtiler.py index 7b201e2..50d8925 100755 --- a/camtiler.py +++ b/camtiler.py @@ -29,6 +29,9 @@ print("Running with following targets:") for name, url in targets: print(url) +GIT_COMMIT = os.getenv("GIT_COMMIT", "null") +GIT_COMMIT_TIMESTAMP = os.getenv("GIT_COMMIT_TIMESTAMP", "null") + counter_dropped_bytes = Counter( "camtiler_client_dropped_bytes", "Bytes that were not not handled or part of actual JPEG frames") @@ -54,6 +57,13 @@ counter_errors = Counter( "camtiler_errors", "Upstream connection errors", ["exception"]) +gauge_build_info = Gauge( + "docker_build_info", + "Build info", + ["git_commit", "git_commit_timestamp"]) +gauge_build_info.labels( + GIT_COMMIT, + GIT_COMMIT_TIMESTAMP).set(1) app = Sanic("camtiler") @@ -143,9 +153,15 @@ async def client_connect(name, resp): async def client(name, url): print("Opening upstream connection to %s" % url) + kwargs = dict( + headers = { + "User-Agent": "camtiler/%s" % GIT_COMMIT_TIMESTAMP + }, + skip_auto_headers = True, + timeout = aiohttp.ClientTimeout(connect=5, sock_read=2)) while True: app.ctx.frames[name] = None - async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(connect=5, sock_read=2)) as session: + async with aiohttp.ClientSession(**kwargs) as session: try: async with session.get(url) as resp: await client_connect(name, resp)