Commit 50c91927 50c91927bb97dc82a9669fdf3920ad80f418914b by Christian Gerdes

Started implementing support for CDB/PDB handling. Experimental commit.

1 parent c3640d40
package se.lil.om;
import java.sql.*;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Properties;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -12,6 +14,13 @@ public class OraMon {
String conPass = "passw0rd";
String dbName = null;
Boolean isPDB = false;
Boolean isCDB = false;
Boolean hasContainers = null;
OraMon containerDB = null;
private Hashtable<String, OraMon> myPDBs = null;
public static final int SYSSTAT = 1;
public static final int OSSTAT = 2;
......@@ -37,6 +46,20 @@ public class OraMon {
return this.conString;
}
public String getServiceName() {
if(this.conString != null) {
int last = this.conString.lastIndexOf('/');
if(last >=0)
return this.conString.substring(last +1);
else {
last = this.conString.lastIndexOf(':');
return this.conString.substring(last +1);
}
} else {
return null;
}
}
//NUM_CPUS
int numCpus = 0;
public long getNumberOfCPUs() throws Throwable {
......@@ -168,19 +191,27 @@ public class OraMon {
}
long lastFetchTSns = 0;
public boolean getData(long ageTs) throws Throwable {
if ((System.nanoTime() - lastFetchTSns) > (ageTs * 1000 * 1000 * 1000)) return getData();
else return false;
}
public long getAgeTs() {
return (System.nanoTime() - lastFetchTSns)/(1000*1000*1000);
}
public boolean getData() throws Throwable {
return getData(0);
}
Lock lock = new ReentrantLock();
Throwable lastEx = null;
public boolean getData() throws Throwable {
public boolean getData(long ageTs) throws Throwable {
//Check age
if ((System.nanoTime() - lastFetchTSns) < (ageTs * 1000 * 1000 * 1000)) return false;
//Bail out if we are a PDB and ask the CDB OraMon object to update us
if(isPDB) {
if(containerDB != null) return containerDB.getData(ageTs);
// If we get here its strange. We know we are a PDB but we have no CDB object.
// Lets see if we ever end up here ;)
}
// Start thread safe
// Try to get a lock
boolean haveLock = lock.tryLock();
......@@ -213,7 +244,7 @@ public class OraMon {
Statement stmt = conn.createStatement();
ResultSet rset = null;
//Get the database name once
//Get the database name once // Currently always gets the CDB name
if(this.dbName == null) {
rset = stmt.executeQuery("select value from V$SYSTEM_PARAMETER where name = 'db_name'");
rset.next();
......@@ -221,12 +252,37 @@ public class OraMon {
rset.close();
}
// Check if we can have containers
if(hasContainers == null) {
// We don't know, check if the CONTAINERS view exists in the database
rset = stmt.executeQuery("select count(*) from SYS.ALL_VIEWS where VIEW_NAME = 'V_$CONTAINERS'");
if(rset.next()) {
if(rset.getInt(0) == 1) {
// We found the containers view. Enable container handling
hasContainers = true;
if(getServiceName().equals(this.dbName)) isCDB = true;
}
}
}
// If we have containers, but we are not the CDB, then we are a PDB.
// At this point we should close the connections, and ask the CDB OraMon object to getData() instead, and update us.
if(hasContainers && isCDB == false) {
}
//Get the entire V_$OSSTAT table from DB
colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
//Set numCpus
this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
// Get OS Load
osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
// SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
// Get DB CPU use time
rset = stmt.executeQuery("select systimestamp, s.value as NIWT, t.value as DBCPU from V$SYSSTAT s, V$SYS_TIME_MODEL t where s.name='non-idle wait time' and t.STAT_NAME='DB CPU'");
rset.next();
......@@ -234,12 +290,6 @@ public class OraMon {
cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
rset.close();
// cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"));
// niwTime.update(stmt.executeQuery("select systimestamp, value from V$SYSSTAT where name='non-idle wait time'"));
// Get OS Load
osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
......