Bytt till att läsa in som BigDecimal i LongDelta klassen istället.
Showing
5 changed files
with
21 additions
and
18 deletions
No preview for this file type
No preview for this file type
| 1 | package se.lil.om; | 1 | package se.lil.om; |
| 2 | 2 | ||
| 3 | import java.math.BigDecimal; | ||
| 3 | import java.sql.ResultSet; | 4 | import java.sql.ResultSet; |
| 4 | import java.sql.Timestamp; | 5 | import java.sql.Timestamp; |
| 5 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
| ... | @@ -12,19 +13,19 @@ class Collector { | ... | @@ -12,19 +13,19 @@ class Collector { |
| 12 | // Add try catch for issue #5 | 13 | // Add try catch for issue #5 |
| 13 | Timestamp ts = rset.getTimestamp(1); | 14 | Timestamp ts = rset.getTimestamp(1); |
| 14 | String name = rset.getString(2); | 15 | String name = rset.getString(2); |
| 15 | Long value; | 16 | BigDecimal value; |
| 16 | try { | 17 | try { |
| 17 | value = rset.getLong(3); | 18 | value = rset.getBigDecimal(3); |
| 18 | } | 19 | } |
| 19 | catch (java.sql.SQLException e) { | 20 | catch (java.sql.SQLException e) { |
| 20 | value = Long.MAX_VALUE; | 21 | value = BigDecimal.ZERO; |
| 21 | } | 22 | } |
| 22 | updateValue(ts, name, value); | 23 | updateValue(ts, name, value); |
| 23 | } | 24 | } |
| 24 | rset.close(); | 25 | rset.close(); |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | public void updateValue(Timestamp ts, String name, Long value) { | 28 | public void updateValue(Timestamp ts, String name, BigDecimal value) { |
| 28 | LongDelta myDelta = null; | 29 | LongDelta myDelta = null; |
| 29 | for(int x = 0; x<list.size() && myDelta == null; x++) { | 30 | for(int x = 0; x<list.size() && myDelta == null; x++) { |
| 30 | if(name.equals(list.get(x).name)) { | 31 | if(name.equals(list.get(x).name)) { | ... | ... |
| 1 | package se.lil.om; | 1 | package se.lil.om; |
| 2 | 2 | ||
| 3 | import java.math.BigDecimal; | ||
| 3 | import java.sql.ResultSet; | 4 | import java.sql.ResultSet; |
| 4 | import java.sql.Timestamp; | 5 | import java.sql.Timestamp; |
| 5 | 6 | ||
| 6 | class LongDelta { | 7 | class LongDelta { |
| 7 | public String name = null; | 8 | public String name = null; |
| 8 | public Long curValue = null; | 9 | public BigDecimal curValue = null; |
| 9 | public Long lastValue = null; | 10 | public BigDecimal lastValue = null; |
| 10 | public Timestamp lastFetch = null; | 11 | public Timestamp lastFetch = null; |
| 11 | public Timestamp curFetch = null; | 12 | public Timestamp curFetch = null; |
| 12 | boolean urProt = false; // Under-run protection | 13 | boolean urProt = false; // Under-run protection |
| 13 | boolean lastUpdCausedUR = false; | 14 | boolean lastUpdCausedUR = false; |
| 15 | public static BigDecimal bd1000 = new BigDecimal(1000); | ||
| 14 | 16 | ||
| 15 | public LongDelta() {}; | 17 | public LongDelta() {}; |
| 16 | public LongDelta(boolean UnderrunProtection) { this.urProt = UnderrunProtection; } | 18 | public LongDelta(boolean UnderrunProtection) { this.urProt = UnderrunProtection; } |
| ... | @@ -26,18 +28,18 @@ class LongDelta { | ... | @@ -26,18 +28,18 @@ class LongDelta { |
| 26 | } | 28 | } |
| 27 | public void update(ResultSet rset, int pos, boolean convert, boolean close) throws Throwable{ | 29 | public void update(ResultSet rset, int pos, boolean convert, boolean close) throws Throwable{ |
| 28 | rset.next(); | 30 | rset.next(); |
| 29 | update(rset.getLong(pos), rset.getTimestamp(1), convert); | 31 | update(rset.getBigDecimal(pos), rset.getTimestamp(1), convert); |
| 30 | if(close) rset.close(); | 32 | if(close) rset.close(); |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | public void update(long value, Timestamp timestamp) { | 35 | public void update(BigDecimal value, Timestamp timestamp) { |
| 34 | update(value, timestamp, false); | 36 | update(value, timestamp, false); |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | public void update(long value, Timestamp timestamp, boolean convert) { | 39 | public void update(BigDecimal value, Timestamp timestamp, boolean convert) { |
| 38 | if(convert) value = value/1000; | 40 | if(convert) value = value.divide(bd1000, BigDecimal.ROUND_HALF_UP); |
| 39 | if(urProt) { | 41 | if(urProt) { |
| 40 | if(this.curValue != null && this.curValue > value) { | 42 | if(this.curValue != null && this.curValue.compareTo(value) > 0) { |
| 41 | //This would be a negative delta. Ignore this data | 43 | //This would be a negative delta. Ignore this data |
| 42 | //System.out.println("Underrunprotection on " + name + " New Val: " + newval + " Old Val: " + this.curValue); | 44 | //System.out.println("Underrunprotection on " + name + " New Val: " + newval + " Old Val: " + this.curValue); |
| 43 | lastUpdCausedUR = true; | 45 | lastUpdCausedUR = true; |
| ... | @@ -59,7 +61,7 @@ class LongDelta { | ... | @@ -59,7 +61,7 @@ class LongDelta { |
| 59 | if(this.curValue != null && this.lastValue != null && this.lastFetch != null && this.curFetch != null) { | 61 | if(this.curValue != null && this.lastValue != null && this.lastFetch != null && this.curFetch != null) { |
| 60 | // We have values, calculate the number of gets per second | 62 | // We have values, calculate the number of gets per second |
| 61 | double numMilliSeconds = this.curFetch.getTime() - this.lastFetch.getTime(); | 63 | double numMilliSeconds = this.curFetch.getTime() - this.lastFetch.getTime(); |
| 62 | double delta = this.curValue - this.lastValue; | 64 | double delta = this.curValue.subtract(this.lastValue).doubleValue(); |
| 63 | double perMilli = delta/numMilliSeconds; | 65 | double perMilli = delta/numMilliSeconds; |
| 64 | return perMilli * 1000; | 66 | return perMilli * 1000; |
| 65 | } else { | 67 | } else { |
| ... | @@ -67,7 +69,7 @@ class LongDelta { | ... | @@ -67,7 +69,7 @@ class LongDelta { |
| 67 | } | 69 | } |
| 68 | } | 70 | } |
| 69 | public long getCurrentValue() throws Throwable { | 71 | public long getCurrentValue() throws Throwable { |
| 70 | if(this.curValue != null) return this.curValue; | 72 | if(this.curValue != null) return this.curValue.longValue(); |
| 71 | else return 0; | 73 | else return 0; |
| 72 | } | 74 | } |
| 73 | public double getSeconds() throws Throwable { | 75 | public double getSeconds() throws Throwable { |
| ... | @@ -85,7 +87,7 @@ class LongDelta { | ... | @@ -85,7 +87,7 @@ class LongDelta { |
| 85 | } | 87 | } |
| 86 | public long getDelta() throws Throwable { | 88 | public long getDelta() throws Throwable { |
| 87 | if(this.lastValue != null && this.curValue != null) { | 89 | if(this.lastValue != null && this.curValue != null) { |
| 88 | return this.curValue - this.lastValue; | 90 | return this.curValue.subtract(this.lastValue).longValue(); |
| 89 | } | 91 | } |
| 90 | return 0; | 92 | return 0; |
| 91 | } | 93 | } | ... | ... |
| ... | @@ -396,8 +396,8 @@ public class OraMon { | ... | @@ -396,8 +396,8 @@ public class OraMon { |
| 396 | // Get DB CPU use time | 396 | // Get DB CPU use time |
| 397 | 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'"); | 397 | 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'"); |
| 398 | rset.next(); | 398 | rset.next(); |
| 399 | niwTime.update(rset.getLong(2), rset.getTimestamp(1)); | 399 | niwTime.update(rset.getBigDecimal(2), rset.getTimestamp(1)); |
| 400 | cpuTime.update(rset.getLong(3), rset.getTimestamp(1)); | 400 | cpuTime.update(rset.getBigDecimal(3), rset.getTimestamp(1)); |
| 401 | rset.close(); | 401 | rset.close(); |
| 402 | 402 | ||
| 403 | //Get the entire V_$SYSSTAT table from DB | 403 | //Get the entire V_$SYSSTAT table from DB |
| ... | @@ -411,8 +411,8 @@ public class OraMon { | ... | @@ -411,8 +411,8 @@ public class OraMon { |
| 411 | while(rset.next()) { | 411 | while(rset.next()) { |
| 412 | Timestamp ts = rset.getTimestamp(1); | 412 | Timestamp ts = rset.getTimestamp(1); |
| 413 | String name = rset.getString(2); | 413 | String name = rset.getString(2); |
| 414 | colPdbCPU.updateValue(ts, name + strNiwTime, rset.getLong(3)); | 414 | colPdbCPU.updateValue(ts, name + strNiwTime, rset.getBigDecimal(3)); |
| 415 | colPdbCPU.updateValue(ts, name + strCpuTime, rset.getLong(4)); | 415 | colPdbCPU.updateValue(ts, name + strCpuTime, rset.getBigDecimal(4)); |
| 416 | if(pdbSet == null) pdbSet = new HashSet<String>(); | 416 | if(pdbSet == null) pdbSet = new HashSet<String>(); |
| 417 | pdbSet.add(name); | 417 | pdbSet.add(name); |
| 418 | } | 418 | } | ... | ... |
-
Please register or sign in to post a comment