Compare commits

..

No commits in common. "72336a3f4ac7fc803c8ace21258e925a86a93b11" and "755b70475a5ab8f49dadd5218e357a38461e1db3" have entirely different histories.

5 changed files with 26 additions and 46 deletions

View File

@ -1,22 +1,18 @@
version: "3" version: "2"
services: services:
import: import:
build: importer build: importer
image: docker.clkl.de/weather/import:0.3 image: docker.clkl.de/weather/import:0.2
environment:
- PYTHONUNBUFFERED=1
- TF_HOST=192.168.2.160
- TF_PORT=4223
- TF_ID=DYC
- INFLUXDB_DB=mydb
influxdb: influxdb:
image: influxdb:1.7-alpine image: influxdb:1.5-alpine
command: influxd -config /etc/influxdb/influxdb.conf command: influxd -config /etc/influxdb/influxdb.conf
ports:
- "8086:8086"
volumes: volumes:
- "./influxdb/:/var/lib/influxdb" - "./influxdb/:/var/lib/influxdb"
environment: environment:
- INFLUXDB_DB=mydb # Y U NO WORK?! - INFLUXDB_DB=mydb
#- INFLUXDB_USER=user #- INFLUXDB_USER=user
#- INLFUXDB_USER_PASSWORD=<secret> #- INLFUXDB_USER_PASSWORD=<secret>
grafana: grafana:
@ -24,7 +20,5 @@ services:
ports: ports:
- "3000:3000" - "3000:3000"
volumes: volumes:
# - "./grafana_etc/:/etc/grafana/"
- "./grafana_lib/:/var/lib/grafana/" - "./grafana_lib/:/var/lib/grafana/"
# docker-compose exec influxdb influx_inspect export -database mydb -out /var/lib/influxdb/backup-text-dump -datadir /var/lib/influxdb/data -waldir /var/lib/influxdb/wal

View File

@ -1,4 +1,4 @@
FROM python:3.7-alpine FROM python:3.7-rc-alpine
WORKDIR /app WORKDIR /app

View File

@ -1,8 +1,11 @@
HOST = "192.168.2.110"
PORT = 4223
UID = "DYC"
URL = "http://192.168.2.30:8086/write?db=mydb"
import logging import logging
import time import time
from os import getenv
import requests import requests
from tinkerforge.ip_connection import IPConnection from tinkerforge.ip_connection import IPConnection
@ -10,32 +13,22 @@ from tinkerforge.bricklet_outdoor_weather import BrickletOutdoorWeather
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def asdf(type, identifier, **kwargs):
HOST = getenv("TF_HOST", "192.168.2.160") log.info(type, identifier, kwargs)
PORT = int(getenv("TF_PORT", 4223))
UID = getenv("TF_ID", "DYC")
URL = getenv("INFLUX_URL", "http://influxdb:8086)
DB = getenv("INFLUXDB_DB", "mydb")
def influx(type, identifier, **kwargs):
log.info(f"{type}, {identifier}, {kwargs}")
time_ns = time.time_ns() time_ns = time.time_ns()
data = [] data = []
for unit in kwargs: for unit in kwargs:
data.append(f"{unit},type={type},identifier={identifier} value={kwargs[unit]} {time_ns}") data.append(f"{unit},type={type},identifier={identifier} value={kwargs[unit]} {time_ns}")
try: try:
url = f"{URL}/write?db={DB}" r = requests.post(URL, data="\n".join(data))
r = requests.post(url, data="\n".join(data)) log.info(r, r.text)
log.info(f"{r}, {r.text}")
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
def cb_station(identifier, temperature, humidity, wind_speed, gust_speed, rain, wind_direction, battery_low): def cb_station(identifier, temperature, humidity, wind_speed, gust_speed, rain, wind_direction, battery_low):
influx(type="station", identifier=identifier, temperature=temperature, humidity=humidity, wind_speed=wind_speed, gust_speed=gust_speed, rain=rain, wind_direction=wind_direction, battery_low=battery_low) asdf(type="station", identifier=identifier, temperature=temperature, humidity=humidity, wind_speed=wind_speed, gust_speed=gust_speed, rain=rain, wind_direction=wind_direction, battery_low=battery_low)
def cb_sensor(identifier, temperature, humidity): def cb_sensor(identifier, temperature, humidity):
influx(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity) asdf(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
@ -47,8 +40,6 @@ if __name__ == "__main__":
ow.set_sensor_callback_configuration(True) ow.set_sensor_callback_configuration(True)
ow.register_callback(ow.CALLBACK_STATION_DATA, cb_station) ow.register_callback(ow.CALLBACK_STATION_DATA, cb_station)
ow.register_callback(ow.CALLBACK_SENSOR_DATA, cb_sensor) ow.register_callback(ow.CALLBACK_SENSOR_DATA, cb_sensor)
log.info("try to create influx db…")
requests.post(f"{URL}/query?q=CREATE DATABASE {DB}")
log.info("now we play the waiting game…") log.info("now we play the waiting game…")
while True: while True:
try: try:

View File

@ -14,6 +14,6 @@ def update(start, end):
if __name__ == "__main__": if __name__ == "__main__":
start = dt(2018, 8 , 3) start = dt(2018, 8 , 1)
end = dt(2018, 8 , 3) end = dt(2018, 8 , 1)
update(start, end) update(start, end)

View File

@ -54,17 +54,12 @@ def auth_from_env():
def ssh_from_env(): def ssh_from_env():
return SSHConfig(user=os.getenv("SSH_USER"), password=os.getenv("SSH_PASSWORD"), host=os.getenv("SSH_HOST"), port=os.getenv("SSH_PORT", 22), dir=os.getenv("SSH_DIR", "/")) return SSHConfig(user=os.getenv("SSH_USER"), password=os.getenv("SSH_PASSWORD"), host=os.getenv("SSH_HOST"), port=os.getenv("SSH_PORT", 22), dir=os.getenv("SSH_DIR", "/"))
def update(save=False): def update():
log.info("run update") log.info("run update")
try: auth = auth_from_env()
auth = auth_from_env() config = ssh_from_env()
config = ssh_from_env() _update(auth, config)
_update(auth, config)
except Exception as e:
if save:
log.e(e)
else:
raise e
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')