# OracleDB Exporter

This page describes how to set up an OracleDB exporter in order to gather metrics regarding an Oracle Database instance through the Prometheus provider.

## Installation <a href="#installation" id="installation"></a>

The OracleDB exporter repository is available on the [official project page](https://github.com/iamseth/oracledb_exporter). The suggested deploy mode is through a [Docker image](https://hub.docker.com/r/prom/cloudwatch-exporter/), since the Prometheus instance can easily access the running container through the Akamas network.

Use the following command line to run the container, where `cust-metrics.toml` is your configuration file defining the queries for additional custom metrics (see paragraph below) and `DATA_SOURCE_NAME` an environment variable containing the Oracle EasyConnect string:

```yaml
docker run -d --name oracledb_exporter --restart always \
  --network akamas -p 9161:9161 \
  -v ~/oracledb_exporter/cust-metrics.toml:/cust-metrics.toml \
  -e CUSTOM_METRICS=/cust-metrics.toml \
  -e DATA_SOURCE_NAME="username/password@//oracledb.mycompany.com/service" \
  iamseth/oracledb_exporter
```

You can refer to the [official guide](https://github.com/prometheus/cloudwatch_exporter) for more details or alternative deployment modes.

## Custom queries <a href="#custom-queries" id="custom-queries"></a>

It is possible to define additional queries to expose custom metrics using any data in the database instance that is readable by the monitoring user (see [the guide](https://github.com/iamseth/oracledb_exporter#custom-metrics) for more details about the syntax).

### Custom Configuration file

The following is an example of exporting system metrics from the Dynamic Performance (V$) Views used by the Prometheus provider default queries for the [Oracle Database optimization pack](https://docs.akamas.io/akamas-docs/3.6/reference/optimization-packs/oracle-database-pack):

```toml
[[metric]]
context= "memory"
labels= [ "component" ]
metricsdesc= { size="Component memory extracted from v$memory_dynamic_components in Oracle." }
request = '''
SELECT component, current_size as "size"
FROM V$MEMORY_DYNAMIC_COMPONENTS
UNION
SELECT name, bytes as "size"
FROM V$SGAINFO
WHERE name in ('Free SGA Memory Available', 'Redo Buffers', 'Maximum SGA Size')
'''

[[metric]]
context = "activity"
metricsdesc = { value="Generic counter metric from v$sysstat view in Oracle." }
fieldtoappend = "name"
request = '''
SELECT name, value
FROM V$SYSSTAT WHERE name IN (
  'execute count',
  'user commits', 'user rollbacks',
  'db block gets from cache', 'consistent gets from cache', 'physical reads cache', /* CACHE */
  'redo log space requests'
 )
 '''

[[metric]]
context = "system_event"
labels = [ "event", "wait_class" ]
request = '''
SELECT
  event, wait_class,
  total_waits, time_waited
FROM V$SYSTEM_EVENT
'''
[metric.metricsdesc]
  total_waits= "Total number of waits for the event as per V$SYSTEM_EVENT in Oracle."
  time_waited= "Total time waited for the event (in hundredths of seconds) as per V$SYSTEM_EVENT in Oracle."
```
