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
9413ce5e
Unverified
Commit
9413ce5e
authored
Apr 13, 2018
by
Daniel Lee
Committed by
GitHub
Apr 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8096 from ryantxu/influx-db-query2
let the influxdb API set a database
parents
511b34eb
a04c4ba4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
31 deletions
+39
-31
pkg/api/pluginproxy/ds_proxy.go
+0
-6
public/app/plugins/datasource/influxdb/datasource.ts
+25
-25
public/app/plugins/datasource/influxdb/partials/config.html
+14
-0
No files found.
pkg/api/pluginproxy/ds_proxy.go
View file @
9413ce5e
...
@@ -189,12 +189,6 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
...
@@ -189,12 +189,6 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
}
}
func
(
proxy
*
DataSourceProxy
)
validateRequest
()
error
{
func
(
proxy
*
DataSourceProxy
)
validateRequest
()
error
{
if
proxy
.
ds
.
Type
==
m
.
DS_INFLUXDB
{
if
proxy
.
ctx
.
Query
(
"db"
)
!=
proxy
.
ds
.
Database
{
return
errors
.
New
(
"Datasource is not configured to allow this database"
)
}
}
if
!
checkWhiteList
(
proxy
.
ctx
,
proxy
.
targetUrl
.
Host
)
{
if
!
checkWhiteList
(
proxy
.
ctx
,
proxy
.
targetUrl
.
Host
)
{
return
errors
.
New
(
"Target url is not a valid target"
)
return
errors
.
New
(
"Target url is not a valid target"
)
}
}
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
9413ce5e
...
@@ -82,7 +82,7 @@ export default class InfluxDatasource {
...
@@ -82,7 +82,7 @@ export default class InfluxDatasource {
// replace templated variables
// replace templated variables
allQueries
=
this
.
templateSrv
.
replace
(
allQueries
,
scopedVars
);
allQueries
=
this
.
templateSrv
.
replace
(
allQueries
,
scopedVars
);
return
this
.
_seriesQuery
(
allQueries
).
then
((
data
):
any
=>
{
return
this
.
_seriesQuery
(
allQueries
,
options
).
then
((
data
):
any
=>
{
if
(
!
data
||
!
data
.
results
)
{
if
(
!
data
||
!
data
.
results
)
{
return
[];
return
[];
}
}
...
@@ -135,7 +135,7 @@ export default class InfluxDatasource {
...
@@ -135,7 +135,7 @@ export default class InfluxDatasource {
var
query
=
options
.
annotation
.
query
.
replace
(
'$timeFilter'
,
timeFilter
);
var
query
=
options
.
annotation
.
query
.
replace
(
'$timeFilter'
,
timeFilter
);
query
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
query
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
return
this
.
_seriesQuery
(
query
).
then
(
data
=>
{
return
this
.
_seriesQuery
(
query
,
options
).
then
(
data
=>
{
if
(
!
data
||
!
data
.
results
||
!
data
.
results
[
0
])
{
if
(
!
data
||
!
data
.
results
||
!
data
.
results
[
0
])
{
throw
{
message
:
'No results in response from InfluxDB'
};
throw
{
message
:
'No results in response from InfluxDB'
};
}
}
...
@@ -164,30 +164,30 @@ export default class InfluxDatasource {
...
@@ -164,30 +164,30 @@ export default class InfluxDatasource {
return
false
;
return
false
;
}
}
metricFindQuery
(
query
)
{
metricFindQuery
(
query
:
string
,
options
?:
any
)
{
var
interpolated
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
var
interpolated
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
return
this
.
_seriesQuery
(
interpolated
).
then
(
_
.
curry
(
this
.
responseParser
.
parse
)(
query
));
return
this
.
_seriesQuery
(
interpolated
,
options
).
then
(
_
.
curry
(
this
.
responseParser
.
parse
)(
query
));
}
}
getTagKeys
(
options
)
{
getTagKeys
(
options
)
{
var
queryBuilder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
},
this
.
database
);
var
queryBuilder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
},
this
.
database
);
var
query
=
queryBuilder
.
buildExploreQuery
(
'TAG_KEYS'
);
var
query
=
queryBuilder
.
buildExploreQuery
(
'TAG_KEYS'
);
return
this
.
metricFindQuery
(
query
);
return
this
.
metricFindQuery
(
query
,
options
);
}
}
getTagValues
(
options
)
{
getTagValues
(
options
)
{
var
queryBuilder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
},
this
.
database
);
var
queryBuilder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
},
this
.
database
);
var
query
=
queryBuilder
.
buildExploreQuery
(
'TAG_VALUES'
,
options
.
key
);
var
query
=
queryBuilder
.
buildExploreQuery
(
'TAG_VALUES'
,
options
.
key
);
return
this
.
metricFindQuery
(
query
);
return
this
.
metricFindQuery
(
query
,
options
);
}
}
_seriesQuery
(
query
)
{
_seriesQuery
(
query
:
string
,
options
?:
any
)
{
if
(
!
query
)
{
if
(
!
query
)
{
return
this
.
$q
.
when
({
results
:
[]
});
return
this
.
$q
.
when
({
results
:
[]
});
}
}
return
this
.
_influxRequest
(
'GET'
,
'/query'
,
{
q
:
query
,
epoch
:
'ms'
});
return
this
.
_influxRequest
(
'GET'
,
'/query'
,
{
q
:
query
,
epoch
:
'ms'
}
,
options
);
}
}
serializeParams
(
params
)
{
serializeParams
(
params
)
{
...
@@ -225,21 +225,21 @@ export default class InfluxDatasource {
...
@@ -225,21 +225,21 @@ export default class InfluxDatasource {
});
});
}
}
_influxRequest
(
method
,
url
,
data
)
{
_influxRequest
(
method
:
string
,
url
:
string
,
data
:
any
,
options
?:
any
)
{
var
self
=
this
;
const
currentUrl
=
this
.
urls
.
shift
();
this
.
urls
.
push
(
currentUrl
);
var
currentUrl
=
self
.
urls
.
shift
();
let
params
:
any
=
{};
self
.
urls
.
push
(
currentUrl
);
var
params
:
any
=
{};
if
(
this
.
username
)
{
params
.
u
=
this
.
username
;
if
(
self
.
username
)
{
params
.
p
=
this
.
password
;
params
.
u
=
self
.
username
;
params
.
p
=
self
.
password
;
}
}
if
(
self
.
database
)
{
if
(
options
&&
options
.
database
)
{
params
.
db
=
self
.
database
;
params
.
db
=
options
.
database
;
}
else
if
(
this
.
database
)
{
params
.
db
=
this
.
database
;
}
}
if
(
method
===
'GET'
)
{
if
(
method
===
'GET'
)
{
...
@@ -247,7 +247,7 @@ export default class InfluxDatasource {
...
@@ -247,7 +247,7 @@ export default class InfluxDatasource {
data
=
null
;
data
=
null
;
}
}
var
options
:
any
=
{
let
req
:
any
=
{
method
:
method
,
method
:
method
,
url
:
currentUrl
+
url
,
url
:
currentUrl
+
url
,
params
:
params
,
params
:
params
,
...
@@ -257,15 +257,15 @@ export default class InfluxDatasource {
...
@@ -257,15 +257,15 @@ export default class InfluxDatasource {
paramSerializer
:
this
.
serializeParams
,
paramSerializer
:
this
.
serializeParams
,
};
};
options
.
headers
=
options
.
headers
||
{};
req
.
headers
=
req
.
headers
||
{};
if
(
this
.
basicAuth
||
this
.
withCredentials
)
{
if
(
this
.
basicAuth
||
this
.
withCredentials
)
{
options
.
withCredentials
=
true
;
req
.
withCredentials
=
true
;
}
}
if
(
self
.
basicAuth
)
{
if
(
this
.
basicAuth
)
{
options
.
headers
.
Authorization
=
self
.
basicAuth
;
req
.
headers
.
Authorization
=
this
.
basicAuth
;
}
}
return
this
.
backendSrv
.
datasourceRequest
(
options
).
then
(
return
this
.
backendSrv
.
datasourceRequest
(
req
).
then
(
result
=>
{
result
=>
{
return
result
.
data
;
return
result
.
data
;
},
},
...
...
public/app/plugins/datasource/influxdb/partials/config.html
View file @
9413ce5e
...
@@ -23,6 +23,20 @@
...
@@ -23,6 +23,20 @@
</div>
</div>
</div>
</div>
<div
class=
"gf-form-group"
>
<div
class=
"grafana-info-box"
>
<h5>
Database Access
</h5>
<p>
Setting the database for this datasource does not deny access to other databases. The InfluxDB query syntax allows
switching the database in the query. For example:
<code>
SHOW MEASUREMENTS ON _internal
</code>
or
<code>
SELECT * FROM "_internal".."database" LIMIT 10
</code>
<br/><br/>
To support data isolation and security, make sure appropriate permissions are configured in InfluxDB.
</p>
</div>
</div>
<div
class=
"gf-form-group"
>
<div
class=
"gf-form-group"
>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<div
class=
"gf-form"
>
...
...
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