@@ -43,7 +42,9 @@ To simplify syntax and to allow for dynamic parts, like date range filters, the
Macro example | Description
------------ | -------------
*$__time(dateColumn)* | Will be replaced by an expression to convert a DATETIME column type to unix timestamp and rename the it to `time_sec`. For example, *DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), dateColumn) ) as time_sec*
*$__time(dateColumn)* | Will rename the column to `time`. For example, *dateColumn AS time*.
*$__utcTime(dateColumn)* | Will be replaced by an expression to convert a DATETIME column type to UTC depending on the server's local timeoffset and rename it to `time`. For example, *DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), dateColumn) ) AS time*
*$__timeEpoch(dateColumn)* | Will be replaced by an expression to convert a DATETIME column type to unix timestamp and rename the it to `time`. For example, *DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), dateColumn) ) AS time*
*$__timeFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name. For example, *dateColumn >= DATEADD(s, 1494410783+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND dateColumn <= DATEADD(s, 1494497183+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')*
*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *DATEADD(second, 1494410783+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')*
*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *DATEADD(second, 1494497183+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')*
...
...
@@ -77,7 +78,7 @@ FROM INFORMATION_SCHEMA.COLUMNS
WHERETABLE_NAME='mssql_types';
```
You can control the name of the Table panel columns by using regular `as ` SQL column selection syntax.
You can control the name of the Table panel columns by using regular `AS ` SQL column selection syntax.
The resulting table panel:
...
...
@@ -85,23 +86,48 @@ The resulting table panel:
### Time series queries
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must follow these rules:
- Must be a column named `time_sec` representing a unix epoch in seconds.
- Must be a column named `value` representing the time series value.
- Must be a column named `metric` representing the time series name.
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 ommit 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 select multiple value columns along with a `metric` column, the names ("MetircName - ColumnName") will be combined to make the metric name.
Example with multiple `value` culumns combined with a `metric` column
```sql
SELECT
[time_date_time]as[time],
[value_double1]as[value1],
[value_int2]as[value2],
[metric_col]as[metric]
FROM[test_data]
WHERE$__timeFilter([time_date_time])
ORDERBY[time_date_time]
```
The result of the above query would look something like the below
![](/img/docs/v47/mssql_metric_value.png)
Currently, there is no support for a dynamic group by time based on time range & panel width.
This is something we plan to add.
...
...
@@ -138,7 +164,7 @@ You can also create nested variables. For example if you had another variable na
the hosts variable only show hosts from the current selected region with a query like this (if `region` is a multi-value variable then use the `IN` comparison operator rather than `=` to match against multiple values):
returnfmt.Errorf("Column metric must be of type CHAR, VARCHAR, NCHAR or NVARCHAR. metric column name: %s type: %s but datatype is %T",columnNames[metricIndex],columnTypes[metricIndex].DatabaseTypeName(),values[metricIndex])
So(column[13].(time.Time),ShouldHappenWithin,time.Duration(10*time.Second),time.Now().UTC().Truncate(24*time.Hour))// ShouldEqual dose not work here !!?
An annotation is an event that is overlayed on top of graphs. The query can have up to four columns per row, the time_sec 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 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.
- column with alias: <b>time_sec</b> for the annotation event. Format is UTC in seconds, use the below to convert a datetime column to UTC unix time stamp: