Skip to content
Snippets Groups Projects
Commit 3054b57f authored by Bruce Flynn's avatar Bruce Flynn
Browse files

Example influx insert script

parent 576bc6a7
No related branches found
No related tags found
No related merge requests found
import logging
from datetime import datetime
import requests
from metobs.data import wind_vector_components
from aosstower.l00.parser import read_frames
LOG = logging.getLogger(__name__)
def _mktime(frame):
return int((frame['stamp'] - datetime(1970, 1, 1)).total_seconds() * 10**9)
def frame_records(frame):
nanos = _mktime(frame)
if 'wind_speed' in frame and 'wind_dir' in frame:
spd = frame.pop('wind_speed')
dr = frame.pop('wind_dir')
e, n, _ = wind_vector_components(spd, dr)
frame['wind_east'] = e
frame['wind_north'] = n
for name, value in frame.items():
if name == 'stamp':
continue
valstr = '{}i'.format(value) if isinstance(value, int) else str(value)
yield '{},inst=tower,site=aoss value={} {}'.format(name, valstr, nanos)
def file_records(filepath):
lines = []
for frame in read_frames(filepath):
lines += frame_records(frame)
return lines
def insert(filepath):
LOG.info('reading %s', filepath)
lines = file_records(filepath)
LOG.info("posting %d record from %s...", len(lines), filepath)
resp = requests.post(
'http://bikini.ssec.wisc.edu:8086/write?db=metobs',
data='\n'.join(lines))
resp.raise_for_status()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('asciifile')
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s -- %(message)s')
logging.getLogger('requests').setLevel(logging.WARN)
insert(args.asciifile)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment