Commit 56b16db9 56b16db97bfffe0976f0329dfdbd668baa027186 by Christian Gerdes

Bytt till att läsa in som BigDecimal i LongDelta klassen istället.

1 parent 6f1bcf88
package se.lil.om;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
......@@ -12,19 +13,19 @@ class Collector {
// Add try catch for issue #5
Timestamp ts = rset.getTimestamp(1);
String name = rset.getString(2);
Long value;
BigDecimal value;
try {
value = rset.getLong(3);
value = rset.getBigDecimal(3);
}
catch (java.sql.SQLException e) {
value = Long.MAX_VALUE;
value = BigDecimal.ZERO;
}
updateValue(ts, name, value);
}
rset.close();
}
public void updateValue(Timestamp ts, String name, Long value) {
public void updateValue(Timestamp ts, String name, BigDecimal value) {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
if(name.equals(list.get(x).name)) {
......
package se.lil.om;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
class LongDelta {
public String name = null;
public Long curValue = null;
public Long lastValue = null;
public BigDecimal curValue = null;
public BigDecimal lastValue = null;
public Timestamp lastFetch = null;
public Timestamp curFetch = null;
boolean urProt = false; // Under-run protection
boolean lastUpdCausedUR = false;
public static BigDecimal bd1000 = new BigDecimal(1000);
public LongDelta() {};
public LongDelta(boolean UnderrunProtection) { this.urProt = UnderrunProtection; }
......@@ -26,18 +28,18 @@ class LongDelta {
}
public void update(ResultSet rset, int pos, boolean convert, boolean close) throws Throwable{
rset.next();
update(rset.getLong(pos), rset.getTimestamp(1), convert);
update(rset.getBigDecimal(pos), rset.getTimestamp(1), convert);
if(close) rset.close();
}
public void update(long value, Timestamp timestamp) {
public void update(BigDecimal value, Timestamp timestamp) {
update(value, timestamp, false);
}
public void update(long value, Timestamp timestamp, boolean convert) {
if(convert) value = value/1000;
public void update(BigDecimal value, Timestamp timestamp, boolean convert) {
if(convert) value = value.divide(bd1000, BigDecimal.ROUND_HALF_UP);
if(urProt) {
if(this.curValue != null && this.curValue > value) {
if(this.curValue != null && this.curValue.compareTo(value) > 0) {
//This would be a negative delta. Ignore this data
//System.out.println("Underrunprotection on " + name + " New Val: " + newval + " Old Val: " + this.curValue);
lastUpdCausedUR = true;
......@@ -59,7 +61,7 @@ class LongDelta {
if(this.curValue != null && this.lastValue != null && this.lastFetch != null && this.curFetch != null) {
// We have values, calculate the number of gets per second
double numMilliSeconds = this.curFetch.getTime() - this.lastFetch.getTime();
double delta = this.curValue - this.lastValue;
double delta = this.curValue.subtract(this.lastValue).doubleValue();
double perMilli = delta/numMilliSeconds;
return perMilli * 1000;
} else {
......@@ -67,7 +69,7 @@ class LongDelta {
}
}
public long getCurrentValue() throws Throwable {
if(this.curValue != null) return this.curValue;
if(this.curValue != null) return this.curValue.longValue();
else return 0;
}
public double getSeconds() throws Throwable {
......@@ -85,7 +87,7 @@ class LongDelta {
}
public long getDelta() throws Throwable {
if(this.lastValue != null && this.curValue != null) {
return this.curValue - this.lastValue;
return this.curValue.subtract(this.lastValue).longValue();
}
return 0;
}
......
......@@ -396,8 +396,8 @@ public class OraMon {
// 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));
niwTime.update(rset.getBigDecimal(2), rset.getTimestamp(1));
cpuTime.update(rset.getBigDecimal(3), rset.getTimestamp(1));
rset.close();
//Get the entire V_$SYSSTAT table from DB
......@@ -411,8 +411,8 @@ public class OraMon {
while(rset.next()) {
Timestamp ts = rset.getTimestamp(1);
String name = rset.getString(2);
colPdbCPU.updateValue(ts, name + strNiwTime, rset.getLong(3));
colPdbCPU.updateValue(ts, name + strCpuTime, rset.getLong(4));
colPdbCPU.updateValue(ts, name + strNiwTime, rset.getBigDecimal(3));
colPdbCPU.updateValue(ts, name + strCpuTime, rset.getBigDecimal(4));
if(pdbSet == null) pdbSet = new HashSet<String>();
pdbSet.add(name);
}
......