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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
11 deletions
+35
-11
public/app/plugins/datasource/prometheus/datasource.js
+35
-11
No files found.
public/app/plugins/datasource/prometheus/datasource.js
View file @
daee7970
...
@@ -128,7 +128,7 @@ function (angular, _, moment, dateMath) {
...
@@ -128,7 +128,7 @@ function (angular, _, moment, dateMath) {
};
};
PrometheusDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
PrometheusDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
var
url
;
if
(
!
query
)
{
return
$q
.
when
([]);
}
var
interpolated
;
var
interpolated
;
try
{
try
{
...
@@ -138,27 +138,51 @@ function (angular, _, moment, dateMath) {
...
@@ -138,27 +138,51 @@ function (angular, _, moment, dateMath) {
return
$q
.
reject
(
err
);
return
$q
.
reject
(
err
);
}
}
var
metricsQuery
=
interpolated
.
match
(
/^
[
a-zA-Z_:*
][
a-zA-Z0-9_:*
]
*/
)
;
var
label_values_regex
=
/^label_values
\(([^
,
]
+
)(?:
,
\s
*
(
.+
))?\)
$/
;
var
labelValuesQuery
=
interpolated
.
match
(
/^label_values
\((
.+
)\)
/
)
;
var
metric_names_regex
=
/^metrics
\((
.+
)\)
$/
;
if
(
labelValuesQuery
)
{
var
label_values_query
=
interpolated
.
match
(
label_values_regex
);
// return label values
if
(
label_values_query
)
{
url
=
'/api/v1/label/'
+
labelValuesQuery
[
1
]
+
'/values'
;
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
this
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
value
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
value
)
{
return
{
text
:
value
};
return
{
text
:
value
};
});
});
});
});
}
else
if
(
metricsQuery
!=
null
&&
metricsQuery
[
0
].
indexOf
(
'*'
)
>=
0
)
{
}
else
{
// if query has wildcard character, return metric name list
var
metric_query
=
'count('
+
label_values_query
[
1
]
+
') by ('
+
url
=
'/api/v1/label/__name__/values'
;
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
)
return
this
.
_request
(
'GET'
,
url
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
return
_
.
chain
(
result
.
data
.
data
)
return
_
.
chain
(
result
.
data
.
data
)
.
filter
(
function
(
metricName
)
{
.
filter
(
function
(
metricName
)
{
var
r
=
new
RegExp
(
metric
sQuery
[
0
].
replace
(
/
\*
/g
,
'.*'
)
);
var
r
=
new
RegExp
(
metric
_names_query
[
1
]
);
return
r
.
test
(
metricName
);
return
r
.
test
(
metricName
);
})
})
.
map
(
function
(
matchedMetricName
)
{
.
map
(
function
(
matchedMetricName
)
{
...
@@ -171,7 +195,7 @@ function (angular, _, moment, dateMath) {
...
@@ -171,7 +195,7 @@ function (angular, _, moment, dateMath) {
});
});
}
else
{
}
else
{
// if query contains full metric name, return metric name and label list
// 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
);
'&time='
+
(
moment
().
valueOf
()
/
1000
);
return
this
.
_request
(
'GET'
,
url
)
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