Oracle Database

Data SourcePREMIUM

Official Enterprise Oracle Datasource from the Grafana team
Premium

Premium plugins, along with support and assistance from the core team behind Grafana, are available with Grafana Enterprise.

Please sign up or log in to get started.

Sign Up
  • Setup
    Setup
  • List
    List
  • Dashboard
    Dashboard
  • Graph
    Graph
  • Table
    Table

Grafana Oracle Database Datasource

CircleCI

This is the Oracle Database Datasource that is used to connect to Oracle databases.

Table of contents

  1. Screenshots
  2. Installation
  3. Usage

Screenshots

This shows an example dashboard that is queries 3 different tables and displays the results as a graph, table, and a pie-chart.

Configuration

full dashboard

Datasource List with Oracle Configured

full dashboard

Full Dashboard

full dashboard

Example Graph

full dashboard

Example Table

full dashboard

Table Time Style

full dashboard

Installation

This plugin should extracted to /var/lib/grafana/plugins, which will create the directory /var/lib/grafana/plugins/oracle-datasource

Prerequisites

OS Packages

UBUNTU/DEBIAN

apt install libaio1 unzip

RHEL/CENTOS

yum install libaio1 unzip

Oracle Instant Client

The Oracle Instanct Client is included with the plugin, there is no additional configuration required.

Validate backend plugin dependencies

ldd /var/lib/grafana/plugins/oracle-datasource/dist/oracle-plugin_linux_amd64

You should see no missing library dependencies, the output should look like this:

root@311b997933b5:/var/lib/grafana/plugins/oracle-datasource/dist# ldd oracle-plugin_linux_amd64 
    linux-vdso.so.1 (0x00007ffda3690000)
    libaio.so.1 => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libaio.so.1 (0x00007fbf5a0de000)
    libclntsh.so.12.1 => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libclntsh.so.12.1 (0x00007fbf56639000)
    libmql1.so => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libmql1.so (0x00007fbf563c2000)
    libipc1.so => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libipc1.so (0x00007fbf55f8f000)
    libnnz12.so => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libnnz12.so (0x00007fbf55846000)
    libons.so => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libons.so (0x00007fbf555f8000)
    libclntshcore.so.12.1 => /var/lib/grafana/plugins/oracle-datasource/dist/./../lib/linux_x64/instantclient_12_2/libclntshcore.so.12.1 (0x00007fbf5502a000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbf54e0d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbf54a6e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbf5486a000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbf54566000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fbf5434e000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fbf54146000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fbf53f2f000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fbf5a2e0000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fbf53d18000)

Restart grafana-server

The grafana-server process will need to be restarted to pick up the new plugin. Typically:

service grafana-server restart

or

systemctl restart grafana-server

Validate Grafana Plugin Loads

The /var/log/grafana/grafana.log should contain this message:

grafana_1  | t=2019-02-21T22:21:58+0000 lvl=info msg="Registering plugin" logger=plugins name="Oracle Database"

Configuration

Select datasources on the left panel of Grafana.

select datasources

Select Add Datasource:

add datasources

Type in oracle to find the datasource:

filter datasources

Enter Oracle server details:

enter datasource detail datasource configured

Save and Test the datasource, you should see a green message with "Database Connection OK"

select datasources

Screenshot Details

The following tables and data were used to generate the example screenshots:

CREATE TABLE sql_types_1
(
  START_DATE DATE,
  PROGRAM_NAME VARCHAR2(256),
  STATUS_CODE VARCHAR2(10),
  DURATION FLOAT(126)
);

INSERT INTO sql_types_1
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG1',
  '0',
  255.0
);

INSERT INTO sql_types_1
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG2',
  '2',
  250.0
);

INSERT INTO sql_types_1
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG3NULL',
  '2',
  NULL);

CREATE TABLE sql_types_2
(
  START_DATE DATE,
  PROGRAM_NAME VARCHAR2(256),
  STATUS_CODE VARCHAR2(10),
  DURATION NUMBER(10)
);

INSERT INTO sql_types_2
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG3',
  '0',
  12
);

INSERT INTO sql_types_2
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG4',
  '2',
  24
);

CREATE TABLE sql_types_3
(
  START_DATE DATE,
  PROGRAM_NAME VARCHAR2(240),
  STATUS_CODE VARCHAR2(1),
  DURATION NUMBER(22)
);

INSERT INTO sql_types_3
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG5',
  '1',
  27
);

INSERT INTO sql_types_3
VALUES (
  (SELECT systimestamp FROM dual),
  'PROG6',
  '2',
  240
);

The queries used in Grafana look like this:

SELECT
  START_DATE AS time,
  PROGRAM_NAME AS metric,
  DURATION AS value
FROM sql_types_1

When querying for time-series data, the plugin requires the "time" "metric" and "value" fields to be mapped.

Troubleshooting

Enable plugin logs

In order to enable plugin logging add filters = plugins:debug to log section in grafana config (/etc/grafana/grafana.ini):

[log.console]
level = debug
filters = plugins:debug

Usage

Macros

To simplify syntax and to allow for dynamic parts, like date range filters, the query can contain macros.

Macro exampleDescription
$__time(dateColumn)Will be replaced by an expression to rename the column to time. For example, dateColumn as time
$__timeEpoch(dateColumn)Will be replaced by an expression to rename the column to time and converting the value to unix timestamp (in milliseconds).
$__timeFilter(dateColumn)Will be replaced by a time range filter using the specified column name. For example, dateColumn BETWEEN TO_DATE('19700101','yyyymmdd') + (1/24/60/60/1000) * 1500376552001 AND TO_DATE('19700101','yyyymmdd') + (1/24/60/60/1000) * 1500376552002
$__timeFrom()Will be replaced by the start of the currently active time selection converted to DATE data type. For example, TO_DATE('19700101','yyyymmdd') + (1/24/60/60/1000) * 1500376552001
$__timeTo()Will be replaced by the end of the currently active time selection converted to DATE data type.
$__timeGroup(dateColumn,'5m')Will be replaced by an expression usable in GROUP BY clause.
$__unixEpochFilter(dateColumn)Will be replaced by a time range filter using the specified column name with times represented as unix timestamp (in milliseconds). For example, dateColumn >= 1500376552001 AND dateColumn <= 1500376552002
$__unixEpochFrom()Will be replaced by the start of the currently active time selection as unix timestamp. For example, 1500376552001
$__unixEpochTo()Will be replaced by the end of the currently active time selection as unix timestamp. For example, 1500376552002

The query editor has a link named Generated SQL that shows up after a query as been executed, while in panel edit mode. Click on it and it will expand and show the raw interpolated SQL string that was executed.

Table queries

If the Format as query option is set to Table then you can basically do any type of SQL query. The table panel will automatically show the results of whatever columns & rows your query returns. You can control the name of the Table panel columns by using regular as SQL column selection syntax.

Time series queries

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 in seconds. 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.

Example with metric column

SELECT
  $__timeGroup(time_date_time, '5m') AS time,
  MIN(value_double),
  'MIN' as metric
FROM test_data
WHERE $__timeFilter(time_date_time)
GROUP BY $__timeGroup(time_date_time, '5m')
ORDER BY time

More Queries - using oracle-fake-data-gen

SELECT
  $__timeGroup(createdAt, '5m') AS time,
  MIN("value"),
  'MIN' as metric
FROM "grafana_metric"
WHERE $__timeFilter(createdAt)
GROUP BY $__timeGroup(createdAt, '5m')
ORDER BY time

Fake Data Time Series:

SELECT
  "createdAt",
  "value"
FROM "grafana_metric"
WHERE $__timeFilter(createdAt)
ORDER BY "createdAt" ASC
SELECT
  "createdAt" as time,
  "value" as value
FROM "grafana_metric"
WHERE $__timeFilter(createdAt)
ORDER BY time ASC

Useful Table Result:

select tc.table_name Table_name
,tc.column_id Column_id
,lower(tc.column_name) Column_name
,lower(tc.data_type) Data_type
,nvl(tc.data_precision,tc.data_length) Length
,lower(tc.data_scale) Data_scale
,tc.nullable nullable
FROM all_tab_columns tc
,all_tables t
WHERE tc.table_name = t.table_name

Templating

Instead of hard-coding things like server, application and sensor name in you metric queries you can use variables in their place. Variables are shown as dropdown select boxes at the top of the dashboard. These dropdowns makes it easy to change the data being displayed in your dashboard.

Query Variable

If you add a template variable of the type Query, you can write a Oracle query that can return things like measurement names, key names or key values that are shown as a dropdown select box.

For example, you can have a variable that contains all values for the hostname column in a table if you specify a query like this in the templating variable Query setting.

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 the refresh mode of the template variable needs to be set to On Time Range Change.

SELECT event_name FROM event_log WHERE $__timeFilter(time_column)

Another option is a query that can create a key/value variable. The query should return two columns that are named __text and __value. The __text column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with hostname as the text and id as the value:

SELECT hostname AS __text, id AS __value FROM host

You can also create nested variables. For example if you had another variable named region. Then you could have 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):

SELECT hostname FROM host WHERE region IN($region)

Using Variables in Queries

From Grafana 4.3.0 to 4.6.0, template variables are always quoted automatically so if it is a string value do not wrap them in quotes in where clauses.

From Grafana 4.7.0, template variable values are only quoted when the template variable is a multi-value.

If the variable is a multi-value variable then use the IN comparison operator rather than = to match against multiple values.

There are two syntaxes:

$<varname> Example with a template variable named hostname:

SELECT
  atimestamp as time,
  aint as value
FROM table
WHERE $__timeFilter(atimestamp) AND hostname IN($hostname)
ORDER BY atimestamp ASC

[[varname]] Example with a template variable named hostname:

SELECT
  atimestamp as time,
  aint as value
FROM table
WHERE $__timeFilter(atimestamp) AND hostname IN([[hostname]])
ORDER BY atimestamp ASC
Install Plugin

Version

Dependencies:
  • Grafana 5.x.x