Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Oracle templates and variables
Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables. Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard. Grafana refers to such variables as template variables.
For an introduction to templates and variables, see the following topics:
To add a new Oracle query variable, see Add and manage variables. Use your Oracle data source as the data source.
An Oracle query can return things like measurement names, key names or key values that are shown as a dropdown select box.
Examples:
You can have a variable that contains all values for the hostname
column in the host
table.
SELECT hostname FROM host
A query can return multiple columns and Grafana will automatically create a list from them. For example, the query below will return a list with values from hostname
and hostname2
.
SELECT host.hostname, other_host.hostname2
FROM host
JOIN other_host ON host.city = other_host.city
To use time range dependent macros like $__timeFilter(column)
in your query, set the refresh mode of the template variable to On Time Range Change
.
SELECT event_name
FROM event_log
sWHERE $__timeFilter(time_column)
You can write a query that creates a key/value variable. The query returns two columns, one called __text
and the other __value
. The __text
column value should be unique. If it’s not unique, the first value is used. The options in the dropdown have a text and value that allows you to have the name as text and an id as the value. The following query has the hostname
as text and id
as the value:
SELECT hostname AS __text, id AS __value
FROM host
You can also create nested variables. You can create a variable called region
, and have the hosts
variable only show hosts from the current selected region with the following query:
SELECT hostname
FROM host
WHERE region = '$region'
If region
is a multi-value variable then use the IN
comparison operator rather than =
to match against multiple values.
Once you have created a variable, you can use it in Oracle queries by following variable syntax.