Loading .gitignore +3 −0 Original line number Diff line number Diff line Loading @@ -162,3 +162,6 @@ cython_debug/ # TeraFlowSDN-generated files tfs_runtime_env_vars.sh delete_local_deployment.sh local_docker_deployment.sh local_k8s_deployment.sh src/monitoring/.gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ unit test monitoring: - docker pull questdb/questdb - docker run --name questdb -d -p 9000:9000 -p 9009:9009 -p 8812:8812 -p 9003:9003 -e QDB_CAIRO_COMMIT_LAG=1000 -e QDB_CAIRO_MAX_UNCOMMITTED_ROWS=100000 --network=teraflowbridge --rm questdb/questdb - sleep 10 - docker run --name $IMAGE_NAME -d -p 7070:7070 --env METRICSDB_HOSTNAME=localhost --env METRICSDB_ILP_PORT=9009 --env METRICSDB_REST_PORT=9000 --env METRICSDB_TABLE=monitoring -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker run --name $IMAGE_NAME -d -p 7070:7070 --env METRICSDB_HOSTNAME=questdb --env METRICSDB_ILP_PORT=9009 --env METRICSDB_REST_PORT=9000 --env METRICSDB_TABLE=monitoring -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - sleep 30 - docker ps -a - docker logs $IMAGE_NAME Loading src/monitoring/service/MetricsDBTools.py +17 −6 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class MetricsDB(): self.ilp_port=int(ilp_port) self.rest_port=rest_port self.table=table self.create_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)) Loading @@ -47,9 +48,19 @@ class MetricsDB(): 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) LOGGER.info(json_response) except requests.exceptions.RequestException as e: LOGGER.info(f'Error: {e}', file=sys.stderr) LOGGER.info(f"Query executed, result:{json_response}") def create_table(self): query = f'CREATE TABLE IF NOT EXISTS {self.table}'\ '(kpi_id SYMBOL,'\ 'kpi_sample_type SYMBOL,'\ 'device_id SYMBOL,'\ 'endpoint_id SYMBOL,'\ 'service_id SYMBOL,'\ 'timestamp TIMESTAMP,'\ 'kpi_value DOUBLE)'\ 'TIMESTAMP(timestamp);' self.run_query(query) LOGGER.info(f"Table {self.table} created") Loading
.gitignore +3 −0 Original line number Diff line number Diff line Loading @@ -162,3 +162,6 @@ cython_debug/ # TeraFlowSDN-generated files tfs_runtime_env_vars.sh delete_local_deployment.sh local_docker_deployment.sh local_k8s_deployment.sh
src/monitoring/.gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ unit test monitoring: - docker pull questdb/questdb - docker run --name questdb -d -p 9000:9000 -p 9009:9009 -p 8812:8812 -p 9003:9003 -e QDB_CAIRO_COMMIT_LAG=1000 -e QDB_CAIRO_MAX_UNCOMMITTED_ROWS=100000 --network=teraflowbridge --rm questdb/questdb - sleep 10 - docker run --name $IMAGE_NAME -d -p 7070:7070 --env METRICSDB_HOSTNAME=localhost --env METRICSDB_ILP_PORT=9009 --env METRICSDB_REST_PORT=9000 --env METRICSDB_TABLE=monitoring -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker run --name $IMAGE_NAME -d -p 7070:7070 --env METRICSDB_HOSTNAME=questdb --env METRICSDB_ILP_PORT=9009 --env METRICSDB_REST_PORT=9000 --env METRICSDB_TABLE=monitoring -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - sleep 30 - docker ps -a - docker logs $IMAGE_NAME Loading
src/monitoring/service/MetricsDBTools.py +17 −6 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class MetricsDB(): self.ilp_port=int(ilp_port) self.rest_port=rest_port self.table=table self.create_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)) Loading @@ -47,9 +48,19 @@ class MetricsDB(): 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) LOGGER.info(json_response) except requests.exceptions.RequestException as e: LOGGER.info(f'Error: {e}', file=sys.stderr) LOGGER.info(f"Query executed, result:{json_response}") def create_table(self): query = f'CREATE TABLE IF NOT EXISTS {self.table}'\ '(kpi_id SYMBOL,'\ 'kpi_sample_type SYMBOL,'\ 'device_id SYMBOL,'\ 'endpoint_id SYMBOL,'\ 'service_id SYMBOL,'\ 'timestamp TIMESTAMP,'\ 'kpi_value DOUBLE)'\ 'TIMESTAMP(timestamp);' self.run_query(query) LOGGER.info(f"Table {self.table} created")