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
0a0a0776
Commit
0a0a0776
authored
Oct 30, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3088 from utkarshcmu/suggest-opentsdb
Tag suggestions fixed for v2.1.1 & above by using Suggest Api.
parents
59d199a1
a27186e3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
9 deletions
+40
-9
docs/sources/datasources/opentsdb.md
+4
-3
public/app/plugins/datasource/opentsdb/datasource.js
+15
-3
public/app/plugins/datasource/opentsdb/queryCtrl.js
+2
-2
public/test/specs/opentsdbDatasource-specs.js
+19
-1
No files found.
docs/sources/datasources/opentsdb.md
View file @
0a0a0776
...
@@ -40,8 +40,10 @@ Grafana's OpenTSDB data source now supports template variable values queries. Th
...
@@ -40,8 +40,10 @@ Grafana's OpenTSDB data source now supports template variable values queries. Th
When using OpenTSDB with a template variable of
`query`
type you can use following syntax for lookup.
When using OpenTSDB with a template variable of
`query`
type you can use following syntax for lookup.
metrics(
) // returns metric names
metrics(
prefix) // returns metric names with specific prefix (can be empty)
tag_names(cpu) // return tag names (i.e. keys) for a specific cpu metric
tag_names(cpu) // return tag names (i.e. keys) for a specific cpu metric
tag_values(cpu, hostname) // return tag values for metric cpu and tag key hostname
tag_values(cpu, hostname) // return tag values for metric cpu and tag key hostname
suggest_tagk(prefix) // return tag names (i.e. keys) for all metrics with specific prefix (can be empty)
suggest_tagv(prefix) // return tag values for all metrics with specific prefix (can be empty)
For details on opentsdb metric queries checkout the official
[
OpenTSDB documentation
](
http://opentsdb.net/docs/build/html/index.html
)
For details on opentsdb metric queries checkout the official
[
OpenTSDB documentation
](
http://opentsdb.net/docs/build/html/index.html
)
\ No newline at end of file
public/app/plugins/datasource/opentsdb/datasource.js
View file @
0a0a0776
...
@@ -80,8 +80,8 @@ function (angular, _, dateMath) {
...
@@ -80,8 +80,8 @@ function (angular, _, dateMath) {
return
backendSrv
.
datasourceRequest
(
options
);
return
backendSrv
.
datasourceRequest
(
options
);
};
};
OpenTSDBDatasource
.
prototype
.
_performSuggestQuery
=
function
(
query
)
{
OpenTSDBDatasource
.
prototype
.
_performSuggestQuery
=
function
(
query
,
type
)
{
return
this
.
_get
(
'/api/suggest'
,
{
type
:
'metrics'
,
q
:
query
,
max
:
1000
}).
then
(
function
(
result
)
{
return
this
.
_get
(
'/api/suggest'
,
{
type
:
type
,
q
:
query
,
max
:
1000
}).
then
(
function
(
result
)
{
return
result
.
data
;
return
result
.
data
;
});
});
};
};
...
@@ -150,10 +150,12 @@ function (angular, _, dateMath) {
...
@@ -150,10 +150,12 @@ function (angular, _, dateMath) {
var
metrics_regex
=
/metrics
\((
.*
)\)
/
;
var
metrics_regex
=
/metrics
\((
.*
)\)
/
;
var
tag_names_regex
=
/tag_names
\((
.*
)\)
/
;
var
tag_names_regex
=
/tag_names
\((
.*
)\)
/
;
var
tag_values_regex
=
/tag_values
\((
.*
)
,
\s?(
.*
)\)
/
;
var
tag_values_regex
=
/tag_values
\((
.*
)
,
\s?(
.*
)\)
/
;
var
tag_names_suggest_regex
=
/suggest_tagk
\((
.*
)\)
/
;
var
tag_values_suggest_regex
=
/suggest_tagv
\((
.*
)\)
/
;
var
metrics_query
=
interpolated
.
match
(
metrics_regex
);
var
metrics_query
=
interpolated
.
match
(
metrics_regex
);
if
(
metrics_query
)
{
if
(
metrics_query
)
{
return
this
.
_performSuggestQuery
(
metrics_query
[
1
]).
then
(
responseTransform
);
return
this
.
_performSuggestQuery
(
metrics_query
[
1
]
,
'metrics'
).
then
(
responseTransform
);
}
}
var
tag_names_query
=
interpolated
.
match
(
tag_names_regex
);
var
tag_names_query
=
interpolated
.
match
(
tag_names_regex
);
...
@@ -166,6 +168,16 @@ function (angular, _, dateMath) {
...
@@ -166,6 +168,16 @@ function (angular, _, dateMath) {
return
this
.
_performMetricKeyValueLookup
(
tag_values_query
[
1
],
tag_values_query
[
2
]).
then
(
responseTransform
);
return
this
.
_performMetricKeyValueLookup
(
tag_values_query
[
1
],
tag_values_query
[
2
]).
then
(
responseTransform
);
}
}
var
tag_names_suggest_query
=
interpolated
.
match
(
tag_names_suggest_regex
);
if
(
tag_names_suggest_query
)
{
return
this
.
_performSuggestQuery
(
tag_names_suggest_query
[
1
],
'tagk'
).
then
(
responseTransform
);
}
var
tag_values_suggest_query
=
interpolated
.
match
(
tag_values_suggest_regex
);
if
(
tag_values_suggest_query
)
{
return
this
.
_performSuggestQuery
(
tag_values_suggest_query
[
1
],
'tagv'
).
then
(
responseTransform
);
}
return
$q
.
when
([]);
return
$q
.
when
([]);
};
};
...
...
public/app/plugins/datasource/opentsdb/queryCtrl.js
View file @
0a0a0776
...
@@ -48,13 +48,13 @@ function (angular, _, kbn) {
...
@@ -48,13 +48,13 @@ function (angular, _, kbn) {
};
};
$scope
.
suggestTagKeys
=
function
(
query
,
callback
)
{
$scope
.
suggestTagKeys
=
function
(
query
,
callback
)
{
$scope
.
datasource
.
metricFindQuery
(
'
tag_names('
+
$scope
.
target
.
metric
+
')'
)
$scope
.
datasource
.
metricFindQuery
(
'
suggest_tagk('
+
query
+
')'
)
.
then
(
$scope
.
getTextValues
)
.
then
(
$scope
.
getTextValues
)
.
then
(
callback
);
.
then
(
callback
);
};
};
$scope
.
suggestTagValues
=
function
(
query
,
callback
)
{
$scope
.
suggestTagValues
=
function
(
query
,
callback
)
{
$scope
.
datasource
.
metricFindQuery
(
'
tag_values('
+
$scope
.
target
.
metric
+
','
+
$scope
.
target
.
currentTagKe
y
+
')'
)
$scope
.
datasource
.
metricFindQuery
(
'
suggest_tagv('
+
quer
y
+
')'
)
.
then
(
$scope
.
getTextValues
)
.
then
(
$scope
.
getTextValues
)
.
then
(
callback
);
.
then
(
callback
);
};
};
...
...
public/test/specs/opentsdbDatasource-specs.js
View file @
0a0a0776
...
@@ -27,9 +27,11 @@ define([
...
@@ -27,9 +27,11 @@ define([
});
});
it
(
'metrics() should generate api suggest query'
,
function
()
{
it
(
'metrics() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'metrics()'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
ds
.
metricFindQuery
(
'metrics(
pew
)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'metrics'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'pew'
);
});
});
it
(
'tag_names(cpu) should generate looku query'
,
function
()
{
it
(
'tag_names(cpu) should generate looku query'
,
function
()
{
...
@@ -46,6 +48,22 @@ define([
...
@@ -46,6 +48,22 @@ define([
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu{hostname=*}'
);
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu{hostname=*}'
);
});
});
it
(
'suggest_tagk() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'suggest_tagk(foo)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'tagk'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'foo'
);
});
it
(
'suggest_tagv() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'suggest_tagv(bar)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'tagv'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'bar'
);
});
});
});
});
});
});
});
...
...
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