-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [oracle] adding oracle integration. * [oracle] preparing travis for oracle integration tests. * [oracle][travis] get CI kickstarted. [oracle][travis] enable agreement switch... * [oracle] fix helper script on linux - handle weird exception. * [oracle] rebuild ldconfig with sudo * [oracle] cannot catch unimportated exception - be generic. [oracle][test] lower cx_Oracle dep, issue with version 6.0 * [oracle][travis] make symlink only if not present. * [oracle] improve connection string generaiton. * [oracle][test] fix container boot-up, cache DB, work locally. * [oracle][test] actually assert something. * [oracle] disable on windows until cx_Oracle 6.0 is fixed. There's an issue with the current pypi release see [this](oracle/python-cx_Oracle#64) * [oracle] bumping cx_Oracle to fixed 6.0.1 version. * Safecoding tablespace check to avoid divide by zero error. * [oracle] Allowing for multiple datafiles and large datafiles * [oracle] Increasing version number. * Update manifest.json [oracle] Removing version bump as requested. * [oracle] adding db setup scripts for XE. [oracle] load setup scripts. [oracle][test] setup test, just play with DB a bit. * [oracle][test] unfortunately we have to wait for stats to populate (for now). [oracle] lint. * [oracle] updating README and manifest. [oracle] adding metadata, fixing typo. [oracle] fix copyritten notices. * [oracle] no need for constructor - just calling super. * [oracle] adding changelog.
- Loading branch information
Showing
16 changed files
with
1,560 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# CHANGELOG - oracle | ||
|
||
1.0.0 / Unreleased | ||
================== | ||
|
||
### Changes | ||
|
||
* [FEATURE] adds oracle integration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Oracle Integration | ||
|
||
## Overview | ||
|
||
Get metrics from oracle service in real time to: | ||
|
||
* Visualize and monitor oracle states | ||
* Be notified about oracle failovers and events. | ||
|
||
## Installation | ||
|
||
Install the `dd-check-oracle` package manually or with your favorite configuration manager | ||
|
||
We cannot ship the oracle `instantclient` libraries with the agent or the standalone check due to licensing issues. Although the required `cx_Oracle` python library will be bundled, you will still need to install the `instantclient` for it to work (hard-requirement). The steps to do so would trypically be: | ||
|
||
``` | ||
mkdir -p /opt/oracle/ && cd /opt/oracle/ | ||
# Download Oracle Instant Client (example dir: /opt/oracle) | ||
unzip /opt/oracle/instantclient-basic-linux.x64-12.1.0.2.0.zip | ||
unzip /opt/oracle/instantclient-sdk-linux.x64-12.1.0.2.0.zip | ||
export ORACLE_HOME=/opt/oracle/instantclient/ | ||
``` | ||
From this point we'll need to make sure the relevant oracle libs are in the `LD_LIBRARY_PATH`: | ||
|
||
``` | ||
if [ ! -e $ORACLE_HOME/libclntsh.so ]; then ln -s $ORACLE_HOME/libclntsh.so.12.1 $ORACLE_HOME/libclntsh.so; fi | ||
echo "$ORACLE_HOME" | sudo tee /etc/ld.so.conf.d/oracle_instantclient.conf | ||
sudo ldconfig | ||
``` | ||
|
||
That should make the oracle `instantclient` dynamic libs be reachable in the host system `LD_LIBRARY_PATH` and the python package `cx_Oracle`. | ||
|
||
Please do not hesitate to contact support or open an issue should you encounter any problems. | ||
|
||
## Configuration | ||
|
||
Edit the `oracle.yaml` file to point to your server and port, set the masters to monitor | ||
|
||
## Validation | ||
|
||
When you run `datadog-agent info` you should see something like the following: | ||
|
||
Checks | ||
====== | ||
|
||
oracle | ||
----------- | ||
- instance #0 [OK] | ||
- Collected 18 metrics, 0 events & 1 service checks | ||
|
||
## Compatibility | ||
|
||
The oracle check is currently compatible with the linux and darwin-based OS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# (C) Datadog, Inc. 2010-2017 | ||
# All rights reserved | ||
# Licensed under Simplified BSD License (see LICENSE) | ||
|
||
# stdlib | ||
|
||
# 3rd party | ||
try: | ||
import cx_Oracle | ||
except Exception as e: | ||
cx_Oracle = None | ||
|
||
# project | ||
from checks import AgentCheck | ||
|
||
EVENT_TYPE = SOURCE_TYPE_NAME = 'oracle' | ||
|
||
|
||
class Oracle(AgentCheck): | ||
|
||
SERVICE_CHECK_NAME = 'oracle.can_connect' | ||
SYS_METRICS = { | ||
'Buffer Cache Hit Ratio': 'oracle.buffer_cachehit_ratio', | ||
'Cursor Cache Hit Ratio': 'oracle.cursor_cachehit_ratio', | ||
'Library Cache Hit Ratio': 'oracle.library_cachehit_ratio', | ||
'Shared Pool Free %': 'oracle.shared_pool_free', | ||
'Physical Reads Per Sec': 'oracle.physical_reads', | ||
'Physical Writes Per Sec': 'oracle.physical_writes', | ||
'Enqueue Timeouts Per Sec': 'oracle.enqueue_timeouts', | ||
'GC CR Block Received Per Second': 'oracle.gc_cr_receive_time', | ||
'Global Cache Blocks Corrupted': 'oracle.cache_blocks_corrupt', | ||
'Global Cache Blocks Lost': 'oracle.cache_blocks_lost', | ||
'Logons Per Sec': 'oracle.logons', | ||
'Average Active Sessions': 'oracle.active_sessions', | ||
'Long Table Scans Per Sec': 'oracle.long_table_scans', | ||
'SQL Service Response Time': 'oracle.service_response_time', | ||
'User Rollbacks Per Sec': 'oracle.user_rollbacks', | ||
'Total Sorts Per User Call': 'oracle.sorts_per_user_call', | ||
'Rows Per Sort': 'oracle.rows_per_sort', | ||
'Disk Sort Per Sec': 'oracle.disk_sorts', | ||
'Memory Sorts Ratio': 'oracle.memory_sorts_ratio', | ||
'Database Wait Time Ratio': 'oracle.database_wait_time_ratio', | ||
'Enqueue Timeouts Per Sec': 'oracle.enqueue_timeouts', | ||
'Session Limit %': 'oracle.session_limit_usage', | ||
'Session Count': 'oracle.session_count', | ||
'Temp Space Used': 'oracle.temp_space_used', | ||
} | ||
|
||
def check(self, instance): | ||
if not cx_Oracle: | ||
msg = """Cannot run the Oracle check until the Oracle instant client is available: | ||
http://www.oracle.com/technetwork/database/features/instant-client/index.html | ||
You will also need to ensure the `LD_LIBRARY_PATH` is also updated so the libs | ||
are reachable. | ||
""" | ||
self.log.error(msg) | ||
return | ||
|
||
self.log.debug('Running cx_Oracle version {0}'.format(cx_Oracle.version)) | ||
server, user, password, service, tags = self._get_config(instance) | ||
|
||
if not server or not user: | ||
raise Exception("Oracle host and user are needed") | ||
|
||
con = self._get_connection(server, user, password, service) | ||
|
||
self._get_sys_metrics(con, tags) | ||
|
||
self._get_tablespace_metrics(con) | ||
|
||
def _get_config(self, instance): | ||
self.server = instance.get('server', None) | ||
user = instance.get('user', None) | ||
password = instance.get('password', None) | ||
service = instance.get('service_name', None) | ||
tags = instance.get('tags', None) | ||
return (self.server, user, password, service, tags) | ||
|
||
def _get_connection(self, server, user, password, service): | ||
self.service_check_tags = [ | ||
'server:%s' % server | ||
] | ||
connect_string = '{0}/{1}@//{2}/{3}'.format(user, password, server, service) | ||
try: | ||
con = cx_Oracle.connect(connect_string) | ||
self.log.debug("Connected to Oracle DB") | ||
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, | ||
tags=self.service_check_tags) | ||
except Exception, e: | ||
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, | ||
tags=self.service_check_tags) | ||
self.log.error(e) | ||
raise | ||
return con | ||
|
||
def _get_sys_metrics(self, con, tags): | ||
query = "SELECT METRIC_NAME, VALUE, BEGIN_TIME FROM GV$SYSMETRIC " \ | ||
"ORDER BY BEGIN_TIME" | ||
cur = con.cursor() | ||
cur.execute(query) | ||
for row in cur: | ||
metric_name = row[0] | ||
metric_value = row[1] | ||
if metric_name in self.SYS_METRICS: | ||
self.gauge(self.SYS_METRICS[metric_name], metric_value, tags=tags) | ||
|
||
def _get_tablespace_metrics(self, con): | ||
query = "SELECT TABLESPACE_NAME, sum(BYTES), sum(MAXBYTES) FROM sys.dba_data_files GROUP BY TABLESPACE_NAME" | ||
cur = con.cursor() | ||
cur.execute(query) | ||
for row in cur: | ||
tablespace_tag = 'tablespace:%s' % row[0] | ||
used = float(row[1]) | ||
size = float(row[2]) | ||
if (used >= size): | ||
in_use = 100 | ||
elif (used == 0) or (size == 0): | ||
in_use = 0 | ||
else: | ||
in_use = used / size * 100 | ||
|
||
self.gauge('oracle.tablespace.used', used, tags=[tablespace_tag]) | ||
self.gauge('oracle.tablespace.size', size, tags=[tablespace_tag]) | ||
self.gauge('oracle.tablespace.in_use', in_use, tags=[tablespace_tag]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
LICENSE AGREEMENT FOR CX_ORACLE | ||
|
||
Copyright 2016, 2017, Oracle and/or its affiliates. All rights reserved. | ||
|
||
Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. | ||
|
||
Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta, | ||
Canada. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions, and the disclaimer that follows. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions, and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the names of the copyright holders nor the names of any contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
DISCLAIMER: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
*AS IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
Computronix is a registered trademark of Computronix (Canada) Ltd. | ||
|
Oops, something went wrong.