Package oracle.jdbc.diagnostics

## Class Metrics

- java.lang.Object
- - oracle.jdbc.diagnostics.Metrics

Direct Known Subclasses:
  `MetricsImpl`

    public class Metrics
    extends java.lang.Object

The metrics of events that occur while establishing `Connection`s to the Oracle database.

Capturing metrics can be enabled globally by calling `enable(boolean)`. When enabled, the metrics of live connections' phases are captured, and aggregated on `Connection#close()`.

To print the aggregation of metrics, of all connections that were established and closed in this JVM process, to the `OutputStream`, call `print(OutputStream, TimeUnit)`.

To disable capturing of metrics, call `enable(boolean)`.

Metrics can also be enabled or disabled globally using the MBean operations. See `DiagnosticsMXBean.enableMetrics()` and `DiagnosticsMXBean.disableMetrics()`.

Metrics can be enabled at connection level using the property `OracleConnection.CONNECTION_PROPERTY_ENABLE_METRICS`.

### Nested Class Summary

Nested Classes
`static class` `Metrics.ConnectionEvent`
`static class` `Metrics.MetricReport` POJO used to expose metrics basic details

### Constructor Summary

Constructors
`Metrics()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected void` `add​(java.util.Map<java.lang.String,​long[]> connectionMetricsMap)` The metrics of connection are added to the consolidated data.
`void` `begin​(Metrics.ConnectionEvent event)` All begin and end calls are noop in this class because this class is instantiated when metrics capturing is disabled.
`static void` `clear()` Clear the metrics of events captured by the JDBC driver.
`void` `close()`
`static void` `enable​(boolean isEnabled)` Switch to turn metrics on or off programmatically.
`void` `end​(Metrics.ConnectionEvent event)`
`static java.lang.String` `getReport​(java.util.concurrent.TimeUnit timeUnit)` Returns the collected metrics.
`static Metrics.MetricReport` `getReport​(Metrics.ConnectionEvent event)` Gets metric report.
`static void` `print​(java.io.OutputStream outputStream, java.util.concurrent.TimeUnit timeUnit)` Prints the aggregation of metrics, of all connections that were established and closed in this JVM process, to the given `OutputStream`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Metrics

    public Metrics()

### Method Detail

#### enable

    public static void enable​(boolean isEnabled)

Switch to turn metrics on or off programmatically.

Parameters:
  `isEnabled` -

#### begin

    public void begin​(Metrics.ConnectionEvent event)

All begin and end calls are noop in this class because this class is instantiated when metrics capturing is disabled. The subclass of this is instantiated when metrics capturing is enabled. This is to avoid 'is capturing metrics enabled' checks in begin and end methods.

#### end

    public void end​(Metrics.ConnectionEvent event)

#### close

    public void close()

#### add

    protected void add​(java.util.Map<java.lang.String,​long[]> connectionMetricsMap)

The metrics of connection are added to the consolidated data.

Parameters:
  `connectionMetricsMap` -

#### clear

    public static void clear()

Clear the metrics of events captured by the JDBC driver.

#### getReport

    public static Metrics.MetricReport getReport​(Metrics.ConnectionEvent event)

Gets metric report.

Parameters:
  `event` - the metric to get report of.
Returns:
  `MetricReport` the report of that metric. Can be null.

#### getReport

    public static java.lang.String getReport​(java.util.concurrent.TimeUnit timeUnit)

Returns the collected metrics.

Parameters:
  `timeUnit` -
Returns:
  metrics

#### print

    public static void print​(java.io.OutputStream outputStream,
                             java.util.concurrent.TimeUnit timeUnit)
                      throws java.io.IOException

Prints the aggregation of metrics, of all connections that were established and closed in this JVM process, to the given `OutputStream`.

The metrics of live connections are aggregated only on `Connection#close()`.

Parameters:
  `outputStream` -
  `timeUnit` -
Throws:
  `java.io.IOException`