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
2f55c18d
Commit
2f55c18d
authored
Sep 29, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2847 from jimmidyson/prometheus-datasource
Add Prometheus datasource
parents
866ea7f9
cf074889
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
+22
-11
public/app/plugins/datasource/prometheus/datasource.js
+20
-9
public/app/plugins/datasource/prometheus/queryCtrl.js
+1
-1
public/test/specs/prometheus-datasource-specs.js
+1
-1
No files found.
public/app/plugins/datasource/prometheus/datasource.js
View file @
2f55c18d
define
([
'angular'
,
'lodash'
,
'kbn'
,
'moment'
,
'app/core/utils/datemath'
,
'./directives'
,
'./queryCtrl'
,
],
function
(
angular
,
_
,
kbn
,
dateMath
)
{
function
(
angular
,
_
,
moment
,
dateMath
)
{
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
var
durationSplitRegexp
=
/
(\d
+
)(
ms|s|m|h|d|w|M|y
)
/
;
module
.
factory
(
'PrometheusDatasource'
,
function
(
$q
,
backendSrv
,
templateSrv
)
{
function
PrometheusDatasource
(
datasource
)
{
...
...
@@ -129,8 +130,16 @@ function (angular, _, kbn, dateMath) {
PrometheusDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
var
url
;
var
metricsQuery
=
query
.
match
(
/^
[
a-zA-Z_:*
][
a-zA-Z0-9_:*
]
*/
);
var
labelValuesQuery
=
query
.
match
(
/^label_values
\((
.+
)\)
/
);
var
interpolated
;
try
{
interpolated
=
templateSrv
.
replace
(
query
);
}
catch
(
err
)
{
return
$q
.
reject
(
err
);
}
var
metricsQuery
=
interpolated
.
match
(
/^
[
a-zA-Z_:*
][
a-zA-Z0-9_:*
]
*/
);
var
labelValuesQuery
=
interpolated
.
match
(
/^label_values
\((
.+
)\)
/
);
if
(
labelValuesQuery
)
{
// return label values
...
...
@@ -162,11 +171,12 @@ function (angular, _, kbn, dateMath) {
});
}
else
{
// if query contains full metric name, return metric name and label list
url
=
'/api/v1/query?query='
+
encodeURIComponent
(
query
);
url
=
'/api/v1/query?query='
+
encodeURIComponent
(
interpolated
)
+
'&time='
+
(
moment
().
valueOf
()
/
1000
);
return
this
.
_request
(
'GET'
,
url
)
.
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
result
,
function
(
metricData
)
{
return
_
.
map
(
result
.
data
.
data
.
result
,
function
(
metricData
)
{
return
{
text
:
getOriginalMetricName
(
metricData
.
metric
),
expandable
:
true
...
...
@@ -183,13 +193,14 @@ function (angular, _, kbn, dateMath) {
};
PrometheusDatasource
.
prototype
.
calculateInterval
=
function
(
interval
,
intervalFactor
)
{
var
sec
=
kbn
.
interval_to_seconds
(
interval
);
var
m
=
interval
.
match
(
durationSplitRegexp
);
var
dur
=
moment
.
duration
(
parseInt
(
m
[
1
]),
m
[
2
]);
var
sec
=
dur
.
asSeconds
();
if
(
sec
<
1
)
{
sec
=
1
;
}
return
sec
*
intervalFactor
;
return
Math
.
floor
(
sec
*
intervalFactor
)
+
's'
;
};
function
transformMetricData
(
md
,
options
)
{
...
...
public/app/plugins/datasource/prometheus/queryCtrl.js
View file @
2f55c18d
...
...
@@ -117,7 +117,7 @@ function (angular, _, kbn, dateMath) {
$scope
.
calculateInterval
=
function
()
{
var
interval
=
$scope
.
target
.
interval
||
$scope
.
interval
;
var
calculatedInterval
=
$scope
.
datasource
.
calculateInterval
(
interval
,
$scope
.
target
.
intervalFactor
);
$scope
.
target
.
calculatedInterval
=
kbn
.
secondsToHms
(
calculatedInterval
)
;
$scope
.
target
.
calculatedInterval
=
calculatedInterval
;
};
// TODO: validate target
...
...
public/test/specs/prometheus-datasource-specs.js
View file @
2f55c18d
...
...
@@ -21,7 +21,7 @@ define([
var
results
;
var
urlExpected
=
'/api/v1/query_range?query='
+
encodeURIComponent
(
'test{job="testjob"}'
)
+
'&start=1443438675&end=1443460275&step=60'
;
'&start=1443438675&end=1443460275&step=60
s
'
;
var
query
=
{
range
:
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)
},
targets
:
[{
expr
:
'test{job="testjob"}'
}],
...
...
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