Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AossTower
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
AossTower
Commits
3054b57f
Commit
3054b57f
authored
8 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
Example influx insert script
parent
576bc6a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/insert_influx.py
+56
-0
56 additions, 0 deletions
scripts/insert_influx.py
with
56 additions
and
0 deletions
scripts/insert_influx.py
0 → 100644
+
56
−
0
View file @
3054b57f
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment