Commit 62174c81 by Marcus Efraimsson

mssql: cleanup and minor changes

parent 8c2f3f76
...@@ -5,14 +5,16 @@ class MssqlConfigCtrl { ...@@ -5,14 +5,16 @@ class MssqlConfigCtrl {
static templateUrl = 'partials/config.html'; static templateUrl = 'partials/config.html';
} }
const defaultQuery = `SELECT TOP 100 const defaultQuery = `SELECT
$__utcTime(<time_column>), <time_column> as time,
<text_column> as text, <text_column> as text,
<tags_column> as tags <tags_column> as tags
FROM <table name> FROM
WHERE $__timeFilter(time_column) <table name>
ORDER BY <time_column> ASC WHERE
`; $__timeFilter(time_column)
ORDER BY
<time_column> ASC`;
class MssqlAnnotationsQueryCtrl { class MssqlAnnotationsQueryCtrl {
static templateUrl = 'partials/annotations.editor.html'; static templateUrl = 'partials/annotations.editor.html';
......
...@@ -18,23 +18,23 @@ ...@@ -18,23 +18,23 @@
<div class="gf-form" ng-show="ctrl.showHelp"> <div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6> <pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6>
An annotation is an event that is overlayed on top of graphs. The query can have up to four columns per row, the <b>time</b> column is mandatory. Annotation rendering is expensive so it is important to limit the number of rows returned. An annotation is an event that is overlayed on top of graphs. The query can have up to three columns per row, the <b>time</b> column is mandatory. Annotation rendering is expensive so it is important to limit the number of rows returned.
- column with alias: <b>time</b> for the annotation event time (in UTC), as a unix time stamp or any sql native date datatype. - column with alias: <b>time</b> for the annotation event time (in UTC). Use unix timestamp in seconds or any native date data type.
- column with alias: <b>text</b> for the annotation text - column with alias: <b>text</b> for the annotation text.
- column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2' - column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'.
Macros: Macros:
- $__time(column) -&gt; column AS time - $__time(column) -&gt; column AS time
- $__utcTime(column) -&gt; DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time - $__utcTime(column) -&gt; DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time
- $__timeEpoch(column) -&gt; DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time - $__timeEpoch(column) -&gt; DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time
- $__timeFilter(column) -&gt; column &gt; DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column &lt; DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeFilter(column) -&gt; column &gt; DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column &lt; DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__unixEpochFilter(column) -&gt; column &gt; 1492750877 AND column &lt; 1492750877 - $__unixEpochFilter(column) -&gt; column &gt; 1492750877 AND column &lt; 1492750877
Or build your own conditionals using these macros which just return the values: Or build your own conditionals using these macros which just return the values:
- $__timeFrom() -&gt; DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeFrom() -&gt; DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__timeTo() -&gt; DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeTo() -&gt; DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__unixEpochFrom() -&gt; 1492750877 - $__unixEpochFrom() -&gt; 1492750877
- $__unixEpochTo() -&gt; 1492750877 - $__unixEpochTo() -&gt; 1492750877
</pre> </pre>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="gf-form-group"> <div class="gf-form-group">
<div class="gf-form max-width-30"> <div class="gf-form max-width-30">
<span class="gf-form-label width-7">Host</span> <span class="gf-form-label width-7">Host</span>
<input type="text" class="gf-form-input" ng-model='ctrl.current.url' placeholder="localhost:1433" bs-typeahead="{{['localhost:1433', '192.168.0.101:1433']}}" required></input> <input type="text" class="gf-form-input" ng-model='ctrl.current.url' placeholder="localhost:1433" bs-typeahead="{{['localhost:1433']}}" required></input>
</div> </div>
<div class="gf-form max-width-30"> <div class="gf-form max-width-30">
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements
like <code>USE otherdb;</code> and <code>DROP TABLE user;</code> would be executed. To protect against this we like <code>USE otherdb;</code> and <code>DROP TABLE user;</code> would be executed. To protect against this we
<strong>Highly</strong> recommmend you create a specific MSSQL user with restricted permissions. <strong>Highly</strong> recommmend you create a specific MSSQL user with restricted permissions.
Checkout the <a class="external-link" target="_blank" href="http://docs.grafana.org/features/datasources/mssql/">MSSQL Data Source Docs</a> for more information.
</p> </p>
</div> </div>
</div> </div>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<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 datatype. 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. - 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". - if multiple value columns are present and a metric column is provided. the series name will be the combination of "MetricName - ValueColumnName".
...@@ -48,15 +48,15 @@ Table: ...@@ -48,15 +48,15 @@ Table:
Macros: Macros:
- $__time(column) -&gt; column AS time - $__time(column) -&gt; column AS time
- $__utcTime(column) -&gt; DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time - $__utcTime(column) -&gt; DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time
- $__timeEpoch(column) -&gt; DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time - $__timeEpoch(column) -&gt; DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time
- $__timeFilter(column) -&gt; column &gt; DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column &lt; DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeFilter(column) -&gt; column &gt; DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column &lt; DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__unixEpochFilter(column) -&gt; column &gt; 1492750877 AND column &lt; 1492750877 - $__unixEpochFilter(column) -&gt; column &gt; 1492750877 AND column &lt; 1492750877
- $__timeGroup(column, '5m'[, fillvalue]) -&gt; cast(cast(DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column))/300 as int)*300 as int). Providing a <i>fillValue</i> of <i>NULL</i> or floating value will automatically fill empty series in timerange with that value. - $__timeGroup(column, '5m'[, fillvalue]) -&gt; cast(cast(DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column))/300 as int)*300 as int). Providing a <i>fillValue</i> of <i>NULL</i> or floating value will automatically fill empty series in timerange with that value.
Or build your own conditionals using these macros which just return the values: Or build your own conditionals using these macros which just return the values:
- $__timeFrom() -&gt; DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeFrom() -&gt; DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__timeTo() -&gt; DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') - $__timeTo() -&gt; DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
- $__unixEpochFrom() -&gt; 1492750877 - $__unixEpochFrom() -&gt; 1492750877
- $__unixEpochTo() -&gt; 1492750877 - $__unixEpochTo() -&gt; 1492750877
</pre> </pre>
......
...@@ -13,13 +13,15 @@ export interface QueryMeta { ...@@ -13,13 +13,15 @@ export interface QueryMeta {
} }
const defaultQuery = `SELECT const defaultQuery = `SELECT
$__utcTime(<time_column>), $__timeEpoch(<time_column>),
<value column> as value, <value column> as value,
<series name column> as metric <series name column> as metric
FROM <table name> FROM
WHERE $__timeFilter(time_column) <table name>
ORDER BY <time_column> ASC WHERE
`; $__timeFilter(time_column)
ORDER BY
<time_column> ASC`;
export class MssqlQueryCtrl extends QueryCtrl { export class MssqlQueryCtrl extends QueryCtrl {
static templateUrl = 'partials/query.editor.html'; static templateUrl = 'partials/query.editor.html';
......
...@@ -112,10 +112,6 @@ export default class ResponseParser { ...@@ -112,10 +112,6 @@ export default class ResponseParser {
for (let i = 0; i < table.columns.length; i++) { for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time') { if (table.columns[i].text === 'time') {
timeColumnIndex = i; timeColumnIndex = i;
} else if (table.columns[i].text === 'title') {
return this.$q.reject({
message: 'The title column for annotations is deprecated, now only a column named text is returned',
});
} else if (table.columns[i].text === 'text') { } else if (table.columns[i].text === 'text') {
textColumnIndex = i; textColumnIndex = i;
} else if (table.columns[i].text === 'tags') { } else if (table.columns[i].text === 'tags') {
......
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