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) {
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)
return this.conString.substring(last +1);
this.serviceName = this.conString.substring(last +1);
else {
last = this.conString.lastIndexOf(':');
return this.conString.substring(last +1);
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,19 +279,28 @@ 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"));
......@@ -292,6 +323,7 @@ public class OraMon {
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
}
stmt.close();
getDataSucess++;
......
......@@ -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>();
......