Skip to content

Commit

Permalink
bluemaestro: populate grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Feb 15, 2021
1 parent 1899b00 commit 6d9bc29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 2 additions & 3 deletions misc/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import my.bluemaestro as M

from my.config import bluemaestro as BC
BC.export_path = get_files(BC.export_path)
# BC.export_path = get_files(BC.export_path)[:40]

# print(list(M.measurements())[:10])

print(M.dataframe())

M.fill_influxdb()

ffwf

Expand Down
29 changes: 29 additions & 0 deletions my/bluemaestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,35 @@ def dataframe() -> DataFrameT:
return df.set_index('dt')


def fill_influxdb() -> None:
from itertools import islice
from .core.common import asdict

from influxdb import InfluxDBClient # type: ignore
client = InfluxDBClient()
db = 'db'
mname = __name__.replace('.', '_')
client.delete_series(database=db, measurement=mname)
def dissoc(d, k):
del d[k]
return d # meh
jsons = ({
'measurement': mname,
# todo maybe good idea to tags with database file/name? to inspect inconsistencies etc..
# 'tags': {'activity': e.activity},
'time': e.dt.isoformat(),
'fields': dissoc(asdict(e), 'dt'),
} for e in measurements())
from more_itertools import chunked
# "The optimal batch size is 5000 lines of line protocol."
# some chunking is def necessary, otherwise it fails
for chunk in chunked(jsons, n=5000):
cl = list(chunk)
logger.debug('writing next chunk %s', cl[-1])
client.write_points(cl, database=db)
# todo "Specify timestamp precision when writing to InfluxDB."?


def check() -> None:
temps = list(measurements())
latest = temps[:-2]
Expand Down

0 comments on commit 6d9bc29

Please sign in to comment.