separate influxdb write to async routine (test)

This commit is contained in:
avollkopf 2023-03-24 18:58:35 +01:00
parent c4333d2cab
commit 9a8b0ca30f
5 changed files with 21 additions and 13 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.7.a4"
__version__ = "4.1.7.a5"
__codename__ = "Groundhog Day"

View file

@ -7,7 +7,7 @@ from time import strftime, localtime
import pandas as pd
import zipfile
import base64
import urllib3
from urllib3 import Timeout, PoolManager
from pathlib import Path
from cbpi.api import *
from cbpi.api.config import ConfigType
@ -46,16 +46,20 @@ class LogController:
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
self.datalogger[name].info("%s,%s" % (formatted_time, str(value)))
if self.influxdb == "Yes":
## Write to influxdb in an asyncio task
self._task = asyncio.create_task(self.log_influx(name,value))
async def log_influx(self, name:str, value:str):
self.influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", "No")
self.influxdbaddr = self.cbpi.config.get("INFLUXDBADDR", None)
#self.influxdbport = self.cbpi.config.get("INFLUXDBPORT", None)
self.influxdbname = self.cbpi.config.get("INFLUXDBNAME", None)
self.influxdbuser = self.cbpi.config.get("INFLUXDBUSER", None)
self.influxdbpwd = self.cbpi.config.get("INFLUXDBPWD", None)
self.influxdbmeasurement = self.cbpi.config.get("INFLUXDBMEASUREMENT", "measurement")
id = name
timeout = Timeout(connect=5.0, read=None)
try:
sensor=self.cbpi.sensor.find_by_id(name)
if sensor is not None:
@ -68,7 +72,7 @@ class LogController:
self.influxdburl=self.influxdbaddr + "/api/v2/write?org=" + self.influxdbuser + "&bucket=" + self.influxdbname + "&precision=s"
try:
header = {'User-Agent': name, 'Authorization': "Token {}".format(self.influxdbpwd)}
http = urllib3.PoolManager()
http = PoolManager(timeout=timeout)
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
except Exception as e:
logging.error("InfluxDB cloud write Error: {}".format(e))
@ -78,7 +82,7 @@ class LogController:
self.influxdburl= self.influxdbaddr + '/write?db=' + self.influxdbname
try:
header = {'User-Agent': name, 'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % self.base64string.decode('utf-8')}
http = urllib3.PoolManager()
http = PoolManager(timeout=timeout)
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
except Exception as e:
logging.error("InfluxDB write Error: {}".format(e))

View file

@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: cbpi4
Version: 4.1.2
Version: 4.1.7a4
Summary: CraftBeerPi4 Brewing Software
Home-page: http://web.craftbeerpi.com
Author: Manuel Fritsch / Alexander Vollkopf
@ -14,14 +14,14 @@ License-File: LICENSE
# CraftBeerPi 4
[![Build](https://github.com/avollkopf/craftbeerpi4/actions/workflows/build.yml/badge.svg)](https://github.com/avollkopf/craftbeerpi4/actions/workflows/build.yml)
[![GitHub license](https://img.shields.io/github/license/avollkopf/craftbeerpi4)](https://github.com/avollkopf/craftbeerpi4/blob/master/LICENSE)
![GitHub issues](https://img.shields.io/github/issues-raw/avollkopf/craftbeerpi4)
[![Build](https://github.com/PiBrewing/craftbeerpi4/actions/workflows/build.yml/badge.svg)](https://github.com/PiBrewing/craftbeerpi4/actions/workflows/build.yml)
[![GitHub license](https://img.shields.io/github/license/PiBrewing/craftbeerpi4)](https://github.com/PiBrewing/craftbeerpi4/blob/master/LICENSE)
![GitHub issues](https://img.shields.io/github/issues-raw/PiBrewing/craftbeerpi4)
![PyPI](https://img.shields.io/pypi/v/cbpi4)
![Happy Brewing](https://img.shields.io/badge/CraftBeerPi%204-Happy%20Brewing-%23FBB117)
<p align="center">
<img src="https://github.com/avollkopf/craftbeerpi4-ui/blob/main/cbpi4gui/public/logo192.png?raw=true" alt="CraftBeerPi Logo"/>
<img src="https://github.com/PiBrewing/craftbeerpi4-ui/blob/main/cbpi4gui/public/logo192.png?raw=true" alt="CraftBeerPi Logo"/>
</p>
CraftBeerPi 4 is an open source software solution to control the brewing and
@ -50,6 +50,6 @@ For a more detailed description of a development setup without the _development
### Contributors
Thanks to all the people who have contributed
[![contributors](https://contributors-img.web.app/image?repo=avollkopf/craftbeerpi4)](https://github.com/avollkopf/craftbeerpi4/graphs/contributors)
[![contributors](https://contributors-img.web.app/image?repo=PiBrewing/craftbeerpi4)](https://github.com/PiBrewing/craftbeerpi4/graphs/contributors)

View file

@ -158,6 +158,10 @@ cbpi/extension/onewire/__pycache__/__init__.cpython-310.pyc
cbpi/extension/onewire/__pycache__/__init__.cpython-311.pyc
cbpi/extension/onewire/__pycache__/__init__.cpython-37.pyc
cbpi/extension/onewire/__pycache__/__init__.cpython-39.pyc
cbpi/extension/timer/__init__.py
cbpi/extension/timer/config.yaml
cbpi/extension/timer/__pycache__/__init__.cpython-311.pyc
cbpi/extension/timer/__pycache__/__init__.cpython-39.pyc
cbpi/http_endpoints/__init__.py
cbpi/http_endpoints/http_actor.py
cbpi/http_endpoints/http_config.py

View file

@ -7,7 +7,7 @@ aiohttp-session==2.12.0
aiohttp-swagger==1.0.16
aiojobs==1.1.0
aiosqlite==0.17.0
cryptography==36.0.1
cryptography==40.0.0
requests==2.28.1
voluptuous==0.13.1
pyfiglet==0.8.post1