Skip to content
Snippets Groups Projects
Commit d646caf9 authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

Merge branch 'feat/monitoring' into fix/ofc22-tests

parents 2dcc49de c2b7ad7d
No related branches found
No related tags found
1 merge request!54Release 2.0.0
......@@ -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
......@@ -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
......
......@@ -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))
......@@ -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)
response = requests.get(url, params=query_params)
json_response = json.loads(response.text)
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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment