Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2374d098
Commit
2374d098
authored
Oct 17, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed query parsing bugs
parent
ace81760
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
55 deletions
+61
-55
pkg/tsdb/opentsdb/opentsdb.go
+61
-55
No files found.
pkg/tsdb/opentsdb/opentsdb.go
View file @
2374d098
...
...
@@ -60,61 +60,8 @@ func (e *OpenTsdbExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
tsdbQuery
.
Queries
=
make
([]
map
[
string
]
interface
{},
len
(
queries
))
for
i
:=
0
;
i
<
len
(
queries
);
i
++
{
metric
:=
make
(
map
[
string
]
interface
{})
// Setting metric and aggregator
metric
[
"metric"
]
=
queries
[
i
]
.
Model
.
Get
(
"metric"
)
.
MustString
()
metric
[
"aggregator"
]
=
queries
[
i
]
.
Model
.
Get
(
"aggregator"
)
.
MustString
()
// Setting downsampling options
disableDownsampling
:=
queries
[
i
]
.
Model
.
Get
(
"disableDownsampling"
)
.
MustBool
()
if
!
disableDownsampling
{
downsampleInterval
:=
queries
[
i
]
.
Model
.
Get
(
"downsampleInterval"
)
.
MustString
()
if
downsampleInterval
==
""
{
downsampleInterval
=
"1m"
//default value for blank
}
downsample
:=
downsampleInterval
+
"-"
+
queries
[
i
]
.
Model
.
Get
(
"downsampleAggregator"
)
.
MustString
()
if
queries
[
i
]
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
!=
"none"
{
metric
[
"downsample"
]
=
downsample
+
"-"
+
queries
[
i
]
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
}
}
// Setting rate options
if
queries
[
i
]
.
Model
.
Get
(
"shouldComputeRate"
)
.
MustBool
()
{
metric
[
"rate"
]
=
true
rateOptions
:=
make
(
map
[
string
]
interface
{})
rateOptions
[
"counter"
]
=
queries
[
i
]
.
Model
.
Get
(
"isCounter"
)
.
MustBool
()
counterMax
,
counterMaxCheck
:=
queries
[
i
]
.
Model
.
CheckGet
(
"counterMax"
)
if
counterMaxCheck
{
counterMaxVal
,
err
:=
strconv
.
ParseFloat
(
counterMax
.
MustString
(),
64
)
if
err
==
nil
{
rateOptions
[
"counterMax"
]
=
counterMaxVal
}
}
resetValue
,
resetValueCheck
:=
queries
[
i
]
.
Model
.
CheckGet
(
"counterResetValue"
)
if
resetValueCheck
{
resetValueVal
,
err
:=
strconv
.
ParseFloat
(
resetValue
.
MustString
(),
64
)
if
err
==
nil
{
rateOptions
[
"resetValue"
]
=
resetValueVal
}
}
metric
[
"rateOptions"
]
=
rateOptions
}
// Setting tags
tags
,
tagsCheck
:=
queries
[
i
]
.
Model
.
CheckGet
(
"tags"
)
if
tagsCheck
&&
len
(
tags
.
MustMap
())
>
0
{
metric
[
"tags"
]
=
tags
.
MustMap
()
}
// Setting filters
filters
,
filtersCheck
:=
queries
[
i
]
.
Model
.
CheckGet
(
"filters"
)
if
filtersCheck
&&
len
(
filters
.
MustArray
())
>
0
{
metric
[
"filters"
]
=
filters
.
MustArray
()
}
tsdbQuery
.
Queries
[
i
]
=
metric
metric
:=
e
.
buildMetric
(
queries
[
i
])
tsdbQuery
.
Queries
[
i
]
=
metric
}
if
setting
.
Env
==
setting
.
DEV
{
...
...
@@ -205,3 +152,62 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
queryResults
[
"A"
]
=
queryRes
return
queryResults
,
nil
}
func
(
e
*
OpenTsdbExecutor
)
buildMetric
(
query
*
tsdb
.
Query
)
(
map
[
string
]
interface
{})
{
metric
:=
make
(
map
[
string
]
interface
{})
// Setting metric and aggregator
metric
[
"metric"
]
=
query
.
Model
.
Get
(
"metric"
)
.
MustString
()
metric
[
"aggregator"
]
=
query
.
Model
.
Get
(
"aggregator"
)
.
MustString
()
// Setting downsampling options
disableDownsampling
:=
query
.
Model
.
Get
(
"disableDownsampling"
)
.
MustBool
()
if
!
disableDownsampling
{
downsampleInterval
:=
query
.
Model
.
Get
(
"downsampleInterval"
)
.
MustString
()
if
downsampleInterval
==
""
{
downsampleInterval
=
"1m"
//default value for blank
}
downsample
:=
downsampleInterval
+
"-"
+
query
.
Model
.
Get
(
"downsampleAggregator"
)
.
MustString
()
if
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
!=
"none"
{
metric
[
"downsample"
]
=
downsample
+
"-"
+
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
}
else
{
metric
[
"downsample"
]
=
downsample
}
}
// Setting rate options
if
query
.
Model
.
Get
(
"shouldComputeRate"
)
.
MustBool
()
{
metric
[
"rate"
]
=
true
rateOptions
:=
make
(
map
[
string
]
interface
{})
rateOptions
[
"counter"
]
=
query
.
Model
.
Get
(
"isCounter"
)
.
MustBool
()
counterMax
,
counterMaxCheck
:=
query
.
Model
.
CheckGet
(
"counterMax"
)
if
counterMaxCheck
{
rateOptions
[
"counterMax"
]
=
counterMax
.
MustFloat64
()
}
resetValue
,
resetValueCheck
:=
query
.
Model
.
CheckGet
(
"counterResetValue"
)
if
resetValueCheck
{
rateOptions
[
"resetValue"
]
=
resetValue
.
MustFloat64
()
}
metric
[
"rateOptions"
]
=
rateOptions
}
// Setting tags
tags
,
tagsCheck
:=
query
.
Model
.
CheckGet
(
"tags"
)
if
tagsCheck
&&
len
(
tags
.
MustMap
())
>
0
{
metric
[
"tags"
]
=
tags
.
MustMap
()
}
// Setting filters
filters
,
filtersCheck
:=
query
.
Model
.
CheckGet
(
"filters"
)
if
filtersCheck
&&
len
(
filters
.
MustArray
())
>
0
{
metric
[
"filters"
]
=
filters
.
MustArray
()
}
return
metric
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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