arbtt: feed data to influxdb
This commit is contained in:
parent
ca4d58e4e7
commit
0585cc4a89
3 changed files with 26 additions and 4 deletions
14
my/arbtt.py
14
my/arbtt.py
|
@ -88,6 +88,20 @@ def entries() -> Iterable[Entry]:
|
|||
yield Entry(json=json)
|
||||
|
||||
|
||||
def fill_influxdb() -> None:
|
||||
from .core.influxdb import magic_fill
|
||||
from .core.types import Freezer
|
||||
freezer = Freezer(Entry)
|
||||
fit = (freezer.freeze(e) for e in entries())
|
||||
# TODO crap, influxdb doesn't like None https://github.com/influxdata/influxdb/issues/7722
|
||||
# wonder if can check it statically/warn?
|
||||
fit = (f for f in fit if f.active is not None)
|
||||
|
||||
# todo could tag with computer name or something...
|
||||
# todo should probably also tag with 'program'?
|
||||
magic_fill(fit, name=f'{entries.__module__}:{entries.__name__}')
|
||||
|
||||
|
||||
from .core import stat, Stats
|
||||
def stats() -> Stats:
|
||||
return stat(entries)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
'''
|
||||
TODO doesn't really belong to 'core' morally, but can think of moving out later
|
||||
'''
|
||||
from .common import assert_subpackage; assert_subpackage(__name__)
|
||||
|
||||
from typing import Iterable, Any, Optional, Dict
|
||||
|
||||
from .common import LazyLogger, asdict, Json
|
||||
|
@ -84,13 +86,17 @@ def fill(it: Iterable[Any], *, measurement: str, reset: bool=False, dt_col: str=
|
|||
# todo "Specify timestamp precision when writing to InfluxDB."?
|
||||
|
||||
|
||||
def magic_fill(it) -> None:
|
||||
assert callable(it)
|
||||
name = f'{it.__module__}:{it.__name__}'
|
||||
def magic_fill(it, *, name: Optional[str]=None) -> None:
|
||||
if name is None:
|
||||
assert callable(it) # generators have no name/module
|
||||
name = f'{it.__module__}:{it.__name__}'
|
||||
assert name is not None
|
||||
|
||||
if callable(it):
|
||||
it = it()
|
||||
|
||||
from itertools import tee
|
||||
from more_itertools import first, one
|
||||
it = it()
|
||||
it, x = tee(it)
|
||||
f = first(x, default=None)
|
||||
if f is None:
|
||||
|
|
|
@ -66,6 +66,8 @@ def test_freezer() -> None:
|
|||
###
|
||||
|
||||
# TODO shit. what to do with exceptions?
|
||||
# e.g. good testcase is date parsing issue. should def yield Exception in this case
|
||||
# fundamentally it should just be Exception aware, dunno
|
||||
#
|
||||
# TODO not entirely sure if best to use Frozen as the schema, or actually convert objects..
|
||||
# guess need to experiment and see
|
||||
|
|
Loading…
Add table
Reference in a new issue