diff --git a/manifests/monitoringservice.yaml b/manifests/monitoringservice.yaml index 7f0bee9efc68e66c72487624241e763dccb2fc76..44b880fa38565e786cb901e53b875a9946da25a0 100644 --- a/manifests/monitoringservice.yaml +++ b/manifests/monitoringservice.yaml @@ -13,13 +13,14 @@ # limitations under the License. apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: - name: monitoringservice + name: monitoringdb spec: selector: matchLabels: app: monitoringservice + serviceName: "monitoringservice" replicas: 1 template: metadata: @@ -32,35 +33,47 @@ spec: - name: metricsdb image: questdb/questdb ports: - - containerPort: 9000 - - containerPort: 9009 - - containerPort: 9003 + - name: http + containerPort: 9000 + protocol: TCP + - name: influxdb + containerPort: 9009 + protocol: TCP env: - name: QDB_CAIRO_COMMIT_LAG value: "1000" - name: QDB_CAIRO_MAX_UNCOMMITTED_ROWS value: "100000" - readinessProbe: - exec: - command: ["curl", "-XGET", "localhost:9000"] - livenessProbe: - exec: - command: ["curl", "-XGET", "localhost:9003/metrics"] - resources: - requests: - cpu: 250m - memory: 512Mi - limits: - cpu: 700m - memory: 1024Mi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: monitoringserver +spec: + selector: + matchLabels: + app: monitoringservice + replicas: 1 + template: + metadata: + labels: + app: monitoringservice + spec: + terminationGracePeriodSeconds: 5 + restartPolicy: Always + containers: - name: server image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest imagePullPolicy: Always ports: - - containerPort: 7070 + - name: grpc + containerPort: 7070 + protocol: TCP env: + - name: LOG_LEVEL + value: "INFO" - name: METRICSDB_HOSTNAME - value: "localhost" + value: "monitoringservice" - name: METRICSDB_ILP_PORT value: "9009" - name: METRICSDB_REST_PORT @@ -68,19 +81,13 @@ spec: - name: METRICSDB_TABLE value: "monitoring" readinessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:7070"] + grpc: + port: 7070 + initialDelaySeconds: 5 livenessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:7070"] - resources: - requests: - cpu: 250m - memory: 512Mi - limits: - cpu: 700m - memory: 1024Mi - + grpc: + port: 7070 + initialDelaySeconds: 10 --- apiVersion: v1 kind: Service @@ -95,7 +102,11 @@ spec: protocol: TCP port: 7070 targetPort: 7070 - - name: questdb + - name: http protocol: TCP port: 9000 - targetPort: 9000 \ No newline at end of file + targetPort: 9000 + - name: influxdb + protocol: TCP + port: 9009 + targetPort: 9009 \ No newline at end of file diff --git a/src/monitoring/service/MetricsDBTools.py b/src/monitoring/service/MetricsDBTools.py index ea6180aa072bd48a04f26d019ba1e4ab9e08af88..84b4b741a45db8e53e5a702a9ae6b56f6df5579d 100644 --- a/src/monitoring/service/MetricsDBTools.py +++ b/src/monitoring/service/MetricsDBTools.py @@ -17,14 +17,17 @@ import socket import requests import json import sys +import logging + +LOGGER = logging.getLogger(__name__) class MetricsDB(): def __init__(self, host, ilp_port, rest_port, table): - self.socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.host=host - self.ilp_port=ilp_port - self.rest_port=rest_port - self.table=table + self.socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.host=host + self.ilp_port=int(ilp_port) + self.rest_port=rest_port + self.table=table def write_KPI(self,time,kpi_id,kpi_sample_type,device_id,endpoint_id,service_id,kpi_value): self.socket.connect((self.host,self.ilp_port)) @@ -42,11 +45,11 @@ class MetricsDB(): self.socket.close() def run_query(self, sql_query): - query_params = {'query': sql_query, 'fmt' : 'json'} - url = f"http://{self.host}:{self.rest_port}/exec" - try: - response = requests.get(url, params=query_params) - json_response = json.loads(response.text) - print(json_response) - except requests.exceptions.RequestException as e: - print(f'Error: {e}', file=sys.stderr) + query_params = {'query': sql_query, 'fmt' : 'json'} + url = f"http://{self.host}:{self.rest_port}/exec" + try: + response = requests.get(url, params=query_params) + json_response = json.loads(response.text) + LOGGER.info(json_response) + except requests.exceptions.RequestException as e: + LOGGER.info(f'Error: {e}', file=sys.stderr) diff --git a/src/monitoring/service/MonitoringServiceServicerImpl.py b/src/monitoring/service/MonitoringServiceServicerImpl.py index d9f8b1e100bada795f8d6c91a796f458da8d212f..af086dd3127d7e7eeac28142cfbd0187ae3a42ac 100644 --- a/src/monitoring/service/MonitoringServiceServicerImpl.py +++ b/src/monitoring/service/MonitoringServiceServicerImpl.py @@ -59,6 +59,7 @@ class MonitoringServiceServicerImpl(MonitoringServiceServicer): # Set metrics_db client self.metrics_db = MetricsDBTools.MetricsDB(METRICSDB_HOSTNAME,METRICSDB_ILP_PORT,METRICSDB_REST_PORT,METRICSDB_TABLE) + LOGGER.info('MetricsDB initialized') # SetKpi (SetKpiRequest) returns (KpiId) {} def SetKpi(