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
1 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 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; ...@@ -6,6 +6,8 @@ import java.util.Hashtable;
6 import java.util.Properties; 6 import java.util.Properties;
7 import java.util.concurrent.locks.Lock; 7 import java.util.concurrent.locks.Lock;
8 import java.util.concurrent.locks.ReentrantLock; 8 import java.util.concurrent.locks.ReentrantLock;
9 import java.util.regex.Matcher;
10 import java.util.regex.Pattern;
9 11
10 public class OraMon { 12 public class OraMon {
11 Connection conn = null; 13 Connection conn = null;
...@@ -13,6 +15,7 @@ public class OraMon { ...@@ -13,6 +15,7 @@ public class OraMon {
13 String conUser = "system"; 15 String conUser = "system";
14 String conPass = "passw0rd"; 16 String conPass = "passw0rd";
15 String dbName = null; 17 String dbName = null;
18 String serviceName = null;
16 19
17 Boolean isPDB = false; 20 Boolean isPDB = false;
18 Boolean isCDB = false; 21 Boolean isCDB = false;
...@@ -47,17 +50,30 @@ public class OraMon { ...@@ -47,17 +50,30 @@ public class OraMon {
47 } 50 }
48 51
49 public String getServiceName() { 52 public String getServiceName() {
53 if(this.serviceName != null) return this.serviceName;
50 if(this.conString != null) { 54 if(this.conString != null) {
51 int last = this.conString.lastIndexOf('/'); 55 if(this.conString.contains("SERVICE_NAME=")) {
52 if(last >=0) 56 //TNS format
53 return this.conString.substring(last +1); 57 Pattern pat = Pattern.compile("SERVICE_NAME=(\\w+)");
54 else { 58 Matcher m = pat.matcher(this.conString);
55 last = this.conString.lastIndexOf(':'); 59 if(m.find()) {
56 return this.conString.substring(last +1); 60 this.serviceName = m.group(1);
61 } else {
62 this.serviceName = null;
63 }
64 } else {
65 int last = this.conString.lastIndexOf('/');
66 if(last >=0)
67 this.serviceName = this.conString.substring(last +1);
68 else {
69 last = this.conString.lastIndexOf(':');
70 this.serviceName = this.conString.substring(last +1);
71 }
57 } 72 }
58 } else { 73 } else {
59 return null; 74 this.serviceName = null;
60 } 75 }
76 return this.serviceName;
61 } 77 }
62 78
63 //NUM_CPUS 79 //NUM_CPUS
...@@ -117,7 +133,13 @@ public class OraMon { ...@@ -117,7 +133,13 @@ public class OraMon {
117 } 133 }
118 134
119 public String getDBName() { 135 public String getDBName() {
120 return this.dbName; 136 // Returns the instance name unless we are a PDB, in that case the service name from the con string is returned instead.
137 if(isPDB) return getServiceName();
138 else return this.dbName;
139 }
140
141 public boolean isPDB() {
142 return isPDB;
121 } 143 }
122 144
123 public double getOsBusyPercent() throws Throwable { 145 public double getOsBusyPercent() throws Throwable {
...@@ -257,42 +279,52 @@ public class OraMon { ...@@ -257,42 +279,52 @@ public class OraMon {
257 // We don't know, check if the CONTAINERS view exists in the database 279 // We don't know, check if the CONTAINERS view exists in the database
258 rset = stmt.executeQuery("select count(*) from SYS.ALL_VIEWS where VIEW_NAME = 'V_$CONTAINERS'"); 280 rset = stmt.executeQuery("select count(*) from SYS.ALL_VIEWS where VIEW_NAME = 'V_$CONTAINERS'");
259 if(rset.next()) { 281 if(rset.next()) {
260 if(rset.getInt(0) == 1) { 282 if(rset.getInt(1) == 1) {
261 // We found the containers view. Enable container handling 283 // We found the containers view. Enable container handling
262 hasContainers = true; 284 hasContainers = true;
263 if(getServiceName().equals(this.dbName)) isCDB = true; 285 String serviceName = getServiceName();
286 if(serviceName != null) {
287 if(serviceName.equals(this.dbName)) isCDB = true;
288 else isPDB = true;
289 } else {
290 // Servicename is null, treat as CDB
291 isCDB = true;
292 isPDB = false;
293 }
264 } 294 }
265 } 295 }
266 } 296 }
267 297
268 // If we have containers, but we are not the CDB, then we are a PDB. 298 // If we have containers, but we are not the CDB, then we are a PDB.
269 // At this point we should close the connections, and ask the CDB OraMon object to getData() instead, and update us. 299 // We should as the CDB object for our data
270 if(hasContainers && isCDB == false) { 300 if(isPDB) {
301 // TODO: Find the CDB OraMon object, get the data we need from it's cached CON tables
302 } else {
303 // All other cases (CDB or an instance without containers)
304
305 //Get the entire V_$OSSTAT table from DB
306 colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
307
308 //Set numCpus
309 this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
310
311 // Get OS Load
312 osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
313
314
315 // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
271 316
317 // Get DB CPU use time
318 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'");
319 rset.next();
320 niwTime.update(rset.getLong(2), rset.getTimestamp(1));
321 cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
322 rset.close();
323
324 //Get the entire V_$SYSSTAT table from DB
325 colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
272 } 326 }
273 327
274 //Get the entire V_$OSSTAT table from DB
275 colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
276
277 //Set numCpus
278 this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
279
280 // Get OS Load
281 osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
282
283
284 // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
285
286 // Get DB CPU use time
287 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'");
288 rset.next();
289 niwTime.update(rset.getLong(2), rset.getTimestamp(1));
290 cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
291 rset.close();
292
293 //Get the entire V_$SYSSTAT table from DB
294 colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
295
296 stmt.close(); 328 stmt.close();
297 getDataSucess++; 329 getDataSucess++;
298 lastFetchTSns = System.nanoTime(); 330 lastFetchTSns = System.nanoTime();
......
...@@ -11,7 +11,26 @@ public class TestRunner { ...@@ -11,7 +11,26 @@ public class TestRunner {
11 /** 11 /**
12 * @param args 12 * @param args
13 */ 13 */
14 public static void main(String[] args) throws Throwable{ 14 public static void main(String[] args) throws Throwable {
15 //runner1();
16 //test1();
17 testTns();
18 }
19
20 public static void test1() throws Throwable {
21 OraMon mon = new OraMon("jdbc:oracle:thin:@//u02822.kap.rsv.se:1526/DB1K06","dbsnmp","dbsnmp"); // CDB
22 System.out.println("getData returned: " + mon.getData());
23 System.out.println("getDatabaseName: " + mon.getDBName());
24 }
25
26 public static void testTns() throws Throwable {
27 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
28 System.out.println("getData returned: " + mon.getData());
29 System.out.println("getDatabaseName: " + mon.getDBName());
30 System.out.println("getServiceName: " + mon.getServiceName());
31 }
32
33 public static void runner1() throws Throwable {
15 // TODO Auto-generated method stub 34 // TODO Auto-generated method stub
16 35
17 //ArrayList<OraMon> oraList = new ArrayList<OraMon>(); 36 //ArrayList<OraMon> oraList = new ArrayList<OraMon>();
......