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
1 /OraMonRESTgetData.class
2 /OraMonRESTgetMetrics.class 1 /OraMonRESTgetMetrics.class
2 /OraMonRESTgetData.class
......
1 /access.log
2 /systemout.log
...@@ -84,7 +84,7 @@ public class OraMonRESTgetData extends HttpServlet { ...@@ -84,7 +84,7 @@ public class OraMonRESTgetData extends HttpServlet {
84 84
85 } catch (Throwable e) { 85 } catch (Throwable e) {
86 response.setStatus(500); 86 response.setStatus(500);
87 response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").trim()+"\"}"); 87 response.getWriter().println("{\"error\":true,\"msg\":\""+e.toString().replace("\n"," ").replace("\"","\\\"").trim()+"\"}");
88 e.printStackTrace(); 88 e.printStackTrace();
89 } 89 }
90 } 90 }
......
...@@ -78,6 +78,9 @@ public class OraMonRESTgetMetrics extends HttpServlet { ...@@ -78,6 +78,9 @@ public class OraMonRESTgetMetrics extends HttpServlet {
78 sb.append("{\"name\":\"Cpus (#)" + aStr + "\",\"value\":" + item.getNumberOfCPUs() + "}"); 78 sb.append("{\"name\":\"Cpus (#)" + aStr + "\",\"value\":" + item.getNumberOfCPUs() + "}");
79 sb.append(",{\"name\":\"Cpu Time (ms/s)" + aStr + "\",\"value\":" + item.getCPUTimePerSecond() + "}"); 79 sb.append(",{\"name\":\"Cpu Time (ms/s)" + aStr + "\",\"value\":" + item.getCPUTimePerSecond() + "}");
80 sb.append(",{\"name\":\"Cpu Usage (%)" + aStr + "\",\"value\":" + item.getCPUPercent() + "}"); 80 sb.append(",{\"name\":\"Cpu Usage (%)" + aStr + "\",\"value\":" + item.getCPUPercent() + "}");
81 sb.append(",{\"name\":\"OS Cpu Usage (%)" + aStr + "\",\"value\":" + item.getOsBusyPercent() + "}");
82 sb.append(",{\"name\":\"OS Load (#)" + aStr + "\",\"value\":" + item.getOsLoad() + "}");
83 sb.append(",{\"name\":\"OS Load per Cpu (#)" + aStr + "\",\"value\":" + item.getOsLoadPerCPU() + "}");
81 sb.append(",{\"name\":\"Logical Reads (#/s)" + aStr + "\",\"value\":" + item.getLogicalReadsPerSecond() + "}"); 84 sb.append(",{\"name\":\"Logical Reads (#/s)" + aStr + "\",\"value\":" + item.getLogicalReadsPerSecond() + "}");
82 sb.append(",{\"name\":\"Consistent Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("consistent gets") + "}"); 85 sb.append(",{\"name\":\"Consistent Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("consistent gets") + "}");
83 sb.append(",{\"name\":\"DB Block Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("db block gets") + "}"); 86 sb.append(",{\"name\":\"DB Block Gets (#/s)" + aStr + "\",\"value\":" + item.getPerSecondValue("db block gets") + "}");
......
...@@ -35,6 +35,19 @@ class Collector { ...@@ -35,6 +35,19 @@ class Collector {
35 } 35 }
36 } 36 }
37 37
38 public long getCurrentValue(String name) throws Throwable {
39 LongDelta myDelta = null;
40 for(int x = 0; x<list.size() && myDelta == null; x++) {
41 if(name.equals(list.get(x).name)) {
42 myDelta = list.get(x);
43 }
44 }
45 if(myDelta != null)
46 return myDelta.getCurrentValue();
47 else
48 return 0;
49 }
50
38 public long getPerSecValue(String name) throws Throwable { 51 public long getPerSecValue(String name) throws Throwable {
39 LongDelta myDelta = null; 52 LongDelta myDelta = null;
40 for(int x = 0; x<list.size() && myDelta == null; x++) { 53 for(int x = 0; x<list.size() && myDelta == null; x++) {
......
...@@ -34,6 +34,10 @@ class LongDelta { ...@@ -34,6 +34,10 @@ class LongDelta {
34 return 0; 34 return 0;
35 } 35 }
36 } 36 }
37 public long getCurrentValue() throws Throwable {
38 if(this.curValue != null) return this.curValue;
39 else return 0;
40 }
37 public long getSeconds() throws Throwable { 41 public long getSeconds() throws Throwable {
38 if(this.lastFetch != null && this.curFetch != null) { 42 if(this.lastFetch != null && this.curFetch != null) {
39 long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000; 43 long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
......
...@@ -12,7 +12,11 @@ public class OraMon { ...@@ -12,7 +12,11 @@ public class OraMon {
12 String conPass = "passw0rd"; 12 String conPass = "passw0rd";
13 String dbName = null; 13 String dbName = null;
14 14
15 Collector col = new Collector(); 15 public static final int SYSSTAT = 1;
16 public static final int OSSTAT = 2;
17
18 Collector colSysStat = new Collector();
19 Collector colOsStat = new Collector();
16 20
17 int getDataCalls = 0; 21 int getDataCalls = 0;
18 int getDataSucess = 0; 22 int getDataSucess = 0;
...@@ -53,13 +57,40 @@ public class OraMon { ...@@ -53,13 +57,40 @@ public class OraMon {
53 } 57 }
54 58
55 public long getPerSecondValue(String name) throws Throwable { 59 public long getPerSecondValue(String name) throws Throwable {
56 return col.getPerSecValue(name); 60 return getPerSecondValue(name, SYSSTAT);
61 }
62
63 public long getPerSecondValue(String name, int table) throws Throwable {
64 switch (table) {
65 case OSSTAT:
66 return colOsStat.getPerSecValue(name);
67 case SYSSTAT:
68 return colSysStat.getPerSecValue(name);
69 default:
70 return colSysStat.getPerSecValue(name);
71 }
57 } 72 }
58 73
59 public String getDBName() throws Throwable { 74 public String getDBName() throws Throwable {
60 return this.dbName; 75 return this.dbName;
61 } 76 }
62 77
78 public double getOsBusyPercent() throws Throwable {
79 double idle = getPerSecondValue("IDLE_TIME", OSSTAT);
80 double busy = getPerSecondValue("BUSY_TIME", OSSTAT);
81 return busy/(busy+idle);
82 }
83
84 public long getOsLoad() throws Throwable {
85 return colOsStat.getCurrentValue("LOAD");
86 }
87
88 public double getOsLoadPerCPU() throws Throwable {
89 double num = this.numCpus;
90 double load = colOsStat.getCurrentValue("LOAD");
91 return load / num;
92 }
93
63 public double getBufferCacheHitRatioPercent() throws Throwable { 94 public double getBufferCacheHitRatioPercent() throws Throwable {
64 double conGetsCache = getPerSecondValue("consistent gets from cache"); 95 double conGetsCache = getPerSecondValue("consistent gets from cache");
65 double dbBlocksCache = getPerSecondValue("db block gets from cache"); 96 double dbBlocksCache = getPerSecondValue("db block gets from cache");
...@@ -150,16 +181,16 @@ public class OraMon { ...@@ -150,16 +181,16 @@ public class OraMon {
150 rset.close(); 181 rset.close();
151 } 182 }
152 183
153 //Get values for CPU calculation 184 //Get the entire V_$OSSTAT table from DB
154 rset = stmt.executeQuery("select value from V$OSSTAT where STAT_NAME = 'NUM_CPUS'"); 185 colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
155 rset.next(); 186
156 this.numCpus = rset.getInt(1); 187 //Set numCpus
157 rset.close(); 188 this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
158 189
159 cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"), true); 190 cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"), true);
160 191
161 // Get the entire V_$SYSSTAT table from DB 192 //Get the entire V_$SYSSTAT table from DB
162 col.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT")); 193 colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
163 194
164 stmt.close(); 195 stmt.close();
165 getDataSucess++; 196 getDataSucess++;
......