Tagit bort PDB koden. Kommer byta till ny approuch. TNS stödet kvar.
PDB som ska cachas får alltid gå via CDB Connection String och istället får man skicka med en flagga med PDB namnet som man vill ha ut. Blir mycket enklare.
Showing
2 changed files
with
25 additions
and
74 deletions
1 | package se.lil.om; | 1 | package se.lil.om; |
2 | 2 | ||
3 | import java.sql.*; | 3 | import java.sql.*; |
4 | import java.util.HashMap; | ||
5 | import java.util.Hashtable; | ||
6 | import java.util.Properties; | 4 | import java.util.Properties; |
7 | import java.util.concurrent.locks.Lock; | 5 | import java.util.concurrent.locks.Lock; |
8 | import java.util.concurrent.locks.ReentrantLock; | 6 | import java.util.concurrent.locks.ReentrantLock; |
... | @@ -22,8 +20,6 @@ public class OraMon { | ... | @@ -22,8 +20,6 @@ public class OraMon { |
22 | Boolean hasContainers = null; | 20 | Boolean hasContainers = null; |
23 | OraMon containerDB = null; | 21 | OraMon containerDB = null; |
24 | 22 | ||
25 | private Hashtable<String, OraMon> myPDBs = null; | ||
26 | |||
27 | public static final int SYSSTAT = 1; | 23 | public static final int SYSSTAT = 1; |
28 | public static final int OSSTAT = 2; | 24 | public static final int OSSTAT = 2; |
29 | 25 | ||
... | @@ -276,60 +272,28 @@ public class OraMon { | ... | @@ -276,60 +272,28 @@ public class OraMon { |
276 | rset.close(); | 272 | rset.close(); |
277 | } | 273 | } |
278 | 274 | ||
279 | // Check if we can have containers | 275 | // All other cases (CDB or an instance without containers) get the data from the database |
280 | if(hasContainers == null) { | ||
281 | // We don't know, check if the CONTAINERS view exists in the database | ||
282 | rset = stmt.executeQuery("select count(*) from SYS.ALL_VIEWS where VIEW_NAME = 'V_$CONTAINERS'"); | ||
283 | if(rset.next()) { | ||
284 | if(rset.getInt(1) == 1) { | ||
285 | // We found the containers view. Enable container handling | ||
286 | hasContainers = true; | ||
287 | String serviceName = getServiceName(); | ||
288 | if(serviceName != null) { | ||
289 | if(serviceName.equals(this.dbName)) isCDB = true; | ||
290 | else isPDB = true; | ||
291 | } else { | ||
292 | // Servicename is null, treat as CDB | ||
293 | isCDB = true; | ||
294 | isPDB = false; | ||
295 | } | ||
296 | } | ||
297 | } | ||
298 | if(hasContainers == null) { | ||
299 | hasContainers = false; | ||
300 | isCDB = true; | ||
301 | isPDB = false; | ||
302 | } | ||
303 | } | ||
304 | 276 | ||
305 | // If we have containers, but we are not the CDB, then we are a PDB. | 277 | //Get the entire V_$OSSTAT table from DB |
306 | // We should ask the CDB object for our data | 278 | colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT")); |
307 | if(isPDB) { | 279 | |
308 | getDataFromCDB(ageTs); | 280 | //Set numCpus |
309 | } else { | 281 | this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS"); |
310 | // All other cases (CDB or an instance without containers) get the data from the database | 282 | |
311 | 283 | // Get OS Load | |
312 | //Get the entire V_$OSSTAT table from DB | 284 | osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'")); |
313 | colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT")); | 285 | |
314 | 286 | // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total. | |
315 | //Set numCpus | 287 | |
316 | this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS"); | 288 | // Get DB CPU use time |
317 | 289 | 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'"); | |
318 | // Get OS Load | 290 | rset.next(); |
319 | osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'")); | 291 | niwTime.update(rset.getLong(2), rset.getTimestamp(1)); |
320 | 292 | cpuTime.update(rset.getLong(3), rset.getTimestamp(1)); | |
321 | // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total. | 293 | rset.close(); |
322 | 294 | ||
323 | // Get DB CPU use time | 295 | //Get the entire V_$SYSSTAT table from DB |
324 | 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'"); | 296 | colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT")); |
325 | rset.next(); | ||
326 | niwTime.update(rset.getLong(2), rset.getTimestamp(1)); | ||
327 | cpuTime.update(rset.getLong(3), rset.getTimestamp(1)); | ||
328 | rset.close(); | ||
329 | |||
330 | //Get the entire V_$SYSSTAT table from DB | ||
331 | colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT")); | ||
332 | } | ||
333 | 297 | ||
334 | stmt.close(); | 298 | stmt.close(); |
335 | getDataSucess++; | 299 | getDataSucess++; |
... | @@ -355,21 +319,6 @@ public class OraMon { | ... | @@ -355,21 +319,6 @@ public class OraMon { |
355 | // End thread safe | 319 | // End thread safe |
356 | } | 320 | } |
357 | 321 | ||
358 | public void getDataFromCDB(long ageTs) throws Throwable { | ||
359 | //Generate a con string for the CDB using the PDB con string and replace the service name | ||
360 | String cdbConString = getConString().replaceAll(getServiceName(), getDBName()); | ||
361 | System.out.println("CDB seems to be: " + cdbConString); | ||
362 | //Find the CDB in the registry | ||
363 | OraMon myCDB = Registry.findOrCreate(cdbConString, conUser, conPass); | ||
364 | myCDB.getData(ageTs); | ||
365 | // Verify the CDB | ||
366 | if (getDBName().equals(myCDB.getDBName())) { | ||
367 | System.out.println("myCDB name equals DBName"); | ||
368 | } else { | ||
369 | System.out.println("myCDB name does not equal DBName"); | ||
370 | } | ||
371 | } | ||
372 | |||
373 | public Throwable getLastEx() { | 322 | public Throwable getLastEx() { |
374 | return lastEx; | 323 | return lastEx; |
375 | } | 324 | } | ... | ... |
... | @@ -24,7 +24,8 @@ public class TestRunner { | ... | @@ -24,7 +24,8 @@ public class TestRunner { |
24 | } | 24 | } |
25 | 25 | ||
26 | public static void testTns() throws Throwable { | 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 | 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 | OraMon mon = new OraMon("jdbc:oracle:thin:@//u00153.kap.rsv.se:1526/DB1K01","dbsnmp","dbsnmp"); | ||
28 | System.out.println("getData returned: " + mon.getData()); | 29 | System.out.println("getData returned: " + mon.getData()); |
29 | System.out.println("getDatabaseName: " + mon.getDBName()); | 30 | System.out.println("getDatabaseName: " + mon.getDBName()); |
30 | System.out.println("getServiceName: " + mon.getServiceName()); | 31 | System.out.println("getServiceName: " + mon.getServiceName()); |
... | @@ -41,7 +42,8 @@ public class TestRunner { | ... | @@ -41,7 +42,8 @@ public class TestRunner { |
41 | 42 | ||
42 | //OraMon mon1 = new OraMon("jdbc:oracle:thin:@uvp3dbkappkg:1550:VP1K03","dbsnmp","dbsnmp"); // SID eller Service Name format | 43 | //OraMon mon1 = new OraMon("jdbc:oracle:thin:@uvp3dbkappkg:1550:VP1K03","dbsnmp","dbsnmp"); // SID eller Service Name format |
43 | //OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u00154.kap.rsv.se:1526/DB1K01","dbsnmp","dbsnmp"); | 44 | //OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u00154.kap.rsv.se:1526/DB1K01","dbsnmp","dbsnmp"); |
44 | OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K001","dbsnmp","dbsnmp"); | 45 | OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K001","dbsnmp","dbsnmp"); // PDB, CDB är DB1K12 |
46 | //OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K002","dbsnmp","dbsnmp"); // Andra PDB på CDB DB1K12 | ||
45 | //OraMon mon2 = new OraMon("jdbc:oracle:thin:@host:port:sid","user","pass"); // SID format | 47 | //OraMon mon2 = new OraMon("jdbc:oracle:thin:@host:port:sid","user","pass"); // SID format |
46 | mon1.open(); | 48 | mon1.open(); |
47 | //mon2.open(); | 49 | //mon2.open(); | ... | ... |
-
Please register or sign in to post a comment