mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
mssql: cleanup and minor changes
This commit is contained in:
@@ -5,14 +5,16 @@ class MssqlConfigCtrl {
|
||||
static templateUrl = 'partials/config.html';
|
||||
}
|
||||
|
||||
const defaultQuery = `SELECT TOP 100
|
||||
$__utcTime(<time_column>),
|
||||
const defaultQuery = `SELECT
|
||||
<time_column> as time,
|
||||
<text_column> as text,
|
||||
<tags_column> as tags
|
||||
FROM <table name>
|
||||
WHERE $__timeFilter(time_column)
|
||||
ORDER BY <time_column> ASC
|
||||
`;
|
||||
FROM
|
||||
<table name>
|
||||
WHERE
|
||||
$__timeFilter(time_column)
|
||||
ORDER BY
|
||||
<time_column> ASC`;
|
||||
|
||||
class MssqlAnnotationsQueryCtrl {
|
||||
static templateUrl = 'partials/annotations.editor.html';
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
|
||||
<div class="gf-form" ng-show="ctrl.showHelp">
|
||||
<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>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>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>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'.
|
||||
|
||||
|
||||
Macros:
|
||||
- $__time(column) -> column AS time
|
||||
- $__utcTime(column) -> DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time
|
||||
- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time
|
||||
- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__utcTime(column) -> DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time
|
||||
- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time
|
||||
- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__unixEpochFilter(column) -> column > 1492750877 AND column < 1492750877
|
||||
|
||||
Or build your own conditionals using these macros which just return the values:
|
||||
- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__unixEpochFrom() -> 1492750877
|
||||
- $__unixEpochTo() -> 1492750877
|
||||
</pre>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="gf-form-group">
|
||||
<div class="gf-form max-width-30">
|
||||
<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 class="gf-form max-width-30">
|
||||
@@ -32,8 +32,6 @@
|
||||
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
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
<div class="gf-form" ng-show="ctrl.showHelp">
|
||||
<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.
|
||||
- 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".
|
||||
@@ -48,15 +48,15 @@ Table:
|
||||
|
||||
Macros:
|
||||
- $__time(column) -> column AS time
|
||||
- $__utcTime(column) -> DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time
|
||||
- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time
|
||||
- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__utcTime(column) -> DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time
|
||||
- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time
|
||||
- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__unixEpochFilter(column) -> column > 1492750877 AND column < 1492750877
|
||||
- $__timeGroup(column, '5m'[, fillvalue]) -> 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:
|
||||
- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
|
||||
- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
|
||||
- $__unixEpochFrom() -> 1492750877
|
||||
- $__unixEpochTo() -> 1492750877
|
||||
</pre>
|
||||
|
||||
@@ -13,13 +13,15 @@ export interface QueryMeta {
|
||||
}
|
||||
|
||||
const defaultQuery = `SELECT
|
||||
$__utcTime(<time_column>),
|
||||
$__timeEpoch(<time_column>),
|
||||
<value column> as value,
|
||||
<series name column> as metric
|
||||
FROM <table name>
|
||||
WHERE $__timeFilter(time_column)
|
||||
ORDER BY <time_column> ASC
|
||||
`;
|
||||
FROM
|
||||
<table name>
|
||||
WHERE
|
||||
$__timeFilter(time_column)
|
||||
ORDER BY
|
||||
<time_column> ASC`;
|
||||
|
||||
export class MssqlQueryCtrl extends QueryCtrl {
|
||||
static templateUrl = 'partials/query.editor.html';
|
||||
|
||||
@@ -112,10 +112,6 @@ export default class ResponseParser {
|
||||
for (let i = 0; i < table.columns.length; i++) {
|
||||
if (table.columns[i].text === 'time') {
|
||||
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') {
|
||||
textColumnIndex = i;
|
||||
} else if (table.columns[i].text === 'tags') {
|
||||
|
||||
Reference in New Issue
Block a user