Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ProfiT-HPC
aggregator
Commits
ac2c32fd
Commit
ac2c32fd
authored
Dec 27, 2018
by
Azat Khuziyakhmetov
Browse files
fixed json to lineprotocol tool
parent
b02089e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/utils/json2lp.py
View file @
ac2c32fd
...
...
@@ -4,6 +4,8 @@ import argparse
import
json
import
os
DEBUG
=
False
def
load_json
(
fname
):
infile
=
os
.
path
.
abspath
(
fname
)
doc
=
{}
...
...
@@ -16,6 +18,9 @@ def parse_tags(tags_raw):
for
t
in
tags_raw
[
"results"
][
0
][
"series"
][
0
][
"values"
]:
tags
.
append
(
t
[
0
])
if
DEBUG
:
print
(
"Tags in file: "
,
tags
)
return
tags
def
parse_values
(
val_raw
):
...
...
@@ -23,6 +28,10 @@ def parse_values(val_raw):
vals
=
val_raw
[
"results"
][
0
][
"series"
][
0
][
"values"
]
if
DEBUG
:
print
(
"Cols in file:"
,
cols
)
print
(
"Vals in file:"
,
vals
[
0
])
return
cols
,
vals
def
parse_metric
(
tags_raw
,
val_raw
):
...
...
@@ -52,6 +61,11 @@ def sep_columns(tags, cols, val):
def
format_line
(
metric
,
time
,
tags
,
vals
):
if
DEBUG
:
print
(
"metric:"
,
metric
)
print
(
"time:"
,
time
)
print
(
"tags:"
,
tags
)
print
(
"vals:"
,
vals
)
out_tags
=
","
.
join
(
"{:s}={:s}"
.
format
(
t
,
v
)
for
t
,
v
in
tags
.
items
())
out_vals
=
","
.
join
(
"{:s}={:}"
.
format
(
...
...
@@ -64,7 +78,10 @@ def format_line(metric, time, tags, vals):
def
output_line_protocol
(
metric
,
tags
,
cols
,
vals
):
timeidx
=
cols
.
index
(
"time"
)
for
v
in
vals
:
for
k
,
v
in
enumerate
(
vals
):
if
DEBUG
and
k
>
2
:
break
time
=
v
[
timeidx
]
v
[
timeidx
]
=
None
...
...
@@ -74,7 +91,9 @@ def output_line_protocol(metric, tags, cols, vals):
print
(
o
)
# def main(arg
def
main
():
global
DEBUG
parser
=
argparse
.
ArgumentParser
(
description
=
"""
Formats JSON output of InfluxDB to line protocol
"""
)
...
...
@@ -83,12 +102,16 @@ def output_line_protocol(metric, tags, cols, vals):
help
=
"filename of JSON file with values"
)
parser
.
add_argument
(
"-t"
,
"--tags"
,
required
=
True
,
help
=
"filename of JSON file with tag keys"
)
parser
.
add_argument
(
"-d"
,
"--debug"
,
action
=
"store_true"
,
help
=
"debugs the tool. Prints only first 3 points"
)
args
=
parser
.
parse_args
()
values_raw
=
load_json
(
args
.
values
)
tags_raw
=
load_json
(
args
.
tags
)
DEBUG
=
args
.
debug
metric
=
parse_metric
(
tags_raw
,
values_raw
)
tags
=
parse_tags
(
tags_raw
)
...
...
@@ -97,4 +120,4 @@ def output_line_protocol(metric, tags, cols, vals):
output_line_protocol
(
metric
,
tags
,
columns
,
values
)
if
__name__
==
"__main__"
:
main
(
sys
.
argv
[
1
:]
)
main
()
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment