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
50795adc
Commit
50795adc
authored
Jul 09, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb 0.9): field lookup and other enhancements, #2311
parent
597c1f6a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
19 deletions
+53
-19
public/app/plugins/datasource/influxdb/funcEditor.js
+23
-3
public/app/plugins/datasource/influxdb/partials/query.editor.html
+1
-1
public/app/plugins/datasource/influxdb/queryBuilder.js
+13
-3
public/app/plugins/datasource/influxdb/queryCtrl.js
+2
-12
public/test/specs/influx09-querybuilder-specs.js
+14
-0
No files found.
public/app/plugins/datasource/influxdb/funcEditor.js
View file @
50795adc
...
...
@@ -16,14 +16,32 @@ function (angular, _, $) {
var
paramTemplate
=
'<input type="text" style="display:none"'
+
' class="input-mini tight-form-func-param"></input>'
;
var
functionList
=
[
'count'
,
'mean'
,
'sum'
,
'min'
,
'max'
,
'mode'
,
'distinct'
,
'median'
,
'derivative'
,
'stddev'
,
'first'
,
'last'
,
'difference'
];
var
functionMenu
=
_
.
map
(
functionList
,
function
(
func
)
{
return
{
text
:
func
,
click
:
"changeFunction('"
+
func
+
"');"
};
});
return
{
restrict
:
'A'
,
scope
:
{
field
:
"="
,
getFields
:
"&"
,
onChange
:
"&"
,
},
link
:
function
postLink
(
$scope
,
elem
)
{
var
$funcLink
=
$
(
funcSpanTemplate
);
$scope
.
functionMenu
=
functionMenu
;
$scope
.
changeFunction
=
function
(
func
)
{
$scope
.
field
.
func
=
func
;
$scope
.
onChange
();
};
function
clickFuncParam
()
{
/*jshint validthis:true */
...
...
@@ -55,7 +73,7 @@ function (angular, _, $) {
$link
.
text
(
$input
.
val
());
$scope
.
field
.
name
=
$input
.
val
();
$scope
.
$apply
(
$scope
.
get_data
);
$scope
.
$apply
(
$scope
.
onChange
()
);
}
$input
.
hide
();
...
...
@@ -79,8 +97,10 @@ function (angular, _, $) {
$input
.
attr
(
'data-provide'
,
'typeahead'
);
$input
.
typeahead
({
source
:
function
()
{
return
$scope
.
getFields
.
apply
(
null
,
arguments
);
source
:
function
(
query
,
callback
)
{
return
$scope
.
getFields
().
then
(
function
(
results
)
{
callback
(
results
);
});
},
minLength
:
0
,
items
:
20
,
...
...
public/app/plugins/datasource/influxdb/partials/query.editor.html
View file @
50795adc
...
...
@@ -66,7 +66,7 @@
SELECT
</li>
<li
class=
"dropdown"
ng-repeat=
"field in target.fields"
>
<span
influxdb-func-editor
field=
"field"
class=
"tight-form-item tight-form-func
"
>
<span
influxdb-func-editor
field=
"field"
get-fields=
"getFields()"
on-change=
"get_data()"
class=
"tight-form-item
"
>
</span>
</li>
</ul>
...
...
public/app/plugins/datasource/influxdb/queryBuilder.js
View file @
50795adc
...
...
@@ -76,15 +76,25 @@ function (_) {
throw
"Metric measurement is missing"
;
}
if
(
!
target
.
fields
)
{
target
.
fields
=
[{
name
:
'value'
,
func
:
target
.
function
||
'mean'
}];
}
var
query
=
'SELECT '
;
var
measurement
=
target
.
measurement
;
var
aggregationFunc
=
target
.
function
||
'mean'
;
var
i
;
for
(
i
=
0
;
i
<
target
.
fields
.
length
;
i
++
)
{
var
field
=
target
.
fields
[
i
];
if
(
i
>
0
)
{
query
+=
', '
;
}
query
+=
field
.
func
+
'('
+
field
.
name
+
')'
;
}
var
measurement
=
target
.
measurement
;
if
(
!
measurement
.
match
(
'^/.*/'
)
&&
!
measurement
.
match
(
/^merge
\(
.*
\)
/
))
{
measurement
=
'"'
+
measurement
+
'"'
;
}
query
+=
aggregationFunc
+
'(value)'
;
query
+=
' FROM '
+
measurement
+
' WHERE '
;
var
conditions
=
_
.
map
(
target
.
tags
,
function
(
tag
,
index
)
{
return
renderTagCondition
(
tag
,
index
);
...
...
public/app/plugins/datasource/influxdb/queryCtrl.js
View file @
50795adc
...
...
@@ -10,15 +10,6 @@ function (angular, _, InfluxQueryBuilder) {
module
.
controller
(
'InfluxQueryCtrl'
,
function
(
$scope
,
$timeout
,
$sce
,
templateSrv
,
$q
)
{
$scope
.
functionList
=
[
'count'
,
'mean'
,
'sum'
,
'min'
,
'max'
,
'mode'
,
'distinct'
,
'median'
,
'derivative'
,
'stddev'
,
'first'
,
'last'
,
'difference'
];
$scope
.
functionMenu
=
_
.
map
(
$scope
.
functionList
,
function
(
func
)
{
return
{
text
:
func
,
click
:
"changeFunction('"
+
func
+
"');"
};
});
$scope
.
init
=
function
()
{
var
target
=
$scope
.
target
;
target
.
tags
=
target
.
tags
||
[];
...
...
@@ -97,12 +88,11 @@ function (angular, _, InfluxQueryBuilder) {
$scope
.
$parent
.
get_data
();
};
$scope
.
getFields
=
function
(
query
,
callback
)
{
$scope
.
getFields
=
function
()
{
var
fieldsQuery
=
$scope
.
queryBuilder
.
buildExploreQuery
(
'FIELDS'
);
return
$scope
.
datasource
.
metricFindQuery
(
fieldsQuery
)
.
then
(
function
(
results
)
{
var
fields
=
_
.
pluck
(
results
,
'text'
);
callback
(
fields
);
return
_
.
pluck
(
results
,
'text'
);
});
};
...
...
public/test/specs/influx09-querybuilder-specs.js
View file @
50795adc
...
...
@@ -38,6 +38,20 @@ define([
});
});
describe
(
'series with multiple fields'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[],
fields
:
[{
name
:
'tx_in'
,
func
:
'sum'
},
{
name
:
'tx_out'
,
func
:
'mean'
}]
});
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT sum(tx_in), mean(tx_out) FROM "cpu" WHERE $timeFilter GROUP BY time($interval) ORDER BY asc'
);
});
});
describe
(
'series with multiple tags only'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
...
...
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