Commit 428225ca 428225ca598269dc4b5f19ff92d2feddfa67ce30 by Christian Gerdes

Added TNS support with failover in LILOM

GetServiceName can handle TNS con strings
No support yet in JavaMonWeb
1 parent 50c91927
javaw.exe -Dcom.sun.management.jmxremote.ssl=false -cp "wls-12.2.1.2.0.4/wljmxclient.jar;jconsole.1.8.0_91.jar" sun.tools.jconsole.JConsole "service:jmx:rmi:///jndi/iiop://damk321s2.da.kap.rsv.se:17010/weblogic.management.mbeanservers.runtime"
\ No newline at end of file
No preview for this file type
No preview for this file type
......@@ -6,6 +6,8 @@ import java.util.Hashtable;
import java.util.Properties;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class OraMon {
Connection conn = null;
......@@ -13,6 +15,7 @@ public class OraMon {
String conUser = "system";
String conPass = "passw0rd";
String dbName = null;
String serviceName = null;
Boolean isPDB = false;
Boolean isCDB = false;
......@@ -47,17 +50,30 @@ public class OraMon {
}
public String getServiceName() {
if(this.serviceName != null) return this.serviceName;
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);
if(this.conString.contains("SERVICE_NAME=")) {
//TNS format
Pattern pat = Pattern.compile("SERVICE_NAME=(\\w+)");
Matcher m = pat.matcher(this.conString);
if(m.find()) {
this.serviceName = m.group(1);
} else {
this.serviceName = null;
}
} else {
int last = this.conString.lastIndexOf('/');
if(last >=0)
this.serviceName = this.conString.substring(last +1);
else {
last = this.conString.lastIndexOf(':');
this.serviceName = this.conString.substring(last +1);
}
}
} else {
return null;
this.serviceName = null;
}
return this.serviceName;
}
//NUM_CPUS
......@@ -117,7 +133,13 @@ public class OraMon {
}
public String getDBName() {
return this.dbName;
// Returns the instance name unless we are a PDB, in that case the service name from the con string is returned instead.
if(isPDB) return getServiceName();
else return this.dbName;
}
public boolean isPDB() {
return isPDB;
}
public double getOsBusyPercent() throws Throwable {
......@@ -257,42 +279,52 @@ public class OraMon {
// 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) {
if(rset.getInt(1) == 1) {
// We found the containers view. Enable container handling
hasContainers = true;
if(getServiceName().equals(this.dbName)) isCDB = true;
String serviceName = getServiceName();
if(serviceName != null) {
if(serviceName.equals(this.dbName)) isCDB = true;
else isPDB = true;
} else {
// Servicename is null, treat as CDB
isCDB = true;
isPDB = false;
}
}
}
}
// 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) {
// We should as the CDB object for our data
if(isPDB) {
// TODO: Find the CDB OraMon object, get the data we need from it's cached CON tables
} else {
// All other cases (CDB or an instance without containers)
//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();
niwTime.update(rset.getLong(2), rset.getTimestamp(1));
cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
rset.close();
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
}
//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();
niwTime.update(rset.getLong(2), rset.getTimestamp(1));
cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
rset.close();
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
stmt.close();
getDataSucess++;
lastFetchTSns = System.nanoTime();
......
......@@ -11,7 +11,26 @@ public class TestRunner {
/**
* @param args
*/
public static void main(String[] args) throws Throwable{
public static void main(String[] args) throws Throwable {
//runner1();
//test1();
testTns();
}
public static void test1() throws Throwable {
OraMon mon = new OraMon("jdbc:oracle:thin:@//u02822.kap.rsv.se:1526/DB1K06","dbsnmp","dbsnmp"); // CDB
System.out.println("getData returned: " + mon.getData());
System.out.println("getDatabaseName: " + mon.getDBName());
}
public static void testTns() throws Throwable {
OraMon mon = new OraMon("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=u00153.kap.rsv.se)(Port=1526))(ADDRESS=(PROTOCOL=TCP)(Host=u00154.kap.rsv.se)(Port=1526)))(CONNECT_DATA=(SERVICE_NAME=PB1K001)))","dbsnmp","dbsnmp"); // PDB using TNS
System.out.println("getData returned: " + mon.getData());
System.out.println("getDatabaseName: " + mon.getDBName());
System.out.println("getServiceName: " + mon.getServiceName());
}
public static void runner1() throws Throwable {
// TODO Auto-generated method stub
//ArrayList<OraMon> oraList = new ArrayList<OraMon>();
......