Improved error handling
continuous-integration/drone Build is passing Details

This commit is contained in:
Lauri Võsandi 2022-02-13 19:53:47 +02:00 committed by Lauri Võsandi
parent d2f37ec192
commit c3f225847a
3 changed files with 33 additions and 19 deletions

View File

@ -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:
async with session.get(url) as resp:
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()
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")

9
config/prometheus.yml Normal file
View File

@ -0,0 +1,9 @@
global:
scrape_interval: 1s
scrape_configs:
- job_name: camtiler
static_configs:
- targets:
- 127.0.0.1:5000

11
mongo-init.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
mongo <<EOF
rs.initiate({
_id: 'rs0',
members: [
{_id: 0, host: '127.0.0.1:27017'}
]
})
EOF