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
080c46f8
Commit
080c46f8
authored
Oct 04, 2017
by
Alin Sinpalean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review comments.
parent
bb884978
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
47 deletions
+31
-47
public/app/plugins/datasource/prometheus/datasource.ts
+31
-47
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
080c46f8
///<reference path="../../../headers/common.d.ts" />
import
_
from
'lodash'
;
import
moment
from
'moment'
;
import
kbn
from
'app/core/utils/kbn'
;
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
PrometheusMetricFindQuery
from
'./metric_find_query'
;
import
TableModel
from
'app/core/table_model'
;
var
durationSplitRegexp
=
/
(\d
+
)(
ms|s|m|h|d|w|M|y
)
/
;
function
prometheusSpecialRegexEscape
(
value
)
{
return
value
.
replace
(
/
[\\
^$*+?.()|[
\]
{}
]
/g
,
'
\\\\
$&'
);
}
...
...
@@ -83,6 +80,7 @@ export class PrometheusDatasource {
var
self
=
this
;
var
start
=
this
.
getPrometheusTime
(
options
.
range
.
from
,
false
);
var
end
=
this
.
getPrometheusTime
(
options
.
range
.
to
,
true
);
var
range
=
Math
.
ceil
(
end
-
start
);
var
queries
=
[];
var
activeTargets
=
[];
...
...
@@ -95,33 +93,7 @@ export class PrometheusDatasource {
}
activeTargets
.
push
(
target
);
var
query
:
any
=
{};
query
.
instant
=
target
.
instant
;
var
interval
=
this
.
intervalSeconds
(
options
.
interval
);
// Minimum interval ("Min step"), if specified for the query. or same as interval otherwise
var
minInterval
=
this
.
intervalSeconds
(
this
.
templateSrv
.
replace
(
target
.
interval
,
options
.
scopedVars
)
||
options
.
interval
);
var
intervalFactor
=
target
.
intervalFactor
||
1
;
var
range
=
Math
.
ceil
(
end
-
start
);
// Adjust the interval to take into account any specified minimum and interval factor plus Prometheus limits
var
adjustedInterval
=
this
.
adjustInterval
(
interval
,
minInterval
,
range
,
intervalFactor
);
var
scopedVars
=
options
.
scopedVars
;
// If the interval was adjusted, make a shallow copy of scopedVars with updated interval vars
if
(
interval
!==
adjustedInterval
)
{
interval
=
adjustedInterval
;
scopedVars
=
Object
.
assign
({},
options
.
scopedVars
,
{
"__interval"
:
{
text
:
interval
+
"s"
,
value
:
interval
+
"s"
},
"__interval_ms"
:
{
text
:
interval
*
1000
,
value
:
interval
*
1000
},
});
}
target
.
step
=
query
.
step
=
interval
;
// Only replace vars in expression after having (possibly) updated interval vars
query
.
expr
=
this
.
templateSrv
.
replace
(
target
.
expr
,
scopedVars
,
self
.
interpolateQueryExpr
);
query
.
requestId
=
options
.
panelId
+
target
.
refId
;
queries
.
push
(
query
);
queries
.
push
(
this
.
createQuery
(
target
,
options
,
range
));
}
// No valid targets, return the empty result to save a round trip.
...
...
@@ -162,14 +134,41 @@ export class PrometheusDatasource {
});
}
createQuery
(
target
,
options
,
range
)
{
var
query
:
any
=
{};
query
.
instant
=
target
.
instant
;
var
interval
=
kbn
.
interval_to_seconds
(
options
.
interval
);
// Minimum interval ("Min step"), if specified for the query. or same as interval otherwise
var
minInterval
=
kbn
.
interval_to_seconds
(
this
.
templateSrv
.
replace
(
target
.
interval
,
options
.
scopedVars
)
||
options
.
interval
);
var
intervalFactor
=
target
.
intervalFactor
||
1
;
// Adjust the interval to take into account any specified minimum and interval factor plus Prometheus limits
var
adjustedInterval
=
this
.
adjustInterval
(
interval
,
minInterval
,
range
,
intervalFactor
);
var
scopedVars
=
options
.
scopedVars
;
// If the interval was adjusted, make a shallow copy of scopedVars with updated interval vars
if
(
interval
!==
adjustedInterval
)
{
interval
=
adjustedInterval
;
scopedVars
=
Object
.
assign
({},
options
.
scopedVars
,
{
"__interval"
:
{
text
:
interval
+
"s"
,
value
:
interval
+
"s"
},
"__interval_ms"
:
{
text
:
interval
*
1000
,
value
:
interval
*
1000
},
});
}
target
.
step
=
query
.
step
=
interval
;
// Only replace vars in expression after having (possibly) updated interval vars
query
.
expr
=
this
.
templateSrv
.
replace
(
target
.
expr
,
scopedVars
,
this
.
interpolateQueryExpr
);
query
.
requestId
=
options
.
panelId
+
target
.
refId
;
return
query
;
}
adjustInterval
(
interval
,
minInterval
,
range
,
intervalFactor
)
{
// Prometheus will drop queries that might return more than 11000 data points.
// Calibrate interval if it is too small.
if
(
interval
!==
0
&&
range
/
intervalFactor
/
interval
>
11000
)
{
interval
=
Math
.
ceil
(
range
/
intervalFactor
/
11000
);
}
interval
=
Math
.
max
(
interval
*
intervalFactor
,
minInterval
);
return
interval
;
return
Math
.
max
(
interval
*
intervalFactor
,
minInterval
);
}
performTimeSeriesQuery
(
query
,
start
,
end
)
{
...
...
@@ -273,21 +272,6 @@ export class PrometheusDatasource {
});
}
calculateInterval
(
interval
,
intervalFactor
)
{
return
Math
.
ceil
(
this
.
intervalSeconds
(
interval
)
*
intervalFactor
);
}
intervalSeconds
(
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
;
}
transformMetricData
(
md
,
options
,
start
,
end
)
{
var
dps
=
[],
metricLabel
=
null
;
...
...
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