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
daee7970
Commit
daee7970
authored
Sep 30, 2015
by
Jimmi Dyson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add label_values query to get labels on a particular metric
parent
2f55c18d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
15 deletions
+39
-15
public/app/plugins/datasource/prometheus/datasource.js
+39
-15
No files found.
public/app/plugins/datasource/prometheus/datasource.js
View file @
daee7970
...
...
@@ -128,7 +128,7 @@ function (angular, _, moment, dateMath) {
};
PrometheusDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
var
url
;
if
(
!
query
)
{
return
$q
.
when
([]);
}
var
interpolated
;
try
{
...
...
@@ -138,27 +138,51 @@ function (angular, _, moment, dateMath) {
return
$q
.
reject
(
err
);
}
var
metricsQuery
=
interpolated
.
match
(
/^
[
a-zA-Z_:*
][
a-zA-Z0-9_:*
]
*/
)
;
var
labelValuesQuery
=
interpolated
.
match
(
/^label_values
\((
.+
)\)
/
)
;
var
label_values_regex
=
/^label_values
\(([^
,
]
+
)(?:
,
\s
*
(
.+
))?\)
$/
;
var
metric_names_regex
=
/^metrics
\((
.+
)\)
$/
;
if
(
labelValuesQuery
)
{
// return label values
url
=
'/api/v1/label/'
+
labelValuesQuery
[
1
]
+
'/values'
;
var
label_values_query
=
interpolated
.
match
(
label_values_regex
);
if
(
label_values_query
)
{
if
(
!
label_values_query
[
2
])
{
// return label values globally
var
url
=
'/api/v1/label/'
+
label_values_query
[
1
]
+
'/values'
;
return
this
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
value
)
{
return
{
text
:
value
};
return
this
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
value
)
{
return
{
text
:
value
};
});
});
});
}
else
if
(
metricsQuery
!=
null
&&
metricsQuery
[
0
].
indexOf
(
'*'
)
>=
0
)
{
// if query has wildcard character, return metric name list
url
=
'/api/v1/label/__name__/values'
;
}
else
{
var
metric_query
=
'count('
+
label_values_query
[
1
]
+
') by ('
+
label_values_query
[
2
]
+
')'
;
var
url
=
'/api/v1/query?query='
+
encodeURIComponent
(
metric_query
)
+
'&time='
+
(
moment
().
valueOf
()
/
1000
);
return
this
.
_request
(
'GET'
,
url
)
.
then
(
function
(
result
)
{
if
(
result
.
data
.
data
.
result
.
length
===
0
||
_
.
keys
(
result
.
data
.
data
.
result
[
0
].
metric
).
length
===
0
)
{
return
[];
}
return
_
.
map
(
result
.
data
.
data
.
result
,
function
(
metricValue
)
{
return
{
text
:
metricValue
.
metric
[
label_values_query
[
2
]],
expandable
:
true
};
});
});
}
}
var
metric_names_query
=
interpolated
.
match
(
metric_names_regex
);
if
(
metric_names_query
)
{
var
url
=
'/api/v1/label/__name__/values'
;
return
this
.
_request
(
'GET'
,
url
)
.
then
(
function
(
result
)
{
return
_
.
chain
(
result
.
data
.
data
)
.
filter
(
function
(
metricName
)
{
var
r
=
new
RegExp
(
metric
sQuery
[
0
].
replace
(
/
\*
/g
,
'.*'
)
);
var
r
=
new
RegExp
(
metric
_names_query
[
1
]
);
return
r
.
test
(
metricName
);
})
.
map
(
function
(
matchedMetricName
)
{
...
...
@@ -171,7 +195,7 @@ function (angular, _, moment, dateMath) {
});
}
else
{
// if query contains full metric name, return metric name and label list
url
=
'/api/v1/query?query='
+
encodeURIComponent
(
interpolated
)
+
var
url
=
'/api/v1/query?query='
+
encodeURIComponent
(
interpolated
)
+
'&time='
+
(
moment
().
valueOf
()
/
1000
);
return
this
.
_request
(
'GET'
,
url
)
...
...
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