Skip to content

Commit

Permalink
Bug fix and improvements
Browse files Browse the repository at this point in the history
Fixed the initialization of the Influxdb client

Added and improved diagnostic messages

Change-Id: Ic8aaa0728a4b936cd4c6e1ed5a0e01ba8f0fb003
  • Loading branch information
Andreas Tsagkaropoulos committed May 16, 2024
1 parent c9109ba commit 73faebe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue May 14 15:38:04 UTC 2024
#Thu May 16 12:31:21 UTC 2024
APP_NAME=default_application
METHOD=exponential_smoothing
INFLUXDB_HOSTNAME=nebulous-influxdb
Expand Down
2 changes: 1 addition & 1 deletion exponential-smoothing-predictor/src/runtime/Predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def sanitize_prediction_statistics(prediction_confidence_interval, prediction_va
confidence_interval_modified = True
if confidence_interval_modified:
new_prediction_confidence_interval = str(lower_value_prediction_confidence_interval)+","+str(upper_value_prediction_confidence_interval)
print_with_time("The confidence interval "+prediction_confidence_interval+"was modified, becoming "+str(new_prediction_confidence_interval)+", taking into account the values of the metric")
print_with_time("The confidence interval "+prediction_confidence_interval+" was modified, becoming "+str(new_prediction_confidence_interval)+", taking into account the values of the metric")
if (prediction_value<lower_bound_value[metric_name]):
print_with_time("The prediction value of " + str(prediction_value) + " for metric " + metric_name + " was sanitized to " + str(lower_bound_value))
prediction_value = lower_bound_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ def update_monitoring_data(self):
print_data_from_db = True
query_string = 'from(bucket: "'+self.influxdb_bucket+'") |> range(start:-'+time_interval_to_get_data_for+') |> filter(fn: (r) => r["_measurement"] == "'+metric_name+'")'
influx_connector = InfluxDBConnector()
print("performing query for application with bucket "+str(self.influxdb_bucket))
logging.info("performing query for application with bucket "+str(self.influxdb_bucket))
logging.info("The body of the query is "+query_string)
logging.info("The configuration of the client is "+Utilities.get_fields_and_values(influx_connector))
current_time = time.time()
result = influx_connector.client.query_api().query(query_string, EsPredictorState.influxdb_organization)
elapsed_time = time.time()-current_time
print("performed query, it took "+str(elapsed_time) + " seconds")
logging.info("performed query, it took "+str(elapsed_time) + " seconds")
#print(result.to_values())
with open(self.get_prediction_data_filename(EsPredictorState.configuration_file_location, metric_name), 'w') as file:
for table in result:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from influxdb_client import InfluxDBClient, Point, WritePrecision
from datetime import datetime
from influxdb_client.client.write_api import SYNCHRONOUS

import logging
from runtime.operational_status.EsPredictorState import EsPredictorState

#import influxdb_client, os, time
Expand Down Expand Up @@ -40,11 +40,11 @@


class InfluxDBConnector:
client = InfluxDBClient(url="http://" + EsPredictorState.influxdb_hostname + ":" + str(EsPredictorState.influxdb_port), token=EsPredictorState.influxdb_token, org=EsPredictorState.influxdb_organization)
write_api = client.write_api(write_options=SYNCHRONOUS)

def InfluxDBConnector(self):
pass
def __init__(self):
self.client = InfluxDBClient(url="http://" + EsPredictorState.influxdb_hostname + ":" + str(EsPredictorState.influxdb_port), token=EsPredictorState.influxdb_token, org=EsPredictorState.influxdb_organization)
self.write_api = self.client.write_api(write_options=SYNCHRONOUS)
logging.info("Successfully created InfluxDB connector, client is "+str(self.client))
def write_data(self,data,bucket):
self.write_api.write(bucket=bucket, org=EsPredictorState.influxdb_organization, record=data, write_precision=WritePrecision.S)

Expand Down
14 changes: 12 additions & 2 deletions exponential-smoothing-predictor/src/runtime/utilities/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#from morphemic.dataset import DatasetMaker
import datetime
import logging,os
from dateutil import parser
import json
from influxdb_client import InfluxDBClient

from runtime.operational_status.EsPredictorState import EsPredictorState
Expand Down Expand Up @@ -42,7 +42,7 @@ def load_configuration():
EsPredictorState.influxdb_password = EsPredictorState.configuration_details.get("INFLUXDB_PASSWORD").data
EsPredictorState.influxdb_org = EsPredictorState.configuration_details.get("INFLUXDB_ORG").data
#This method accesses influx db to retrieve the most recent metric values.

Utilities.print_with_time("The configuration effective currently is the following\n "+Utilities.get_fields_and_values(EsPredictorState))

@staticmethod
def update_influxdb_organization_id():
Expand All @@ -63,3 +63,13 @@ def fix_path_ending(path):
return path
else:
return path + os.sep

@staticmethod
def default_to_string(obj):
return str(obj)
@classmethod
def get_fields_and_values(cls,object):
#Returns those fields that do not start with __ (and their values)
fields_values = {key: value for key, value in object.__dict__.items() if not key.startswith("__")}
return json.dumps(fields_values,indent=4,default=cls.default_to_string)

0 comments on commit 73faebe

Please sign in to comment.