Commit 1f664f68 1f664f68078814f65bf3dccd769bd3d202538a1b by Christian Gerdes

Ökat nogrannheten överlag genom att använda doubles istället för long

och undvika avrundningar i både LongDelta, Collector och OraMon. Skapat 
en ny klass DoubleDelta som kan hantera värden från Oracle med
decimaler,
behövdes för att mäta LOAD från OSSTAT. Testat med både piloop och
cpuloop
i oracle sql (som tar en hel cpu) och mätvärden ser ut att stämma bra.
1 parent d413c61e
/OraMonRESTgetMetrics.class
/OraMonRESTgetData.class
/OraMonRESTgetMetrics.class
......
......@@ -76,9 +76,9 @@ public class OraMonRESTgetMetrics extends HttpServlet {
for (OraMon item : list) {
if (list.size() > 1) aStr = " " + item.getDBName();
sb.append("{\"name\":\"Cpus (#)" + aStr + "\",\"value\":" + item.getNumberOfCPUs() + "}");
sb.append(",{\"name\":\"Cpu Time (ms/s)" + aStr + "\",\"value\":" + item.getCPUTimePerSecond() + "}");
sb.append(",{\"name\":\"Cpu Time (us/s)" + aStr + "\",\"value\":" + item.getCPUTimePerSecond() + "}");
sb.append(",{\"name\":\"Cpu Usage (%)" + aStr + "\",\"value\":" + item.getCPUPercent() + "}");
sb.append(",{\"name\":\"OS Cpu Usage (%)" + aStr + "\",\"value\":" + item.getOsBusyPercent() + "}");
sb.append(",{\"name\":\"OS Busy (%)" + aStr + "\",\"value\":" + item.getOsBusyPercent() + "}");
sb.append(",{\"name\":\"OS Load (#)" + aStr + "\",\"value\":" + item.getOsLoad() + "}");
sb.append(",{\"name\":\"OS Load per Cpu (#)" + aStr + "\",\"value\":" + item.getOsLoadPerCPU() + "}");
sb.append(",{\"name\":\"Logical Reads (#/s)" + aStr + "\",\"value\":" + item.getLogicalReadsPerSecond() + "}");
......
......@@ -3,6 +3,6 @@
<classpathentry kind="src" path=""/>
<classpathentry exported="true" kind="lib" path="lib/ojdbc6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ojdbc5.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path=""/>
</classpath>
......
......@@ -5,3 +5,4 @@
/TestRunner.class
/WGet.class
/Utils.class
/DoubleDelta.class
......
......@@ -48,7 +48,7 @@ class Collector {
return 0;
}
public long getPerSecValue(String name) throws Throwable {
public double getPerSecValue(String name) throws Throwable {
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.sql.ResultSet;
import java.sql.Timestamp;
public class DoubleDelta {
public String name = null;
public Double curValue = null;
public Double lastValue = null;
public Timestamp lastFetch = null;
public Timestamp curFetch = null;
public void update(ResultSet rset) throws Throwable{
update(rset, false);
}
public void update(ResultSet rset, boolean convert) throws Throwable{
rset.next();
this.lastFetch = this.curFetch;
this.curFetch = rset.getTimestamp(1);
this.lastValue = this.curValue;
if(convert)
this.curValue = rset.getDouble(2)/1000;
else
this.curValue = rset.getDouble(2);
rset.close();
}
public double getPerSecondValue() throws Throwable {
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 perMilli = delta/numMilliSeconds;
return perMilli * 1000;
} else {
return 0;
}
}
public double getCurrentValue() throws Throwable {
if(this.curValue != null) return this.curValue;
else return 0;
}
public double getSeconds() throws Throwable {
if(this.lastFetch != null && this.curFetch != null) {
double numSeconds = this.curFetch.getTime() - this.lastFetch.getTime();
return numSeconds/1000;
}
return 0;
}
public long getMilliSeconds() throws Throwable {
if(this.lastFetch != null && this.curFetch != null) {
return this.curFetch.getTime() - this.lastFetch.getTime();
}
return 0;
}
}
......@@ -24,12 +24,13 @@ class LongDelta {
this.curValue = rset.getLong(2);
rset.close();
}
public long getPerSecondValue() throws Throwable {
public double getPerSecondValue() throws Throwable {
if(this.curValue != null && this.lastValue != null && this.lastFetch != null && this.curFetch != null) {
// We have values, calculate the number of gets per second
long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
long delta = this.curValue - this.lastValue;
return delta/numSeconds;
double numMilliSeconds = this.curFetch.getTime() - this.lastFetch.getTime();
double delta = this.curValue - this.lastValue;
double perMilli = delta/numMilliSeconds;
return perMilli * 1000;
} else {
return 0;
}
......@@ -38,10 +39,16 @@ class LongDelta {
if(this.curValue != null) return this.curValue;
else return 0;
}
public long getSeconds() throws Throwable {
public double getSeconds() throws Throwable {
if(this.lastFetch != null && this.curFetch != null) {
long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
return numSeconds;
double numSeconds = this.curFetch.getTime() - this.lastFetch.getTime();
return numSeconds/1000;
}
return 0;
}
public long getMilliSeconds() throws Throwable {
if(this.lastFetch != null && this.curFetch != null) {
return this.curFetch.getTime() - this.lastFetch.getTime();
}
return 0;
}
......
......@@ -47,20 +47,20 @@ public class OraMon {
LongDelta cpuTime = new LongDelta();
public double getCPUPercent() throws Throwable {
double perSec = cpuTime.getPerSecondValue();
double totSec = numCpus * 1000;
double totSec = numCpus * 1000 * 1000;
double percent = (perSec / totSec) * 100;
return percent;
}
public long getCPUTimePerSecond() throws Throwable {
public double getCPUTimePerSecond() throws Throwable {
return cpuTime.getPerSecondValue();
}
public long getPerSecondValue(String name) throws Throwable {
public double getPerSecondValue(String name) throws Throwable {
return getPerSecondValue(name, SYSSTAT);
}
public long getPerSecondValue(String name, int table) throws Throwable {
public double getPerSecondValue(String name, int table) throws Throwable {
switch (table) {
case OSSTAT:
return colOsStat.getPerSecValue(name);
......@@ -78,16 +78,19 @@ public class OraMon {
public double getOsBusyPercent() throws Throwable {
double idle = getPerSecondValue("IDLE_TIME", OSSTAT);
double busy = getPerSecondValue("BUSY_TIME", OSSTAT);
return busy/(busy+idle);
return 100*(busy/(busy+idle));
}
public long getOsLoad() throws Throwable {
return colOsStat.getCurrentValue("LOAD");
// OS LOAD
DoubleDelta osLoad = new DoubleDelta();
public double getOsLoad() throws Throwable {
return osLoad.getCurrentValue();
}
public double getOsLoadPerCPU() throws Throwable {
double num = this.numCpus;
double load = colOsStat.getCurrentValue("LOAD");
double load = getOsLoad();
return load / num;
}
......@@ -119,7 +122,7 @@ public class OraMon {
return cacheHitRatio * 100;
}
public long getLogicalReadsPerSecond() throws Throwable {
public double getLogicalReadsPerSecond() throws Throwable {
return getPerSecondValue("consistent gets") + getPerSecondValue("db block gets");
}
......@@ -187,7 +190,11 @@ public class OraMon {
//Set numCpus
this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"), true);
// Get DB CPU use time
cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"));
// Get OS Load
osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
......