summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Hensman <richard@onevisionconsulting.co.uk>2012-07-18 14:09:10 (GMT)
committerJohn Mazzitelli <mazz@redhat.com>2012-08-06 18:59:57 (GMT)
commit9726761caf702f5a53f33ef2d957a84e55953196 (patch)
tree3ec5a0b20dfcfed7ecde10df85d4bb1a5cb2433d
parent5b37f7a17ef64863a810a5b92cbf885eca05dda3 (diff)
downloadrhq-9726761caf702f5a53f33ef2d957a84e55953196.zip
rhq-9726761caf702f5a53f33ef2d957a84e55953196.tar.gz
rhq-9726761caf702f5a53f33ef2d957a84e55953196.tar.xz
Add support for monitoring table spaces to the Oracle plugin
-rw-r--r--modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleTablespaceComponent.java83
-rw-r--r--modules/plugins/oracle/src/main/resources/META-INF/rhq-plugin.xml25
2 files changed, 106 insertions, 2 deletions
diff --git a/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleTablespaceComponent.java b/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleTablespaceComponent.java
new file mode 100644
index 0000000..e99787b
--- /dev/null
+++ b/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleTablespaceComponent.java
@@ -0,0 +1,83 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.plugins.oracle;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.core.util.jdbc.JDBCUtil;
+import org.rhq.plugins.database.AbstractDatabaseComponent;
+import org.rhq.plugins.database.DatabaseQueryUtility;
+
+/**
+ * Oracle Tablespace Component.
+ *
+ * @author Richard Hensman
+ */
+public class OracleTablespaceComponent extends AbstractDatabaseComponent implements MeasurementFacet {
+
+ private static final String SQL_AVAILABLE = "SELECT COUNT(*) FROM dba_tablespaces WHERE tablespace_name = ?";
+ private static final String SQL_VALUES =
+ "SELECT USED_SPACE usedSpace, TABLESPACE_SIZE totalSize, (USED_PERCENT/100) usedPercent " +
+ "FROM dba_tablespace_usage_metrics where tablespace_name = ?";
+
+
+ private static Log log = LogFactory.getLog(OracleTablespaceComponent.class);
+
+ public AvailabilityType getAvailability() {
+ PreparedStatement statement = null;
+ ResultSet resultSet = null;
+ try {
+ statement = getConnection().prepareStatement(SQL_AVAILABLE);
+ statement.setString(1, this.resourceContext.getResourceKey());
+ resultSet = statement.executeQuery();
+ if (resultSet.next() && (resultSet.getInt(1) == 1)) {
+ return AvailabilityType.UP;
+ }
+ } catch (SQLException e) {
+ log.debug("unable to query", e);
+ } finally {
+ JDBCUtil.safeClose(statement, resultSet);
+ }
+
+ return AvailabilityType.DOWN;
+ }
+
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
+ Map<String, Double> values = DatabaseQueryUtility.getNumericQueryValues(this, SQL_VALUES,
+ this.resourceContext.getResourceKey());
+ for (MeasurementScheduleRequest request : metrics) {
+ Double d = values.get(request.getName().toUpperCase(Locale.US));
+ if (d != null) {
+ report.addData(new MeasurementDataNumeric(request, d));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/modules/plugins/oracle/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/oracle/src/main/resources/META-INF/rhq-plugin.xml
index 00f0284..8ef56cb 100644
--- a/modules/plugins/oracle/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/oracle/src/main/resources/META-INF/rhq-plugin.xml
@@ -593,8 +593,29 @@
<c:simple-property name="description" default="Oracle User"/>
</plugin-configuration>
- <metric property="connections" displayName="Total Connections" displayType="summary"/>
- <metric property="active" displayName="Active Connections" displayType="summary"/>
+ <metric property="connections" displayName="Total Connections" displayType="summary"/>
+ <metric property="active" displayName="Active Connections" displayType="summary"/>
+
+ </service>
+
+ <service name="Oracle Tablespaces"
+ discovery="org.rhq.plugins.database.CustomTableRowDiscoveryComponent"
+ class="org.rhq.plugins.oracle.OracleTablespaceComponent">
+
+ <plugin-configuration>
+ <c:simple-property name="table" default="DBA_TABLESPACES"/>
+ <c:simple-property name="metricQuery" default="SELECT {key} FROM DBA_TABLESPACES"/>
+ <c:simple-property name="keyColumn" default="tablespace_name"/>
+ <c:simple-property name="name" default="{key}"/>
+ <c:simple-property name="description" default="Oracle Tablespace"/>
+ </plugin-configuration>
+
+ <!-- Space used in the tablespace (database blocks) -->
+ <metric property="usedSpace" displayName="Used Space" description="Space used in the tablespace (database blocks)" displayType="summary"/>
+ <!-- Total size of the tablespace (database blocks) -->
+ <metric property="totalSize" displayName="Total Size" description="Total size of the tablespace (database blocks)" displayType="summary"/>
+ <!-- Percentage of the tablespace used -->
+ <metric property="usedPercent" displayName="Used Percent" description="Percentage of the tablespace used" displayType="summary" units="percentage"/>
</service>