diff --git a/laborious/metrics.py b/laborious/metrics.py index e8d9063..bcd2d4f 100644 --- a/laborious/metrics.py +++ b/laborious/metrics.py @@ -120,6 +120,18 @@ OPC_CONNECTION_STATUS = Gauge( ['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'], +) + # ================== Model metrics ================== MODEL_READ_LAG = Histogram( diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index a14e89b..f234361 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -170,23 +170,29 @@ class OpcRepository(SientiaMonitoring): } await self.client.connect() + tags = { + 'pod_id': self.pod_id, + 'opc_server_id': self.id, + } + await self.emit_metric( metric_object=metrics.OPC_CONNECTION_STATUS, method='set', - tags={ - 'pod_id': self.pod_id, - 'opc_server_id': self.id, - }, + tags=tags, value=1, ) + await self.emit_metric(metrics.OPC_CONNECTION_COUNT, tags) + return True, {} except Exception as e: - self.disconnect() + await self.disconnect() trace = traceback.format_exc() self.logger.custom_error(trace, self.metadata) + await self.emit_metric(metrics.OPC_CONNECTION_ERROR_COUNT, tags) + return False, { 'notification_id': f'OPC_CONNECTION_ERROR_{self.id}', 'message': f'Failed to connect to OPC server: {e}', diff --git a/values.yaml b/values.yaml index d5faf9b..114a394 100644 --- a/values.yaml +++ b/values.yaml @@ -11,7 +11,7 @@ image: # This sets the pull policy for images. pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. - tag: "1.0.1" + tag: "1.1.0" 0# This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ imagePullSecrets: @@ -151,7 +151,7 @@ env: - name: GITHUB_REPO_URL value: "git@github.com:Aignosi/sientia-dataops-laborious_temporal.git" - name: GITHUB_BRANCH - value: "fix/SIENTIAPDE-1314-ajustes-nas-camadas-de-monitoramento-do-sientia" + value: "feature/SIENTIAPDE-1325-adicionar-metricas-especificas-de-operacoes-externas" - name: PYTHON_APP value: "laborious.worker.worker"