From 4136c116da386fd540bc7c8388ed73743f85355b Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Fri, 7 Nov 2025 08:37:08 -0300 Subject: [PATCH] SIENTIAPDE-1325 Refactor OPC metrics in metrics.py and opc_repository.py - Replaced existing OPC connection metrics with new metrics for total connections and failed connections. - Updated the OPC connection status metric to include server URL and adjusted corresponding metric emissions in opc_repository.py. --- laborious/metrics.py | 26 +++++++++----------- laborious/utils/repository/opc_repository.py | 4 +-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/laborious/metrics.py b/laborious/metrics.py index bcd2d4f..ec87867 100644 --- a/laborious/metrics.py +++ b/laborious/metrics.py @@ -114,22 +114,20 @@ PREDICTION_OPC_WRITING_RESPONSE_TIME_MONITOR = Histogram( buckets=[0.01, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0], ) +OPC_CONNECTIONS_TOTAL = Counter( + 'opc_connections_initiated_total', + 'Total connection attempts to OPC servers', + ['pod_id', 'server_name'], +) +OPC_CONNECTIONS_FAILED = Counter( + 'opc_connections_failed_total', + 'Total failed connection attempts to OPC servers', + ['pod_id', 'server_name'], +) OPC_CONNECTION_STATUS = Gauge( - 'laborious_opc_connection_status', + 'opc_connection_status', 'Connection status with the OPC server (1=connected, 0=disconnected)', - ['pod_id', 'opc_server_id'], -) - -OPC_CONNECTION_COUNT = Counter( - 'laborious_opc_connection_count', - 'Number of connections to the OPC server', - ['pod_id', 'opc_server_id'], -) - -OPC_CONNECTION_ERROR_COUNT = Counter( - 'laborious_opc_connection_error_count', - 'Number of errors connecting to the OPC server', - ['pod_id', 'opc_server_id'], + ['pod_id', 'server_name', 'server_url'], ) # ================== Model metrics ================== diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index f234361..3afa791 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -182,7 +182,7 @@ class OpcRepository(SientiaMonitoring): value=1, ) - await self.emit_metric(metrics.OPC_CONNECTION_COUNT, tags) + await self.emit_metric(metrics.OPC_CONNECTIONS_TOTAL, tags) return True, {} except Exception as e: @@ -191,7 +191,7 @@ class OpcRepository(SientiaMonitoring): trace = traceback.format_exc() self.logger.custom_error(trace, self.metadata) - await self.emit_metric(metrics.OPC_CONNECTION_ERROR_COUNT, tags) + await self.emit_metric(metrics.OPC_CONNECTIONS_FAILED, tags) return False, { 'notification_id': f'OPC_CONNECTION_ERROR_{self.id}',