Add datasource option to more elements

This change adds support for datasource option to:
* graph panel
* singlestat panel
* templating

This enables the user to use other datasource than the default datasource
for graph/singlestat panels and templating. It is useful when more
than one datasource are available in Grafana.

Change-Id: I2e81a2dc4658c530bf82c4b349e2991dad348b01
This commit is contained in:
Ye Na Rhee 2016-04-21 23:09:12 +02:00 committed by Mathieu Gagné
parent 3b01b4df7d
commit f89102bbf9
9 changed files with 186 additions and 0 deletions

View File

@ -115,6 +115,7 @@ class Graph(Base):
graph = { graph = {
v.Required('bars', default=False): v.All(bool), v.Required('bars', default=False): v.All(bool),
v.Optional('datasource'): v.All(str),
v.Required('fill', default=1): v.All(int), v.Required('fill', default=1): v.All(int),
v.Optional('hideTimeOverride'): v.All(bool), v.Optional('hideTimeOverride'): v.All(bool),
v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)), v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)),

View File

@ -62,6 +62,7 @@ class Singlestat(Base):
v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')), v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
v.Required('valueName', default='avg'): v.Any( v.Required('valueName', default='avg'): v.Any(
'avg', 'current', 'max', 'min', 'total'), 'avg', 'current', 'max', 'min', 'total'),
v.Optional('datasource'): v.All(str),
v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)), v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)),
v.Optional('hideTimeOverride'): v.All(bool), v.Optional('hideTimeOverride'): v.All(bool),
v.Optional('timeFrom'): v.All(v.Match(r'[1-9]+[0-9]*[smhdw]')), v.Optional('timeFrom'): v.All(v.Match(r'[1-9]+[0-9]*[smhdw]')),

View File

@ -25,6 +25,7 @@ class Query(Base):
v.Required('multi', default=False): v.All(bool), v.Required('multi', default=False): v.All(bool),
v.Required('query', default=''): v.All(str), v.Required('query', default=''): v.All(str),
v.Required('refresh', default=False): v.All(bool), v.Required('refresh', default=False): v.All(bool),
v.Optional('datasource'): v.All(str),
} }
query.update(self.base) query.update(self.base)
return v.Schema(query) return v.Schema(query)

View File

@ -0,0 +1,43 @@
{
"dashboard": {
"new-dashboard": {
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"bars": false,
"datasource": "graphite",
"editable": true,
"error": false,
"fill": 1,
"lines": true,
"linewidth": 2,
"percentage": false,
"pointradius": 5,
"points": false,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [],
"title": "no title (click here)",
"type": "graph",
"x-axis": true,
"y-axis": true
}
],
"showTitle": false,
"title": "New row"
}
],
"templating": {
"enabled": false,
"list": []
},
"timezone": "utc",
"title": "New dashboard"
}
}
}

View File

@ -0,0 +1,9 @@
dashboard:
title: New dashboard
rows:
- title: New row
height: 250px
panels:
- title: no title (click here)
type: graph
datasource: graphite

View File

@ -0,0 +1,48 @@
{
"dashboard": {
"new-dashboard": {
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"colorBackground": false,
"colorValue": false,
"datasource": "graphite",
"editable": true,
"error": false,
"maxDataPoints": 100,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"span": 12,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [],
"thresholds": "",
"title": "no title (click here)",
"type": "singlestat",
"valueFontSize": "80%",
"valueName": "avg"
}
],
"showTitle": false,
"title": "New row"
}
],
"templating": {
"enabled": false,
"list": []
},
"timezone": "utc",
"title": "New dashboard"
}
}
}

View File

@ -0,0 +1,9 @@
dashboard:
title: New dashboard
rows:
- title: New row
height: 250px
panels:
- title: no title (click here)
type: singlestat
datasource: graphite

View File

@ -0,0 +1,57 @@
{
"dashboard": {
"new-dashboard": {
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"bars": false,
"datasource": "graphite",
"editable": true,
"error": false,
"fill": 1,
"lines": true,
"linewidth": 2,
"percentage": false,
"pointradius": 5,
"points": false,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"target": "$hostname.Cpu.cpu_prct_used"
}
],
"title": "no title (click here)",
"type": "graph",
"x-axis": true,
"y-axis": true
}
],
"showTitle": false,
"title": "New row"
}
],
"templating": {
"enabled": true,
"list": [
{
"datasource": "graphite",
"includeAll": false,
"multi": false,
"name": "hostname",
"query": "node*",
"refresh": true,
"type": "query"
}
]
},
"timezone": "utc",
"title": "New dashboard"
}
}
}

View File

@ -0,0 +1,17 @@
dashboard:
templating:
- name: hostname
type: query
datasource: graphite
query: node*
refresh: true
title: New dashboard
rows:
- title: New row
height: 250px
panels:
- title: no title (click here)
type: graph
datasource: graphite
targets:
- target: $hostname.Cpu.cpu_prct_used