Skip to content
Snippets Groups Projects
Commit 92142ab1 authored by Sergio Gonzalez Diaz's avatar Sergio Gonzalez Diaz
Browse files

Fix "Connection refused" error in QuestDB

parent 54f9b4cd
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -9,13 +9,14 @@ Jinja2==3.0.3 ...@@ -9,13 +9,14 @@ Jinja2==3.0.3
ncclient==0.6.13 ncclient==0.6.13
p4runtime==1.3.0 p4runtime==1.3.0
paramiko==2.9.2 paramiko==2.9.2
influx-line-protocol==0.1.4 # influx-line-protocol==0.1.4
python-dateutil==2.8.2 python-dateutil==2.8.2
python-json-logger==2.0.2 python-json-logger==2.0.2
pytz==2021.3 pytz==2021.3
redis==4.1.2 redis==4.1.2
requests==2.27.1 requests==2.27.1
xmltodict==0.12.0 xmltodict==0.12.0
questdb==1.0.1
# pip's dependency resolver does not take into account installed packages. # pip's dependency resolver does not take into account installed packages.
# p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one # p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one
......
...@@ -12,18 +12,16 @@ ...@@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from influx_line_protocol import Metric from questdb.ingress import Sender, IngressError
import socket
import requests import requests
import json import json
import sys
import logging import logging
import datetime
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
class MetricsDB(): class MetricsDB():
def __init__(self, host, ilp_port, rest_port, table): def __init__(self, host, ilp_port, rest_port, table):
self.socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.host=host self.host=host
self.ilp_port=int(ilp_port) self.ilp_port=int(ilp_port)
self.rest_port=rest_port self.rest_port=rest_port
...@@ -31,19 +29,30 @@ class MetricsDB(): ...@@ -31,19 +29,30 @@ class MetricsDB():
self.create_table() self.create_table()
def write_KPI(self,time,kpi_id,kpi_sample_type,device_id,endpoint_id,service_id,kpi_value): 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)) counter=0
metric = Metric(self.table) number_of_retries=10
metric.with_timestamp(time) while (counter<number_of_retries):
metric.add_tag('kpi_id', kpi_id) try:
metric.add_tag('kpi_sample_type', kpi_sample_type) with Sender(self.host, self.ilp_port) as sender:
metric.add_tag('device_id', device_id) sender.row(
metric.add_tag('endpoint_id', endpoint_id) self.table,
metric.add_tag('service_id', service_id) symbols={
metric.add_value('kpi_value', kpi_value) 'kpi_id': kpi_id,
str_metric = str(metric) 'kpi_sample_type': kpi_sample_type,
str_metric += "\n" 'device_id': device_id,
self.socket.sendall((str_metric).encode()) 'endpoint_id': endpoint_id,
self.socket.close() 'service_id': service_id},
columns={
'kpi_value': kpi_value},
at=datetime.datetime.fromtimestamp(time))
sender.flush()
counter=number_of_retries
LOGGER.info(f"KPI written")
except IngressError as ierr:
# LOGGER.info(ierr)
# LOGGER.info(f"Ingress Retry number {counter}")
counter=counter+1
def run_query(self, sql_query): def run_query(self, sql_query):
query_params = {'query': sql_query, 'fmt' : 'json'} query_params = {'query': sql_query, 'fmt' : 'json'}
......
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