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
991b6eaf
Commit
991b6eaf
authored
Mar 23, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech(influxdb): convert datasource to TS class
parent
5b75eea8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
44 deletions
+59
-44
public/app/plugins/datasource/influxdb/datasource.ts
+57
-43
public/app/plugins/datasource/influxdb/influx_query.ts
+1
-0
public/app/plugins/datasource/influxdb/module.ts
+1
-1
No files found.
public/app/plugins/datasource/influxdb/datasource.ts
View file @
991b6eaf
...
...
@@ -8,35 +8,49 @@ import InfluxSeries from './influx_series';
import
InfluxQuery
from
'./influx_query'
;
import
ResponseParser
from
'./response_parser'
;
/** @ngInject */
export
function
InfluxDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
)
{
this
.
type
=
'influxdb'
;
this
.
urls
=
_
.
map
(
instanceSettings
.
url
.
split
(
','
),
function
(
url
)
{
return
url
.
trim
();
});
this
.
username
=
instanceSettings
.
username
;
this
.
password
=
instanceSettings
.
password
;
this
.
name
=
instanceSettings
.
name
;
this
.
database
=
instanceSettings
.
database
;
this
.
basicAuth
=
instanceSettings
.
basicAuth
;
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
this
.
responseParser
=
new
ResponseParser
();
this
.
query
=
function
(
options
)
{
var
timeFilter
=
getTimeFilter
(
options
);
export
default
class
InfluxDatasource
{
type
:
string
;
urls
:
any
;
username
:
string
;
password
:
string
;
name
:
string
;
database
:
any
;
basicAuth
:
any
;
interval
:
any
;
supportAnnotations
:
boolean
;
supportMetrics
:
boolean
;
responseParser
:
any
;
/** @ngInject */
constructor
(
instanceSettings
,
private
$q
,
private
backendSrv
,
private
templateSrv
)
{
this
.
type
=
'influxdb'
;
this
.
urls
=
_
.
map
(
instanceSettings
.
url
.
split
(
','
),
function
(
url
)
{
return
url
.
trim
();
});
this
.
username
=
instanceSettings
.
username
;
this
.
password
=
instanceSettings
.
password
;
this
.
name
=
instanceSettings
.
name
;
this
.
database
=
instanceSettings
.
database
;
this
.
basicAuth
=
instanceSettings
.
basicAuth
;
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
this
.
responseParser
=
new
ResponseParser
();
}
query
(
options
)
{
var
timeFilter
=
this
.
getTimeFilter
(
options
);
var
queryTargets
=
[];
var
i
,
y
;
var
allQueries
=
_
.
map
(
options
.
targets
,
function
(
target
)
{
var
allQueries
=
_
.
map
(
options
.
targets
,
(
target
)
=>
{
if
(
target
.
hide
)
{
return
[];
}
queryTargets
.
push
(
target
);
// build query
var
queryModel
=
new
InfluxQuery
(
target
,
templateSrv
,
options
.
scopedVars
);
var
queryModel
=
new
InfluxQuery
(
target
,
t
his
.
t
emplateSrv
,
options
.
scopedVars
);
var
query
=
queryModel
.
render
(
true
);
query
=
query
.
replace
(
/
\$
interval/g
,
(
target
.
interval
||
options
.
interval
));
return
query
;
...
...
@@ -47,9 +61,9 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
allQueries
=
allQueries
.
replace
(
/
\$
timeFilter/g
,
timeFilter
);
// replace templated variables
allQueries
=
templateSrv
.
replace
(
allQueries
,
options
.
scopedVars
);
allQueries
=
t
his
.
t
emplateSrv
.
replace
(
allQueries
,
options
.
scopedVars
);
return
this
.
_seriesQuery
(
allQueries
).
then
(
function
(
data
):
any
{
return
this
.
_seriesQuery
(
allQueries
).
then
(
(
data
):
any
=>
{
if
(
!
data
||
!
data
.
results
)
{
return
[];
}
...
...
@@ -62,7 +76,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
var
target
=
queryTargets
[
i
];
var
alias
=
target
.
alias
;
if
(
alias
)
{
alias
=
templateSrv
.
replace
(
target
.
alias
,
options
.
scopedVars
);
alias
=
t
his
.
t
emplateSrv
.
replace
(
target
.
alias
,
options
.
scopedVars
);
}
var
influxSeries
=
new
InfluxSeries
({
series
:
data
.
results
[
i
].
series
,
alias
:
alias
});
...
...
@@ -86,16 +100,16 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
});
};
this
.
annotationQuery
=
function
(
options
)
{
annotationQuery
(
options
)
{
if
(
!
options
.
annotation
.
query
)
{
return
$q
.
reject
({
message
:
'Query missing in annotation definition'
});
return
this
.
$q
.
reject
({
message
:
'Query missing in annotation definition'
});
}
var
timeFilter
=
getTimeFilter
({
rangeRaw
:
options
.
rangeRaw
});
var
timeFilter
=
this
.
getTimeFilter
({
rangeRaw
:
options
.
rangeRaw
});
var
query
=
options
.
annotation
.
query
.
replace
(
'$timeFilter'
,
timeFilter
);
query
=
templateSrv
.
replace
(
query
);
query
=
t
his
.
t
emplateSrv
.
replace
(
query
);
return
this
.
_seriesQuery
(
query
).
then
(
function
(
data
)
{
return
this
.
_seriesQuery
(
query
).
then
(
data
=>
{
if
(
!
data
||
!
data
.
results
||
!
data
.
results
[
0
])
{
throw
{
message
:
'No results in response from InfluxDB'
};
}
...
...
@@ -103,29 +117,29 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
});
};
this
.
metricFindQuery
=
(
query
)
=>
{
metricFindQuery
(
query
)
{
var
interpolated
;
try
{
interpolated
=
templateSrv
.
replace
(
query
,
null
,
'regex'
);
interpolated
=
t
his
.
t
emplateSrv
.
replace
(
query
,
null
,
'regex'
);
}
catch
(
err
)
{
return
$q
.
reject
(
err
);
return
this
.
$q
.
reject
(
err
);
}
return
this
.
_seriesQuery
(
interpolated
)
.
then
(
_
.
curry
(
this
.
responseParser
.
parse
)(
query
));
};
this
.
_seriesQuery
=
function
(
query
)
{
_seriesQuery
(
query
)
{
return
this
.
_influxRequest
(
'GET'
,
'/query'
,
{
q
:
query
,
epoch
:
'ms'
});
}
;
}
t
his
.
testDatasource
=
function
()
{
return
this
.
metricFindQuery
(
'SHOW MEASUREMENTS LIMIT 1'
).
then
(
function
()
{
t
estDatasource
()
{
return
this
.
metricFindQuery
(
'SHOW MEASUREMENTS LIMIT 1'
).
then
(
()
=>
{
return
{
status
:
"success"
,
message
:
"Data source is working"
,
title
:
"Success"
};
});
}
;
}
this
.
_influxRequest
=
function
(
method
,
url
,
data
)
{
_influxRequest
(
method
,
url
,
data
)
{
var
self
=
this
;
var
currentUrl
=
self
.
urls
.
shift
();
...
...
@@ -159,7 +173,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
options
.
headers
.
Authorization
=
self
.
basicAuth
;
}
return
backendSrv
.
datasourceRequest
(
options
).
then
(
function
(
result
)
{
return
this
.
backendSrv
.
datasourceRequest
(
options
).
then
(
result
=>
{
return
result
.
data
;
},
function
(
err
)
{
if
(
err
.
status
!==
0
||
err
.
status
>=
300
)
{
...
...
@@ -172,9 +186,9 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
});
};
function
getTimeFilter
(
options
)
{
var
from
=
getInfluxTime
(
options
.
rangeRaw
.
from
,
false
);
var
until
=
getInfluxTime
(
options
.
rangeRaw
.
to
,
true
);
getTimeFilter
(
options
)
{
var
from
=
this
.
getInfluxTime
(
options
.
rangeRaw
.
from
,
false
);
var
until
=
this
.
getInfluxTime
(
options
.
rangeRaw
.
to
,
true
);
var
fromIsAbsolute
=
from
[
from
.
length
-
1
]
===
's'
;
if
(
until
===
'now()'
&&
!
fromIsAbsolute
)
{
...
...
@@ -184,7 +198,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
return
'time > '
+
from
+
' and time < '
+
until
;
}
function
getInfluxTime
(
date
,
roundUp
)
{
getInfluxTime
(
date
,
roundUp
)
{
if
(
_
.
isString
(
date
))
{
if
(
date
===
'now'
)
{
return
'now()'
;
...
...
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
991b6eaf
...
...
@@ -11,6 +11,7 @@ export default class InfluxQuery {
templateSrv
:
any
;
scopedVars
:
any
;
/** @ngInject */
constructor
(
target
,
templateSrv
?,
scopedVars
?)
{
this
.
target
=
target
;
this
.
templateSrv
=
templateSrv
;
...
...
public/app/plugins/datasource/influxdb/module.ts
View file @
991b6eaf
import
{
InfluxDatasource
}
from
'./datasource'
;
import
InfluxDatasource
from
'./datasource'
;
import
{
InfluxQueryCtrl
}
from
'./query_ctrl'
;
class
InfluxConfigCtrl
{
...
...
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