Commit e648ed19 by Marcus Efraimsson Committed by GitHub

Merge pull request #12679 from svenklemm/postgres-metric-prefix

Use metric column as prefix when returning multiple value columns
parents e4983cba 8a221291
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532618879985, "iteration": 1532949769359,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -871,14 +871,8 @@ ...@@ -871,14 +871,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement + ' - value one' as metric, \n avg(valueOne) as valueOne\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n ($metric = 'ALL' OR measurement = $metric)\nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1", "rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement as metric, \n avg(valueOne) as valueOne,\n avg(valueTwo) as valueTwo\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n ($metric = 'ALL' OR measurement = $metric)\nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement + ' - value two' as metric, \n avg(valueTwo) as valueTwo \nFROM\n metric_values\nWHERE\n $__timeFilter(time) AND\n ($metric = 'ALL' OR measurement = $metric)\nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1067,14 +1061,8 @@ ...@@ -1067,14 +1061,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1245,14 +1233,8 @@ ...@@ -1245,14 +1233,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1423,14 +1405,8 @@ ...@@ -1423,14 +1405,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1773,14 +1749,8 @@ ...@@ -1773,14 +1749,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1954,14 +1924,8 @@ ...@@ -1954,14 +1924,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2135,14 +2099,8 @@ ...@@ -2135,14 +2099,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2316,14 +2274,8 @@ ...@@ -2316,14 +2274,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values\nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND ($metric = 'ALL' OR measurement = $metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2460,7 +2412,10 @@ ...@@ -2460,7 +2412,10 @@
"refresh": false, "refresh": false,
"schemaVersion": 16, "schemaVersion": 16,
"style": "dark", "style": "dark",
"tags": ["gdev", "mssql"], "tags": [
"gdev",
"mssql"
],
"templating": { "templating": {
"list": [ "list": [
{ {
...@@ -2587,5 +2542,5 @@ ...@@ -2587,5 +2542,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - MSSQL (unit test)", "title": "Datasource tests - MSSQL (unit test)",
"uid": "GlAqcPgmz", "uid": "GlAqcPgmz",
"version": 58 "version": 3
} }
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532620354037, "iteration": 1532949531280,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -871,14 +871,8 @@ ...@@ -871,14 +871,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n CONCAT(measurement, ' - value one') as metric, \n avg(valueOne) as valueOne\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n measurement IN($metric)\nGROUP BY 1, 2\nORDER BY 1", "rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement as metric, \n avg(valueOne) as valueOne,\n avg(valueTwo) as valueTwo\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n measurement IN($metric)\nGROUP BY 1, 2\nORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n CONCAT(measurement, ' - value two') as metric, \n avg(valueTwo) as valueTwo \nFROM\n metric_values\nWHERE\n $__timeFilter(time) AND\n measurement IN($metric)\nGROUP BY 1,2\nORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1061,14 +1055,8 @@ ...@@ -1061,14 +1055,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1239,14 +1227,8 @@ ...@@ -1239,14 +1227,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1417,14 +1399,8 @@ ...@@ -1417,14 +1399,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__time(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1593,14 +1569,8 @@ ...@@ -1593,14 +1569,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1774,14 +1744,8 @@ ...@@ -1774,14 +1744,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1955,14 +1919,8 @@ ...@@ -1955,14 +1919,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2136,14 +2094,8 @@ ...@@ -2136,14 +2094,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value one') as metric, valueOne FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1", "rawSql": "SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values WHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), CONCAT(measurement, ' - value two') as metric, valueTwo FROM metric_values \nWHERE $__timeFilter(time) AND measurement IN($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2280,7 +2232,10 @@ ...@@ -2280,7 +2232,10 @@
"refresh": false, "refresh": false,
"schemaVersion": 16, "schemaVersion": 16,
"style": "dark", "style": "dark",
"tags": ["gdev", "mysql"], "tags": [
"gdev",
"mysql"
],
"templating": { "templating": {
"list": [ "list": [
{ {
...@@ -2405,5 +2360,5 @@ ...@@ -2405,5 +2360,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - MySQL (unittest)", "title": "Datasource tests - MySQL (unittest)",
"uid": "Hmf8FDkmz", "uid": "Hmf8FDkmz",
"version": 12 "version": 1
} }
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532619575136, "iteration": 1532951521836,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -871,14 +871,8 @@ ...@@ -871,14 +871,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize'), \n measurement || ' - value one' as metric, \n avg(\"valueOne\") as \"valueOne\"\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n measurement in($metric)\nGROUP BY 1, 2\nORDER BY 1", "rawSql": "SELECT \n $__timeGroup(time, '$summarize'), \n measurement, \n avg(\"valueOne\") as \"valueOne\",\n avg(\"valueTwo\") as \"valueTwo\"\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n measurement in($metric)\nGROUP BY 1, 2\nORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize'), \n measurement || ' - value two' as metric, \n avg(\"valueTwo\") as \"valueTwo\"\nFROM\n metric_values \nWHERE\n $__timeFilter(time) AND\n measurement in($metric)\nGROUP BY 1, 2\nORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1049,14 +1043,8 @@ ...@@ -1049,14 +1043,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1227,14 +1215,8 @@ ...@@ -1227,14 +1215,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1405,14 +1387,8 @@ ...@@ -1405,14 +1387,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1581,14 +1557,8 @@ ...@@ -1581,14 +1557,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1762,14 +1732,8 @@ ...@@ -1762,14 +1732,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1943,14 +1907,8 @@ ...@@ -1943,14 +1907,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2124,14 +2082,8 @@ ...@@ -2124,14 +2082,8 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value one' as metric, \"valueOne\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement, \"valueOne\", \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement || ' - value two' as metric, \"valueTwo\" FROM metric_values \nWHERE $__timeFilter(time) AND measurement in($metric) ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2268,7 +2220,10 @@ ...@@ -2268,7 +2220,10 @@
"refresh": false, "refresh": false,
"schemaVersion": 16, "schemaVersion": 16,
"style": "dark", "style": "dark",
"tags": ["gdev", "postgres"], "tags": [
"gdev",
"postgres"
],
"templating": { "templating": {
"list": [ "list": [
{ {
...@@ -2397,5 +2352,5 @@ ...@@ -2397,5 +2352,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - Postgres (unittest)", "title": "Datasource tests - Postgres (unittest)",
"uid": "vHQdlVziz", "uid": "vHQdlVziz",
"version": 17 "version": 1
} }
\ No newline at end of file
...@@ -148,7 +148,8 @@ The resulting table panel: ...@@ -148,7 +148,8 @@ The resulting table panel:
## Time series queries ## Time series queries
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must must have a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch in seconds. You may return a column named `metric` that is used as metric name for the value column. Any column except `time` and `metric` is treated as a value column. If you omit the `metric` column, tha name of the value column will be the metric name. You may select multiple value columns, each will have its name as metric. If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must must have a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch in seconds. You may return a column named `metric` that is used as metric name for the value column. Any column except `time` and `metric` is treated as a value column. If you omit the `metric` column, the name of the value column will be the metric name. You may select multiple value columns, each will have its name as metric.
If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+).
**Example database table:** **Example database table:**
......
...@@ -104,6 +104,7 @@ The resulting table panel: ...@@ -104,6 +104,7 @@ The resulting table panel:
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch. If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch.
Any column except `time` and `metric` is treated as a value column. Any column except `time` and `metric` is treated as a value column.
You may return a column named `metric` that is used as metric name for the value column. You may return a column named `metric` that is used as metric name for the value column.
If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+).
**Example with `metric` column:** **Example with `metric` column:**
......
...@@ -102,6 +102,7 @@ The resulting table panel: ...@@ -102,6 +102,7 @@ The resulting table panel:
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch. If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a sql datetime or any numeric datatype representing unix epoch.
Any column except `time` and `metric` is treated as a value column. Any column except `time` and `metric` is treated as a value column.
You may return a column named `metric` that is used as metric name for the value column. You may return a column named `metric` that is used as metric name for the value column.
If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+).
**Example with `metric` column:** **Example with `metric` column:**
......
...@@ -610,6 +610,31 @@ func TestMSSQL(t *testing.T) { ...@@ -610,6 +610,31 @@ func TestMSSQL(t *testing.T) {
So(queryResult.Series[1].Name, ShouldEqual, "valueTwo") So(queryResult.Series[1].Name, ShouldEqual, "valueTwo")
}) })
Convey("When doing a metric query with metric column and multiple value columns", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": "SELECT $__timeEpoch(time), measurement, valueOne, valueTwo FROM metric_values ORDER BY 1",
"format": "time_series",
}),
RefId: "A",
},
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A valueOne")
So(queryResult.Series[1].Name, ShouldEqual, "Metric A valueTwo")
So(queryResult.Series[2].Name, ShouldEqual, "Metric B valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
})
Convey("Given a stored procedure that takes @from and @to in epoch time", func() { Convey("Given a stored procedure that takes @from and @to in epoch time", func() {
sql := ` sql := `
IF object_id('sp_test_epoch') IS NOT NULL IF object_id('sp_test_epoch') IS NOT NULL
...@@ -635,21 +660,9 @@ func TestMSSQL(t *testing.T) { ...@@ -635,21 +660,9 @@ func TestMSSQL(t *testing.T) {
SELECT SELECT
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time, CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time,
measurement + ' - value one' as metric, measurement as metric,
avg(valueOne) as value avg(valueOne) as valueOne,
FROM avg(valueTwo) as valueTwo
metric_values
WHERE
time BETWEEN DATEADD(s, @from, '1970-01-01') AND DATEADD(s, @to, '1970-01-01') AND
(@metric = 'ALL' OR measurement = @metric)
GROUP BY
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval,
measurement
UNION ALL
SELECT
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time,
measurement + ' - value two' as metric,
avg(valueTwo) as value
FROM FROM
metric_values metric_values
WHERE WHERE
...@@ -692,10 +705,10 @@ func TestMSSQL(t *testing.T) { ...@@ -692,10 +705,10 @@ func TestMSSQL(t *testing.T) {
So(queryResult.Error, ShouldBeNil) So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4) So(len(queryResult.Series), ShouldEqual, 4)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A - value one") So(queryResult.Series[0].Name, ShouldEqual, "Metric A valueOne")
So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one") So(queryResult.Series[1].Name, ShouldEqual, "Metric A valueTwo")
So(queryResult.Series[2].Name, ShouldEqual, "Metric A - value two") So(queryResult.Series[2].Name, ShouldEqual, "Metric B valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B - value two") So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
}) })
}) })
...@@ -724,21 +737,9 @@ func TestMSSQL(t *testing.T) { ...@@ -724,21 +737,9 @@ func TestMSSQL(t *testing.T) {
SELECT SELECT
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time, CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time,
measurement + ' - value one' as metric, measurement as metric,
avg(valueOne) as value avg(valueOne) as valueOne,
FROM avg(valueTwo) as valueTwo
metric_values
WHERE
time BETWEEN @from AND @to AND
(@metric = 'ALL' OR measurement = @metric)
GROUP BY
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval,
measurement
UNION ALL
SELECT
CAST(ROUND(DATEDIFF(second, '1970-01-01', time)/CAST(@dInterval as float), 0) as bigint)*@dInterval as time,
measurement + ' - value two' as metric,
avg(valueTwo) as value
FROM FROM
metric_values metric_values
WHERE WHERE
...@@ -781,10 +782,10 @@ func TestMSSQL(t *testing.T) { ...@@ -781,10 +782,10 @@ func TestMSSQL(t *testing.T) {
So(queryResult.Error, ShouldBeNil) So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4) So(len(queryResult.Series), ShouldEqual, 4)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A - value one") So(queryResult.Series[0].Name, ShouldEqual, "Metric A valueOne")
So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one") So(queryResult.Series[1].Name, ShouldEqual, "Metric A valueTwo")
So(queryResult.Series[2].Name, ShouldEqual, "Metric A - value two") So(queryResult.Series[2].Name, ShouldEqual, "Metric B valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B - value two") So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
}) })
}) })
}) })
......
...@@ -634,6 +634,31 @@ func TestMySQL(t *testing.T) { ...@@ -634,6 +634,31 @@ func TestMySQL(t *testing.T) {
So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one") So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one")
}) })
Convey("When doing a metric query with metric column and multiple value columns", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": `SELECT $__time(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1,2`,
"format": "time_series",
}),
RefId: "A",
},
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A valueOne")
So(queryResult.Series[1].Name, ShouldEqual, "Metric A valueTwo")
So(queryResult.Series[2].Name, ShouldEqual, "Metric B valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
})
Convey("When doing a metric query grouping by time should return correct series", func() { Convey("When doing a metric query grouping by time should return correct series", func() {
query := &tsdb.TsdbQuery{ query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{ Queries: []*tsdb.Query{
......
...@@ -568,6 +568,31 @@ func TestPostgres(t *testing.T) { ...@@ -568,6 +568,31 @@ func TestPostgres(t *testing.T) {
So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one") So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one")
}) })
Convey("When doing a metric query with metric column and multiple value columns", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": `SELECT $__timeEpoch(time), measurement as metric, "valueOne", "valueTwo" FROM metric_values ORDER BY 1`,
"format": "time_series",
}),
RefId: "A",
},
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A valueOne")
So(queryResult.Series[1].Name, ShouldEqual, "Metric A valueTwo")
So(queryResult.Series[2].Name, ShouldEqual, "Metric B valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
})
Convey("When doing a metric query grouping by time should return correct series", func() { Convey("When doing a metric query grouping by time should return correct series", func() {
query := &tsdb.TsdbQuery{ query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{ Queries: []*tsdb.Query{
......
...@@ -75,6 +75,10 @@ var NewSqlQueryEndpoint = func(config *SqlQueryEndpointConfiguration, rowTransfo ...@@ -75,6 +75,10 @@ var NewSqlQueryEndpoint = func(config *SqlQueryEndpointConfiguration, rowTransfo
queryEndpoint.timeColumnNames = config.TimeColumnNames queryEndpoint.timeColumnNames = config.TimeColumnNames
} }
if len(config.MetricColumnTypes) > 0 {
queryEndpoint.metricColumnTypes = config.MetricColumnTypes
}
engineCache.Lock() engineCache.Lock()
defer engineCache.Unlock() defer engineCache.Unlock()
...@@ -229,6 +233,8 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows, ...@@ -229,6 +233,8 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
rowCount := 0 rowCount := 0
timeIndex := -1 timeIndex := -1
metricIndex := -1 metricIndex := -1
metricPrefix := false
var metricPrefixValue string
// check columns of resultset: a column named time is mandatory // check columns of resultset: a column named time is mandatory
// the first text column is treated as metric name unless a column named metric is present // the first text column is treated as metric name unless a column named metric is present
...@@ -247,6 +253,7 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows, ...@@ -247,6 +253,7 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
columnType := columnTypes[i].DatabaseTypeName() columnType := columnTypes[i].DatabaseTypeName()
for _, mct := range e.metricColumnTypes { for _, mct := range e.metricColumnTypes {
e.log.Info(mct)
if columnType == mct { if columnType == mct {
metricIndex = i metricIndex = i
continue continue
...@@ -256,6 +263,11 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows, ...@@ -256,6 +263,11 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
} }
} }
// use metric column as prefix with multiple value columns
if metricIndex != -1 && len(columnNames) > 3 {
metricPrefix = true
}
if timeIndex == -1 { if timeIndex == -1 {
return fmt.Errorf("Found no column named %s", strings.Join(e.timeColumnNames, " or ")) return fmt.Errorf("Found no column named %s", strings.Join(e.timeColumnNames, " or "))
} }
...@@ -301,7 +313,11 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows, ...@@ -301,7 +313,11 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
if metricIndex >= 0 { if metricIndex >= 0 {
if columnValue, ok := values[metricIndex].(string); ok { if columnValue, ok := values[metricIndex].(string); ok {
metric = columnValue if metricPrefix {
metricPrefixValue = columnValue
} else {
metric = columnValue
}
} else { } else {
return fmt.Errorf("Column metric must be of type %s. metric column name: %s type: %s but datatype is %T", strings.Join(e.metricColumnTypes, ", "), columnNames[metricIndex], columnTypes[metricIndex].DatabaseTypeName(), values[metricIndex]) return fmt.Errorf("Column metric must be of type %s. metric column name: %s type: %s but datatype is %T", strings.Join(e.metricColumnTypes, ", "), columnNames[metricIndex], columnTypes[metricIndex].DatabaseTypeName(), values[metricIndex])
} }
...@@ -318,6 +334,8 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows, ...@@ -318,6 +334,8 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
if metricIndex == -1 { if metricIndex == -1 {
metric = col metric = col
} else if metricPrefix {
metric = metricPrefixValue + " " + col
} }
series, exist := pointsBySeries[metric] series, exist := pointsBySeries[metric]
......
...@@ -39,9 +39,11 @@ ...@@ -39,9 +39,11 @@
<div class="gf-form" ng-show="ctrl.showHelp"> <div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info">Time series: <pre class="gf-form-pre alert alert-info">Time series:
- return column named time (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below. - return column named time (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below.
- optional: return column named metric to represent the series names.
- any other columns returned will be the time point values. - any other columns returned will be the time point values.
- if multiple value columns are present and a metric column is provided. the series name will be the combination of "MetricName - ValueColumnName". Optional:
- return column named <i>metric</i> to represent the series name.
- If multiple value columns are returned the metric column is used as prefix.
- If no column named metric is found the column name of the value column is used as series name
Table: Table:
- return any set of columns - return any set of columns
......
...@@ -40,7 +40,10 @@ ...@@ -40,7 +40,10 @@
<pre class="gf-form-pre alert alert-info">Time series: <pre class="gf-form-pre alert alert-info">Time series:
- return column named time or time_sec (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below. - return column named time or time_sec (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below.
- return column(s) with numeric datatype as values - return column(s) with numeric datatype as values
- (Optional: return column named <i>metric</i> to represent the series name. If no column named metric is found the column name of the value column is used as series name) Optional:
- return column named <i>metric</i> to represent the series name.
- If multiple value columns are returned the metric column is used as prefix.
- If no column named metric is found the column name of the value column is used as series name
Table: Table:
- return any set of columns - return any set of columns
......
...@@ -40,7 +40,10 @@ ...@@ -40,7 +40,10 @@
<pre class="gf-form-pre alert alert-info">Time series: <pre class="gf-form-pre alert alert-info">Time series:
- return column named <i>time</i> (UTC in seconds or timestamp) - return column named <i>time</i> (UTC in seconds or timestamp)
- return column(s) with numeric datatype as values - return column(s) with numeric datatype as values
- (Optional: return column named <i>metric</i> to represent the series name. If no column named metric is found the column name of the value column is used as series name) Optional:
- return column named <i>metric</i> to represent the series name.
- If multiple value columns are returned the metric column is used as prefix.
- If no column named metric is found the column name of the value column is used as series name
Table: Table:
- return any set of columns - return any set of columns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment