diff --git a/README.md b/README.md index a5050f01..2abed0ed 100755 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ Un template est disponible sur le repo [config.yaml](https://github.com/m4dm4rti | discovery_prefix | Préfixe configuré dans Home Assistant pour l'auto-discovery | homeassistant | ### influxdb + +> Version supportée minimun 1.8 + | Champs | Information | Défaut | |------------------|---------------------------------------------------------------|------------------| | enable | Activation ou non des exports vers InfluxDB | False | @@ -123,7 +126,7 @@ Ces 2 propriétés vont vous permettre de jouer sur la rapidité d'importation d #### Configuration par version : -##### v1.X : +##### v1.8 : ```yaml influxdb: enable: 'true' diff --git a/app/main.py b/app/main.py index 2b435617..4b845917 100755 --- a/app/main.py +++ b/app/main.py @@ -67,10 +67,14 @@ INFLUXB_ENABLE = False INFLUXDB = None -if "asynchronous" in INFLUXDB_CONFIG and str2bool(INFLUXDB_CONFIG["asynchronous"]): - write_options = "ASYNCHRONOUS" +if "method" in INFLUXDB_CONFIG: + method = INFLUXDB_CONFIG["method"] else: - write_options = "SYNCHRONOUS" + method = "SYNCHRONOUS" + +write_options = [] +if "batching_options" in INFLUXDB_CONFIG: + write_options = INFLUXDB_CONFIG["batching_options"] if INFLUXDB_CONFIG and "enable" in INFLUXDB_CONFIG and INFLUXDB_CONFIG["enable"]: INFLUXB_ENABLE = True @@ -80,6 +84,7 @@ token=INFLUXDB_CONFIG["token"], org=INFLUXDB_CONFIG["org"], bucket=INFLUXDB_CONFIG["bucket"], + method=method, write_options=write_options ) if CONFIG.get("wipe_influxdb"): diff --git a/app/models/database.py b/app/models/database.py index d587fb70..15247fa1 100644 --- a/app/models/database.py +++ b/app/models/database.py @@ -366,7 +366,6 @@ def set_usage_point(self, usage_point_id, data): self.session.add( UsagePoints( usage_point_id=usage_point_id, - # TODO : Erreur si name est vide name=name, cache=str2bool(cache), consumption=str2bool(consumption), diff --git a/app/models/influxdb.py b/app/models/influxdb.py index 89bcf4a1..893abcc1 100644 --- a/app/models/influxdb.py +++ b/app/models/influxdb.py @@ -13,7 +13,7 @@ class InfluxDB: - def __init__(self, hostname, port, token, org="myelectricaldata.fr", bucket="myelectricaldata", method="batching", + def __init__(self, hostname, port, token, org="myelectricaldata.fr", bucket="myelectricaldata", method="SYNCHRONOUS", write_options=None): if write_options is None: write_options = {} @@ -66,8 +66,8 @@ def __init__(self, hostname, port, token, org="myelectricaldata.fr", bucket="mye self.get_list_retention_policies() if self.retention < 94608000: day = int(self.retention / 60 / 60 / 24) - app.LOG.log([ - f" => ATTENTION, l'InfluxDB est configuré avec une durée de retention de {day} jours.", + app.LOG.warning([ + f" ATTENTION, l'InfluxDB est configuré avec une durée de retention de {day} jours.", f" Toutes les données supérieurs à {day} jours ne seront jamais inséré dans celui-ci." ]) @@ -93,7 +93,9 @@ def connect(self): "https://github.com/m4dm4rtig4n/enedisgateway2mqtt#configuration-file" ]) + app.LOG.log(f" => Methode d'importation : {self.method.upper()}") if self.method.upper() == "ASYNCHRONOUS": + app.LOG.warning(" ATTENTION, le mode d'importation \"ASYNCHRONOUS\" est très consommateur de ressources système.") self.write_api = self.influxdb.write_api(write_options=ASYNCHRONOUS) elif self.method.upper() == "SYNCHRONOUS": self.write_api = self.influxdb.write_api(write_options=SYNCHRONOUS) diff --git a/app/models/query_daily.py b/app/models/query_daily.py index 6c33d330..daeb5f2f 100644 --- a/app/models/query_daily.py +++ b/app/models/query_daily.py @@ -61,8 +61,6 @@ def run(self, begin, end): app.LOG.log(f" => Chargement des données depuis MyElectricalData {begin_str} => {end_str}") data = Query(endpoint=f"{self.url}/{endpoint}/", headers=self.headers).get() blacklist = 0 - from pprint import pprint - pprint(data.text) if hasattr(data, "status_code"): if data.status_code == 200: meter_reading = json.loads(data.text)['meter_reading'] diff --git a/app/models/query_detail.py b/app/models/query_detail.py index 6750b2c0..e30d8ca7 100644 --- a/app/models/query_detail.py +++ b/app/models/query_detail.py @@ -112,15 +112,23 @@ def run(self, begin, end): result = is_between(dateHourMinute, (offpeak_begin, offpeak_stop)) if result: measure_type = "HC" - bulk_insert.append(self.detail_table( + self.db.insert_detail( usage_point_id=self.usage_point_id, date=date, value=value, interval=interval, measure_type=measure_type, - blacklist=0 - )) - self.db.insert_detail_bulk(bulk_insert, self.measure_type) + blacklist=0, + ) + # bulk_insert.append(self.detail_table( + # usage_point_id=self.usage_point_id, + # date=date, + # value=value, + # interval=interval, + # measure_type=measure_type, + # blacklist=0 + # )) + # self.db.insert_detail_bulk(bulk_insert, self.measure_type) return meter_reading["interval_reading"] else: return {