Report user agent
Some checks failed
continuous-integration/drone Build is failing

This commit is contained in:
Lauri Võsandi 2022-09-04 09:01:22 +03:00
parent 937859c60d
commit 76c99bd568

View File

@ -29,6 +29,9 @@ print("Running with following targets:")
for name, url in targets: for name, url in targets:
print(url) print(url)
GIT_COMMIT = os.getenv("GIT_COMMIT", "null")
GIT_COMMIT_TIMESTAMP = os.getenv("GIT_COMMIT_TIMESTAMP", "null")
counter_dropped_bytes = Counter( counter_dropped_bytes = Counter(
"camtiler_client_dropped_bytes", "camtiler_client_dropped_bytes",
"Bytes that were not not handled or part of actual JPEG frames") "Bytes that were not not handled or part of actual JPEG frames")
@ -54,6 +57,13 @@ counter_errors = Counter(
"camtiler_errors", "camtiler_errors",
"Upstream connection errors", "Upstream connection errors",
["exception"]) ["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") app = Sanic("camtiler")
@ -143,9 +153,15 @@ async def client_connect(name, resp):
async def client(name, url): async def client(name, url):
print("Opening upstream connection to %s" % 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: while True:
app.ctx.frames[name] = None 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: try:
async with session.get(url) as resp: async with session.get(url) as resp:
await client_connect(name, resp) await client_connect(name, resp)