Skip to content

Commit

Permalink
feat: stress_level metric for whisper (#72)
Browse files Browse the repository at this point in the history
* feat: stress_level metric for whisper

* Decrease stress level on disconnect

---------

Co-authored-by: Răzvan Purdel <[email protected]>
  • Loading branch information
aaronkvanmeerten and rpurdel authored Apr 22, 2024
1 parent 7d27db2 commit 2026cdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions skynet/modules/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
subsystem=PROMETHEUS_STREAMING_WHISPER_SUBSYSTEM,
)

TRANSCRIBE_STRESS_LEVEL_METRIC = Gauge(
'stress_level',
documentation='Whisper stress level',
namespace=PROMETHEUS_NAMESPACE,
subsystem=PROMETHEUS_STREAMING_WHISPER_SUBSYSTEM,
)

TRANSCRIBE_CONNECTIONS_COUNTER = Counter(
'LiveWsConnectionsCounter',
documentation='Number of active WS connections',
Expand Down
6 changes: 4 additions & 2 deletions skynet/modules/stt/streaming_whisper/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from fastapi import WebSocket, WebSocketDisconnect

from skynet.auth.jwt import authorize
from skynet.env import bypass_auth
from skynet.env import bypass_auth, whisper_max_connections
from skynet.logs import get_logger
from skynet.modules.monitoring import CONNECTIONS_METRIC, TRANSCRIBE_CONNECTIONS_COUNTER
from skynet.modules.monitoring import CONNECTIONS_METRIC, TRANSCRIBE_CONNECTIONS_COUNTER, TRANSCRIBE_STRESS_LEVEL_METRIC
from skynet.modules.stt.streaming_whisper.meeting_connection import MeetingConnection
from skynet.modules.stt.streaming_whisper.utils import utils

Expand Down Expand Up @@ -35,6 +35,7 @@ async def connect(self, websocket: WebSocket, meeting_id: str, auth_token: str |
loop = asyncio.get_running_loop()
self.flush_audio_task = loop.create_task(self.flush_working_audio_worker())
CONNECTIONS_METRIC.set(len(self.connections))
TRANSCRIBE_STRESS_LEVEL_METRIC.set(len(self.connections)/whisper_max_connections)
TRANSCRIBE_CONNECTIONS_COUNTER.inc()
log.info(f'Meeting with id {meeting_id} started. Ongoing meetings {len(self.connections)}')

Expand Down Expand Up @@ -63,6 +64,7 @@ def disconnect(self, meeting_id: str):
except KeyError:
log.warning(f'The meeting {meeting_id} doesn\'t exist anymore.')
CONNECTIONS_METRIC.set(len(self.connections))
TRANSCRIBE_STRESS_LEVEL_METRIC.set(len(self.connections)/whisper_max_connections)

async def flush_working_audio_worker(self):
"""
Expand Down

0 comments on commit 2026cdb

Please sign in to comment.