Commit d413c61e d413c61e6c79de286904526e4942edad1e1f2827 by Christian Gerdes

Lagt till stöd att läsa in hela OSSTAT tabellen och därmed stöd för att

hantera flera tabeller i OraMon. Skapat räknare för busy percent och
load.
Load är dock en double i oracle tabellen och vi läser den som en long
just nu så load fungerar inte. Busy percent fungerar dock fint. Även
rättat en bug i getData genom att göra escape på citattecken då den 
returnerar oracle felmeddelanden (som kan innehålla citat tecken).
1 parent 6b86f43d
/OraMonRESTgetData.class
/OraMonRESTgetMetrics.class
/OraMonRESTgetData.class
......
/access.log
/systemout.log
......@@ -84,7 +84,7 @@ public class OraMonRESTgetData extends HttpServlet {
} catch (Throwable e) {
response.setStatus(500);
response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").trim()+"\"}");
response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").replace("\"","\\\"").trim()+"\"}");
e.printStackTrace();
}
}
......
......@@ -78,6 +78,9 @@ public class OraMonRESTgetMetrics extends HttpServlet {
sb.append("{\"name\":\"Cpus (#)" + aStr + "\",\"value\":" + item.getNumberOfCPUs() + "}");
sb.append(",{\"name\":\"Cpu Time (ms/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 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() + "}");
sb.append(",{\"name\":\"Consistent Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("consistent gets") + "}");
sb.append(",{\"name\":\"DB Block Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("db block gets") + "}");
......
......@@ -35,6 +35,19 @@ class Collector {
}
}
public long getCurrentValue(String name) throws Throwable {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
if(name.equals(list.get(x).name)) {
myDelta = list.get(x);
}
}
if(myDelta != null)
return myDelta.getCurrentValue();
else
return 0;
}
public long getPerSecValue(String name) throws Throwable {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
......
......@@ -34,6 +34,10 @@ class LongDelta {
return 0;
}
}
public long getCurrentValue() throws Throwable {
if(this.curValue != null) return this.curValue;
else return 0;
}
public long getSeconds() throws Throwable {
if(this.lastFetch != null && this.curFetch != null) {
long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
......
......@@ -12,7 +12,11 @@ public class OraMon {
String conPass = "passw0rd";
String dbName = null;
Collector col = new Collector();
public static final int SYSSTAT = 1;
public static final int OSSTAT = 2;
Collector colSysStat = new Collector();
Collector colOsStat = new Collector();
int getDataCalls = 0;
int getDataSucess = 0;
......@@ -53,13 +57,40 @@ public class OraMon {
}
public long getPerSecondValue(String name) throws Throwable {
return col.getPerSecValue(name);
return getPerSecondValue(name, SYSSTAT);
}
public long getPerSecondValue(String name, int table) throws Throwable {
switch (table) {
case OSSTAT:
return colOsStat.getPerSecValue(name);
case SYSSTAT:
return colSysStat.getPerSecValue(name);
default:
return colSysStat.getPerSecValue(name);
}
}
public String getDBName() throws Throwable {
return this.dbName;
}
public double getOsBusyPercent() throws Throwable {
double idle = getPerSecondValue("IDLE_TIME", OSSTAT);
double busy = getPerSecondValue("BUSY_TIME", OSSTAT);
return busy/(busy+idle);
}
public long getOsLoad() throws Throwable {
return colOsStat.getCurrentValue("LOAD");
}
public double getOsLoadPerCPU() throws Throwable {
double num = this.numCpus;
double load = colOsStat.getCurrentValue("LOAD");
return load / num;
}
public double getBufferCacheHitRatioPercent() throws Throwable {
double conGetsCache = getPerSecondValue("consistent gets from cache");
double dbBlocksCache = getPerSecondValue("db block gets from cache");
......@@ -150,16 +181,16 @@ public class OraMon {
rset.close();
}
//Get values for CPU calculation
rset = stmt.executeQuery("select value from V$OSSTAT where STAT_NAME = 'NUM_CPUS'");
rset.next();
this.numCpus = rset.getInt(1);
rset.close();
//Get the entire V_$OSSTAT table from DB
colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
//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 the entire V_$SYSSTAT table from DB
col.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
stmt.close();
getDataSucess++;
......