Even more generalized exception handling
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Lauri Võsandi 2022-02-13 22:02:51 +02:00 committed by Lauri Võsandi
parent c3f225847a
commit 8cef6d853f

View File

@ -27,39 +27,36 @@ THRESHOLD_BLOCKS = 20
THRESHOLD_MOTION_START = 2
counter_dropped_bytes = Counter(
"camtiler_client_dropped_bytes",
"camdetect_dropped_bytes",
"Bytes that were not not handled or part of actual JPEG frames")
counter_rx_bytes = Counter(
"camtiler_client_rx_bytes",
"camdetect_rx_bytes",
"Bytes received over HTTP stream")
counter_tx_bytes = Counter(
"camtiler_client_tx_bytes",
"camdetect_tx_bytes",
"Bytes transmitted over HTTP streams")
counter_rx_frames = Counter(
"camtiler_client_rx_frames",
"camdetect_rx_frames",
"Frames received")
counter_tx_frames = Counter(
"camtiler_client_tx_frames",
"camdetect_tx_frames",
"Frames transmitted")
counter_tx_events = Counter(
"camtiler_client_tx_events",
"camdetect_tx_events",
"Events emitted")
counter_eos = Counter(
"camtiler_client_eos",
"Count of End of Stream occurrences")
counter_connection_errors = Counter(
"camtiler_client_connection_errors",
counter_errors = Counter(
"camdetect_errors",
"Upstream connection errors",
["error"])
["exception"])
counter_movement_frames = Counter(
"camtiler_client_movement_frames",
"camdetect_movement_frames",
"Frames with movement detected in them")
gauge_total_blocks = Gauge(
"camtiler_client_total_blocks",
"camdetect_total_blocks",
"Total DCT blocks")
gauge_active_blocks = Gauge(
"camtiler_client_active_blocks",
"camdetect_active_blocks",
"Total active, threshold exceeding DCT blocks")
class Frame(object):
@ -148,10 +145,11 @@ async def client():
try:
async with session.get(url) as resp:
await client_connect(resp)
except aiohttp.ClientConnectorError as e:
counter_connection_errors.labels(error=e.strerror).inc()
except asyncio.exceptions.TimeoutError:
counter_connection_errors.labels(error="Timeout").inc()
except (aiohttp.ClientError, asyncio.exceptions.TimeoutError) as e:
j = "%s.%s" % (e.__class__.__module__, e.__class__.__name__)
print("Caught exception %s" % j)
counter_errors.labels(exception=j).inc()
await asyncio.sleep(1)
app = Sanic("lease")