Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metric for expected camera position #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions camera-control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ calendar:
# Default: 604800 (7 days)
cutoff: 604800

# The frequency in which the cameras position should be updated in seconds
# Default: 60
# The frequency in which to re-send the command to move the cameras to the
# desired position in seconds. This ensure the camera position is corrected
# eventually, even if there was an unexpected error.
# Default: 300
camera_update_frequency: 300

# Camera Configuration
Expand Down
4 changes: 3 additions & 1 deletion occameracontrol/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from typing import Optional

from occameracontrol.agent import Agent
from occameracontrol.metrics import register_camera_move
from occameracontrol.metrics import register_camera_move, \
register_camera_expectation


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,6 +78,7 @@ def __str__(self) -> str:
def move_to_preset(self, preset: int):
'''Move the PTZ camera to the specified preset position
'''
register_camera_expectation(self.url, preset)
if self.type == CameraType.panasonic:
params = {'cmd': f'#R{preset - 1:02}', 'res': 1}
url = f'{self.url}/cgi-bin/aw_ptz'
Expand Down
44 changes: 31 additions & 13 deletions occameracontrol/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@

logger = logging.getLogger(__name__)

request_errors = Counter('request_errors',
'Number of errors related to HTTP requests',
('ressource', 'type'))
agent_calendar_update_total = Gauge('agent_calendar_update_total',
'Nuber of calendar update',
('agent',))
agent_calendar_update_time = Gauge('agent_calendar_update_time',
'Time of the last calendar update',
('agent',))
camera_position = Gauge('camera_position',
'Last position (preset number) a camera moved to',
('camera',))
request_errors = Counter(
'request_errors',
'Number of errors related to HTTP requests',
('ressource', 'type'))
agent_calendar_update_total = Gauge(
'agent_calendar_update_total',
'Nuber of calendar update',
('agent',))
agent_calendar_update_time = Gauge(
'agent_calendar_update_time',
'Time of the last calendar update',
('agent',))
camera_position = Gauge(
'camera_position',
'Last position (preset number) a camera moved to',
('camera',))
camera_position_expected = Gauge(
'camera_position_expected',
'The position (preset number) a camera should be in',
('camera',))


class RequestErrorHandler():
Expand Down Expand Up @@ -93,14 +101,24 @@ def register_calendar_update(agent_id: str):

def register_camera_move(camera: str, position: int):
'''Update metrics for when a camera move has happened. This ensures the
position the camera is available as part of the metrics.
position of the camera is available as part of the metrics.

:param camera: Camera identifier
:param position: New camera position
'''
camera_position.labels(camera).set(position)


def register_camera_expectation(camera: str, position: int):
'''Update metrics for when a camera is supposed to move. This ensures the
position the camera is expected in is available as part of the metrics.

:param camera: Camera identifier
:param position: New camera position
'''
camera_position_expected.labels(camera).set(position)


def start_metrics_exporter():
'''Start the web server for the metrics exporter endpoint if it is enabled
in the configuration.
Expand Down
Loading