Commit 12a3a5d5 authored by Rousseau Vincent's avatar Rousseau Vincent
Browse files

Enable python log and fix query to csv duration

parent 93675829
No related merge requests found
Showing with 18 additions and 9 deletions
+18 -9
......@@ -7,4 +7,4 @@ COPY requirements.txt /usr/src/app
RUN python3 -m pip install -r requirements.txt
COPY influx_to_csv.py /usr/src/app
CMD ["python3", "/usr/src/app/influx_to_csv.py"]
\ No newline at end of file
CMD ["python3", "-u", "/usr/src/app/influx_to_csv.py"]
\ No newline at end of file
......@@ -3,34 +3,40 @@ import os
from datetime import datetime, timedelta
from pathlib import Path
import csv
from influxdb import InfluxDBClient
from random import uniform
# Start sensors at different time after
time.sleep(uniform(10,60))
print('Starting influx_to_csv')
influx_host = os.getenv("INFLUX_HOST", "localhost")
influx_client = InfluxDBClient(host=influx_host, database="multi-sense")
write_time_interval = 60
start_time = datetime.utcnow()
begin = start_time - timedelta(seconds=100)
begin = start_time - timedelta(seconds=3*write_time_interval)
end = begin + timedelta(seconds=write_time_interval)
csv_folder_path = os.getenv("CSV_FOLDER_PATH", "./data")
data_folder = Path(csv_folder_path)
data_folder.mkdir(parents=True, exist_ok=True)
measurement = 'bme280'
while True:
begin += timedelta(seconds=write_time_interval)
end += timedelta(seconds=write_time_interval)
query = 'select * from "bme280" where time > \'' + begin.isoformat() + "Z' AND time <= '" + end.isoformat() + "Z' tz('Europe/Paris')"
query = 'select * from "' + measurement + '" where time > \'' + begin.isoformat() + "Z' AND time <= '" + end.isoformat() + "Z' tz('Europe/Paris')"
result = influx_client.query(query, epoch="ms")
#print(query)
try:
n = next(result.get_points())
except StopIteration:
print('Influxdb result query is empty')
else:
file_date = datetime.now().strftime('%Y_%m_%d_%H_%M')
file_name = data_folder/str('bme280_' + file_date + '.csv')
file_date = datetime.now().strftime('%Y_%m_%d')
file_name = data_folder/str(measurement + '_' + file_date + '.csv')
with file_name.open('a') as csvfile:
fieldnames = list(next(result.get_points()).keys())
writer = csv.DictWriter(csvfile, fieldnames)
......
......@@ -7,4 +7,4 @@ COPY requirements.txt /usr/src/app
RUN python3 -m pip install -r requirements.txt
COPY ads1115_influx.py /usr/src/app
CMD ["python3", "/usr/src/app/ads1115_influx.py"]
\ No newline at end of file
CMD ["python3", "-u", "/usr/src/app/ads1115_influx.py"]
\ No newline at end of file
......@@ -8,6 +8,7 @@ from random import uniform
# Start sensors at different time after
time.sleep(uniform(10,60))
print('Starting ads1115')
influx_host = os.getenv('INFLUX_HOST', 'localhost')
influx_dbname = os.getenv('INFLUX_DBNAME', 'multi-sense')
......
......@@ -7,4 +7,4 @@ COPY requirements.txt /usr/src/app
RUN python3 -m pip install -r requirements.txt
COPY bme280_influx.py /usr/src/app
CMD ["python3", "/usr/src/app/bme280_influx.py"]
CMD ["python3", "-u", "/usr/src/app/bme280_influx.py"]
......@@ -7,6 +7,7 @@ from random import uniform
# Start sensors at different time after
time.sleep(uniform(10,60))
print('Starting bme280')
influx_host = os.getenv('INFLUX_HOST', 'localhost')
influx_dbname = os.getenv('INFLUX_DBNAME', 'multi-sense')
......
......@@ -7,4 +7,4 @@ COPY requirements.txt /usr/src/app
RUN python3 -m pip install -r requirements.txt
COPY cpu_load.py /usr/src/app
CMD ["python3", "/usr/src/app/cpu_load.py"]
\ No newline at end of file
CMD ["python3", "-u", "/usr/src/app/cpu_load.py"]
\ No newline at end of file
......@@ -6,6 +6,7 @@ from random import uniform
# Start sensors at different time after
time.sleep(uniform(10,60))
print('Starting cpu_load')
influx_host = os.getenv('INFLUX_HOST', 'localhost')
influx_dbname = os.getenv('INFLUX_DBNAME', 'multi-sense')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment