diff --git a/camdetect.py b/camdetect.py index dbc755a..ed0ba3f 100755 --- a/camdetect.py +++ b/camdetect.py @@ -47,15 +47,10 @@ counter_tx_events = Counter( counter_eos = Counter( "camtiler_client_eos", "Count of End of Stream occurrences") -counter_timeout_errors = Counter( - "camtiler_client_timeout_errors", - "Upstream connection timeout errors") -counter_cancelled_errors = Counter( - "camtiler_client_cancelled_errors", - "Upstream connection cancelled errors") -counter_incomplete_read_errors = Counter( - "camtiler_client_incomplete_read_errors", - "Upstream incomplete read errors") +counter_connection_errors = Counter( + "camtiler_client_connection_errors", + "Upstream connection errors", + ["error"]) counter_movement_frames = Counter( "camtiler_client_movement_frames", "Frames with movement detected in them") @@ -147,17 +142,16 @@ async def client_connect(resp): async def client(): - print("Opening upstream connection...") - async with aiohttp.ClientSession() as session: - async with session.get(url) as resp: + while True: + async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(connect=5, sock_read=2)) as session: + print("Opening upstream connection to %s" % url) try: - await client_connect(resp) - except asyncio.TimeoutError: - counter_timeout_errors.inc() - except asyncio.CancelledError: - counter_cancelled_errors.inc() - except asyncio.IncompleteReadError: - counter_incomplete_read_errors.inc() + 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() app = Sanic("lease") diff --git a/config/prometheus.yml b/config/prometheus.yml new file mode 100644 index 0000000..806673e --- /dev/null +++ b/config/prometheus.yml @@ -0,0 +1,9 @@ +global: + scrape_interval: 1s + +scrape_configs: + - job_name: camtiler + static_configs: + - targets: + - 127.0.0.1:5000 + diff --git a/mongo-init.sh b/mongo-init.sh new file mode 100644 index 0000000..5dacf7a --- /dev/null +++ b/mongo-init.sh @@ -0,0 +1,11 @@ +#!/bin/bash +mongo <