Commit 120dfc5a 120dfc5a0acb9e91856dc16bfedbd375dcba698d by Christian Gerdes

Initial commit

0 parents
1 /*
2 * LoadRunner Java script. (Build: _build_number_)
3 *
4 * Script Description:
5 *
6 */
7
8 import java.util.ArrayList;
9 import lrapi.lr;
10 import se.lil.om.*;
11
12 public class Actions
13 {
14
15 ArrayList<OraMon> oraList = new ArrayList<OraMon>();
16
17 boolean firstIteration = true;
18 String empty = "";
19
20 public int init() throws Throwable
21 {
22 if(lr.get_attrib_string("ConnectionString") == null || lr.get_attrib_string("User") == null || lr.get_attrib_string("Password") == null ||
23 lr.get_attrib_string("ConnectionString").equals(empty) || lr.get_attrib_string("User").equals(empty) || lr.get_attrib_string("Password").equals(empty))
24 {
25 lr.error_message("Attributes are missing for Oracle: ConnectionString, User or Password are null. Nothing to do, aborting vuser.");
26 lr.exit(lr.EXIT_VUSER, lr.FAIL);
27 }
28
29 String[] conS = lr.get_attrib_string("ConnectionString").split(",");
30 String[] usrS = lr.get_attrib_string("User").split(",");
31 String[] pasS = lr.get_attrib_string("Password").split(",");
32
33 if(conS.length != usrS.length || conS.length != pasS.length)
34 {
35 lr.error_message("Oracle has multiple comma separated connection strings but not the same number of multiple user or password strings. Cannot continue, abort.");
36 lr.exit(lr.EXIT_VUSER, lr.FAIL);
37 }
38
39 for(int x=0; x<conS.length; x++)
40 {
41 OraMon mon = new OraMon();
42 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG , " Using " + conS[x].trim() + " User " + usrS[x].trim() + " Pass " + pasS[x].trim());
43 mon.open(conS[x].trim(), usrS[x].trim(), pasS[x].trim());
44 oraList.add(mon);
45 }
46 return 0;
47 }//end of init
48
49
50 public int action() throws Throwable
51 {
52
53 for(OraMon oracle : oraList)
54 {
55 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG , "#### ORACLE COUNTERS ####");
56 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG, "Using: " + oracle.getConString());
57 oracle.getData();
58 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG, "Returned DB Name: " + oracle.getDBName());
59
60 if(firstIteration == false)
61 {
62 String instance = oracle.getDBName();
63 sendDataPoint("ORA Cpus (#) " + instance, oracle.getNumberOfCPUs());
64 sendDataPoint("ORA Cpu Time (ms/s) " + instance, oracle.getCPUTimePerSecond());
65 sendDataPoint("ORA Cpu Usage (%) " + instance, oracle.getCPUPercent());
66 sendDataPoint("ORA Logical Reads (#/s) " + instance, oracle.getLogicalReadsPerSecond());
67 sendDataPoint("ORA Consistent Gets (#/s) " + instance, oracle.getPerSecondValue("consistent gets"));
68 sendDataPoint("ORA DB Block Gets (#/s) " + instance, oracle.getPerSecondValue("db block gets"));
69 sendDataPoint("ORA Cache Hit Ratio (%) " + instance, oracle.getCacheHitRatioPercent());
70 sendDataPoint("ORA Buffer Cache Hit Ratio (%) " + instance, oracle.getBufferCacheHitRatioPercent());
71 sendDataPoint("ORA DB Block Changes (#/s) " + instance, oracle.getPerSecondValue("db block changes"));
72 sendDataPoint("ORA Redo Size (#/s) " + instance, oracle.getPerSecondValue("redo size"));
73 sendDataPoint("ORA Physical Reads (#/s) " + instance, oracle.getPerSecondValue("physical reads"));
74 sendDataPoint("ORA Physical Writes (#/s) " + instance, oracle.getPerSecondValue("physical writes"));
75 sendDataPoint("ORA Redo Writes (#/s) " + instance, oracle.getPerSecondValue("redo writes"));
76 sendDataPoint("ORA Non-idle Wait Time (ms/s) " + instance, oracle.getPerSecondValue("non-idle wait time"));
77 sendDataPoint("ORA File I/O Wait Time (ms/s) " + instance, oracle.getPerSecondValue("file io wait time"));
78 sendDataPoint("ORA Executes (#/s) " + instance, oracle.getPerSecondValue("execute count"));
79 sendDataPoint("ORA User Calls (#/s) " + instance, oracle.getPerSecondValue("user calls"));
80 sendDataPoint("ORA User Commits (#/s) " + instance, oracle.getPerSecondValue("user commits"));
81 sendDataPoint("ORA User Rollbacks (#/s) " + instance, oracle.getPerSecondValue("user rollbacks"));
82 sendDataPoint("ORA Parse Count Total (#/s) " + instance, oracle.getPerSecondValue("parse count (total)"));
83 sendDataPoint("ORA Parse Count Hard (#/s) " + instance, oracle.getPerSecondValue("parse count (hard)"));
84 } else {
85 firstIteration = false;
86 }
87 }
88
89 return 0;
90 }//end of action
91
92
93 public int end() throws Throwable
94 {
95 for(OraMon oracle : oraList)
96 {
97 oracle.close();
98 }
99
100 return 0;
101 }//end of end
102
103 // Needed to avoid LR12 VuGen from hanging in a CPU loop (later fixed by a patch but just in case)
104 public void sendDataPoint(String name, double value)
105 {
106 lr.user_data_point(name, value);
107 }
108 }
109
110
1 /*
2 * LoadRunner Java script. (Build: _build_number_)
3 *
4 * Script Description:
5 *
6 */
7
8 import java.util.ArrayList;
9 import lrapi.lr;
10 import se.lil.om.*;
11
12 public class Actions
13 {
14
15 ArrayList<OraMon> oraList = new ArrayList<OraMon>();
16
17 boolean firstIteration = true;
18 String empty = "";
19
20 public int init() throws Throwable
21 {
22 if(lr.get_attrib_string("ConnectionString") == null || lr.get_attrib_string("User") == null || lr.get_attrib_string("Password") == null ||
23 lr.get_attrib_string("ConnectionString").equals(empty) || lr.get_attrib_string("User").equals(empty) || lr.get_attrib_string("Password").equals(empty))
24 {
25 lr.error_message("Attributes are missing for Oracle: ConnectionString, User or Password are null. Nothing to do, aborting vuser.");
26 lr.exit(lr.EXIT_VUSER, lr.FAIL);
27 }
28
29 String[] conS = lr.get_attrib_string("ConnectionString").split(",");
30 String[] usrS = lr.get_attrib_string("User").split(",");
31 String[] pasS = lr.get_attrib_string("Password").split(",");
32
33 if(conS.length != usrS.length || conS.length != pasS.length)
34 {
35 lr.error_message("Oracle has multiple comma separated connection strings but not the same number of multiple user or password strings. Cannot continue, abort.");
36 lr.exit(lr.EXIT_VUSER, lr.FAIL);
37 }
38
39 for(int x=0; x<conS.length; x++)
40 {
41 OraMon mon = new OraMon();
42 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG , " Using " + conS[x].trim() + " User " + usrS[x].trim() + " Pass " + pasS[x].trim());
43 mon.open(conS[x].trim(), usrS[x].trim(), pasS[x].trim());
44 oraList.add(mon);
45 }
46 return 0;
47 }////end of init
48
49
50 public int action() throws Throwable
51 {
52
53 for(OraMon oracle : oraList)
54 {
55 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG , "#### ORACLE COUNTERS ####");
56 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG, "Using: " + oracle.getConString());
57 oracle.getData();
58 lr.debug_message (lr.MSG_CLASS_EXTENDED_LOG, "Returned DB Name: " + oracle.getDBName());
59
60 if(firstIteration == false)
61 {
62 String instance = oracle.getDBName();
63 sendDataPoint("ORA Cpus (#) " + instance, oracle.getNumberOfCPUs());
64 sendDataPoint("ORA Cpu Time (ms/s) " + instance, oracle.getCPUTimePerSecond());
65 sendDataPoint("ORA Cpu Usage (%) " + instance, oracle.getCPUPercent());
66 sendDataPoint("ORA Logical Reads (#/s) " + instance, oracle.getLogicalReadsPerSecond());
67 sendDataPoint("ORA Consistent Gets (#/s) " + instance, oracle.getPerSecondValue("consistent gets"));
68 sendDataPoint("ORA DB Block Gets (#/s) " + instance, oracle.getPerSecondValue("db block gets"));
69 sendDataPoint("ORA Cache Hit Ratio (%) " + instance, oracle.getCacheHitRatioPercent());
70 sendDataPoint("ORA Buffer Cache Hit Ratio (%) " + instance, oracle.getBufferCacheHitRatioPercent());
71 sendDataPoint("ORA DB Block Changes (#/s) " + instance, oracle.getPerSecondValue("db block changes"));
72 sendDataPoint("ORA Redo Size (#/s) " + instance, oracle.getPerSecondValue("redo size"));
73 sendDataPoint("ORA Physical Reads (#/s) " + instance, oracle.getPerSecondValue("physical reads"));
74 sendDataPoint("ORA Physical Writes (#/s) " + instance, oracle.getPerSecondValue("physical writes"));
75 sendDataPoint("ORA Redo Writes (#/s) " + instance, oracle.getPerSecondValue("redo writes"));
76 sendDataPoint("ORA Non-idle Wait Time (ms/s) " + instance, oracle.getPerSecondValue("non-idle wait time"));
77 sendDataPoint("ORA File I/O Wait Time (ms/s) " + instance, oracle.getPerSecondValue("file io wait time"));
78 sendDataPoint("ORA Executes (#/s) " + instance, oracle.getPerSecondValue("execute count"));
79 sendDataPoint("ORA User Calls (#/s) " + instance, oracle.getPerSecondValue("user calls"));
80 sendDataPoint("ORA User Commits (#/s) " + instance, oracle.getPerSecondValue("user commits"));
81 sendDataPoint("ORA User Rollbacks (#/s) " + instance, oracle.getPerSecondValue("user rollbacks"));
82 sendDataPoint("ORA Parse Count Total (#/s) " + instance, oracle.getPerSecondValue("parse count (total)"));
83 sendDataPoint("ORA Parse Count Hard (#/s) " + instance, oracle.getPerSecondValue("parse count (hard)"));
84 } else {
85 firstIteration = false;
86 }
87 }
88
89 return 0;
90 }////end of action
91
92
93 public int end() throws Throwable
94 {
95 for(OraMon oracle : oraList)
96 {
97 oracle.close();
98 }
99
100 return 0;
101 }////end of end
102
103 // Needed to avoid LR12 VuGen from hanging in a CPU loop (later fixed by a patch but just in case)
104 public void sendDataPoint(String name, double value)
105 {
106 lr.user_data_point(name, value);
107 }
108 }
109
110
1 [General]
2 Type=General-Java
3 RecordedProtocol=
4 DefaultCfg=default.cfg
5 AppName=
6 BuildTarget=
7 ParamRightBrace=>
8 ParamLeftBrace=<
9 NewFunctionHeader=1
10 LastActiveAction=Actions
11 CorrInfoReportDir=
12 LastResultDir=
13 DevelopTool=Vugen
14 ActionLogicExt=action_logic
15 MajorVersion=12
16 MinorVersion=50
17 ParameterFile=
18 GlobalParameterFile=
19 RunType=Java-Interpreter
20 LastModifyVer=12.50.0.0
21 AdditionalTypes=General-Java
22 GenerateTypes=
23 ActiveTypes=
24 ScriptLanguage=JAVA
25 DisableRegenerate=0
26 Description=
27 [TransactionsOrder]
28 Order=
29 [Actions]
30 vuser_init=vuser_init.java
31 Actions=Actions.java
32 vuser_end=vuser_end.java
33 [ProtocolsVersion]
34 General-Java=11.0.0.0
35 [RunLogicFiles]
36 Default Profile=default.usp
37 [StateManagement]
38 1=1
39 4=0
40 9=0
41 10=0
42 11=0
43 12=0
44 17=0
45 18=0
46 20=0
47 21=0
48 CurrentState=1
49 VuserStateHistory=0 65536 65552
50 LastReplayStatus=2
51 [ActiveReplay]
52 LastReplayedRunName=result1
53 ActiveRunName=result1
54 [Recorded Actions]
55 vuser_init=0
56 Actions=0
57 vuser_end=0
58 [Replayed Actions]
59 vuser_init=1
60 Actions=1
61 vuser_end=1
62 [Modified Actions]
63 vuser_init=0
64 Actions=1
65 vuser_end=0
66 [ManuallyExtraFiles]
67 lilom.jar=
68 ojdbc6.jar=
69 [Interpreters]
70 vuser_init=Java-Interpreter
71 Actions=Java-Interpreter
72 vuser_end=Java-Interpreter
1 [General]
2 XlBridgeTimeout=120
3 DefaultRunLogic=default.usp
4 iter_begins_val=fixed
5 iter_ends_val=fixed
6 ContinueOnError=0
7 FailTransOnErrorMsg=0
8 AutomaticTransactions=0
9 UseThreads=1
10 [ThinkTime]
11 Options=NOTHINK
12 Factor=1.000000
13 LimitFlag=0
14 Limit=1
15 ThinkTimeRandomLow=50
16 ThinkTimeRandomHigh=150
17 [Iterations]
18 NumOfIterations=1
19 IterationPace=IterationASAP
20 StartEvery=60
21 RandomMin=60
22 RandomMax=90
23 [Log]
24 LogOptions=LogExtended
25 MsgClassData=0
26 MsgClassParameters=0
27 MsgClassFull=0
28 AutoLog=0
29 PrintTimeStamp=0
30 [CommandArguments]
31 ConnectionString=jdbc:oracle:thin:@host:port:sid
32 ~ConnectionString=Tex "jdbc:oracle:thin:@host:port:sid"
33 User=system
34 ~User=Tex "oracleuser"
35 Password=passw0rd
36 ~Password=
37 [JavaVM:Options]
38 Java_Env_ClassPath=ojdbc6.jar;se.ttm.tdemon.jar;
39 Java_Env_ClassPath_Unused=
40 Java_Previous_Class_Path=
41 use_jdk=search_jdk
42 jdk_home=
43 Java_VM_Params=
44 Use_Xboot=0
45 enable_CL_per_vuser=0
46 [ModemSpeed]
47 EnableModemSpeed=0
48 EnableCustomModemSpeed=0
49 ModemSpeed=128000
50 CustomModemSpeed=1000
1 [RunLogicEndRoot:vuser_end]
2 MercIniTreeSectionName="vuser_end"
3 RunLogicObjectKind="Action"
4 Name="vuser_end"
5 RunLogicInterpreterType="Java-Interpreter"
6 MercIniTreeFather="RunLogicEndRoot"
7 RunLogicActionType="VuserEnd"
8 [RunLogicInitRoot:vuser_init]
9 MercIniTreeSectionName="vuser_init"
10 RunLogicObjectKind="Action"
11 Name="vuser_init"
12 RunLogicInterpreterType="Java-Interpreter"
13 MercIniTreeFather="RunLogicInitRoot"
14 RunLogicActionType="VuserInit"
15 [RunLogicRunRoot:Actions]
16 MercIniTreeSectionName="Actions"
17 RunLogicObjectKind="Action"
18 Name="Actions"
19 RunLogicInterpreterType="Java-Interpreter"
20 MercIniTreeFather="RunLogicRunRoot"
21 RunLogicActionType="VuserRun"
22 [Profile Actions]
23 Profile Actions name=vuser_init,Actions,vuser_end
24 MercIniTreeSectionName="Profile Actions"
25 MercIniTreeFather=""
26 [RunLogicRunRoot]
27 RunLogicPaceConstTime="60,000"
28 RunLogicRandomPaceMax="90,000"
29 RunLogicActionOrder="Actions"
30 RunLogicAfterPaceMax="90,000"
31 MercIniTreeFather=""
32 RunLogicPaceType="ConstAfter"
33 MercIniTreeSons="Actions"
34 RunLogicNumOfIterations="2"
35 Name="Run"
36 RunLogicAfterPaceMin="60,000"
37 RunLogicRunMode="Sequential"
38 RunLogicPaceConstAfterTime="15,000"
39 RunLogicObjectKind="Group"
40 RunLogicActionType="VuserRun"
41 RunLogicRandomPaceMin="60,000"
42 MercIniTreeSectionName="RunLogicRunRoot"
43 [RunLogicEndRoot]
44 RunLogicActionOrder="vuser_end"
45 MercIniTreeFather=""
46 MercIniTreeSons="vuser_end"
47 RunLogicNumOfIterations="1"
48 Name="End"
49 RunLogicRunMode="Sequential"
50 RunLogicObjectKind="Group"
51 RunLogicActionType="VuserEnd"
52 MercIniTreeSectionName="RunLogicEndRoot"
53 [RunLogicInitRoot]
54 RunLogicActionOrder="vuser_init"
55 MercIniTreeFather=""
56 MercIniTreeSons="vuser_init"
57 RunLogicNumOfIterations="1"
58 Name="Init"
59 RunLogicRunMode="Sequential"
60 RunLogicObjectKind="Group"
61 RunLogicActionType="VuserInit"
62 MercIniTreeSectionName="RunLogicInitRoot"
No preview for this file type
No preview for this file type
No preview for this file type
1
2 // Do not change this file
1
2 // Do not change this file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <classpath>
3 <classpathentry kind="src" path=""/>
4 <classpathentry exported="true" kind="lib" path="lib/ojdbc6.jar"/>
5 <classpathentry exported="true" kind="lib" path="lib/ojdbc5.jar"/>
6 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
7 <classpathentry kind="output" path=""/>
8 </classpath>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <projectDescription>
3 <name>LILOM Library</name>
4 <comment></comment>
5 <projects>
6 </projects>
7 <buildSpec>
8 <buildCommand>
9 <name>org.eclipse.jdt.core.javabuilder</name>
10 <arguments>
11 </arguments>
12 </buildCommand>
13 </buildSpec>
14 <natures>
15 <nature>org.eclipse.jdt.core.javanature</nature>
16 </natures>
17 </projectDescription>
1 eclipse.preferences.version=1
2 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 org.eclipse.jdt.core.compiler.compliance=1.6
6 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 org.eclipse.jdt.core.compiler.source=1.6
No preview for this file type
No preview for this file type
1 package se.lil.om;
2
3 import java.sql.ResultSet;
4 import java.sql.Timestamp;
5 import java.util.ArrayList;
6
7 class Collector {
8 ArrayList<LongDelta> list = new ArrayList<LongDelta>();
9
10 public void update(ResultSet rset) throws Throwable {
11 while(rset.next()) {
12 updateValue(rset.getTimestamp(1), rset.getString(2), rset.getLong(3));
13 }
14 rset.close();
15 }
16
17 public void updateValue(Timestamp ts, String name, Long value) {
18 LongDelta myDelta = null;
19 for(int x = 0; x<list.size() && myDelta == null; x++) {
20 if(name.equals(list.get(x).name)) {
21 myDelta = list.get(x);
22 }
23 }
24 if(myDelta != null) {
25 myDelta.lastFetch = myDelta.curFetch;
26 myDelta.curFetch = ts;
27 myDelta.lastValue = myDelta.curValue;
28 myDelta.curValue = value;
29 } else {
30 myDelta = new LongDelta();
31 myDelta.curFetch = ts;
32 myDelta.curValue = value;
33 myDelta.name = name;
34 list.add(myDelta);
35 }
36 }
37
38 public long getPerSecValue(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.getPerSecondValue();
47 else
48 return 0;
49 }
50 }
...\ No newline at end of file ...\ No newline at end of file
1 package se.lil.om;
2
3 import java.sql.ResultSet;
4 import java.sql.Timestamp;
5
6 class LongDelta {
7 public String name = null;
8 public Long curValue = null;
9 public Long lastValue = null;
10 public Timestamp lastFetch = null;
11 public Timestamp curFetch = null;
12
13 public void update(ResultSet rset) throws Throwable{
14 update(rset, false);
15 }
16 public void update(ResultSet rset, boolean convert) throws Throwable{
17 rset.next();
18 this.lastFetch = this.curFetch;
19 this.curFetch = rset.getTimestamp(1);
20 this.lastValue = this.curValue;
21 if(convert)
22 this.curValue = rset.getLong(2)/1000;
23 else
24 this.curValue = rset.getLong(2);
25 rset.close();
26 }
27 public long getPerSecondValue() throws Throwable {
28 if(this.curValue != null && this.lastValue != null && this.lastFetch != null && this.curFetch != null) {
29 // We have values, calculate the number of gets per second
30 long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
31 long delta = this.curValue - this.lastValue;
32 return delta/numSeconds;
33 } else {
34 return 0;
35 }
36 }
37 public long getSeconds() throws Throwable {
38 if(this.lastFetch != null && this.curFetch != null) {
39 long numSeconds = (this.curFetch.getTime() - this.lastFetch.getTime()) / 1000;
40 return numSeconds;
41 }
42 return 0;
43 }
44 }
...\ No newline at end of file ...\ No newline at end of file
1 package se.lil.om;
2
3 import java.sql.*;
4
5 public class OraMon {
6 Connection conn = null;
7 String conString = "jdbc:oracle:thin:@//hostname:1521/SID";
8 String conUser = "system";
9 String conPass = "passw0rd";
10 String dbName = null;
11
12 Collector col = new Collector();
13
14 public String getConString() {
15 return this.conString;
16 }
17
18 //NUM_CPUS
19 int numCpus = 0;
20 public long getNumberOfCPUs() throws Throwable {
21 return numCpus;
22 }
23
24 //DB CPU
25 LongDelta cpuTime = new LongDelta();
26 public double getCPUPercent() throws Throwable {
27 double perSec = cpuTime.getPerSecondValue();
28 double totSec = numCpus * 1000;
29 double percent = (perSec / totSec) * 100;
30 return percent;
31 }
32
33 public long getCPUTimePerSecond() throws Throwable {
34 return cpuTime.getPerSecondValue();
35 }
36
37 public long getPerSecondValue(String name) throws Throwable {
38 return col.getPerSecValue(name);
39 }
40
41 public String getDBName() throws Throwable {
42 return this.dbName;
43 }
44
45 public double getBufferCacheHitRatioPercent() throws Throwable {
46 double conGetsCache = getPerSecondValue("consistent gets from cache");
47 double dbBlocksCache = getPerSecondValue("db block gets from cache");
48 double physReadsCache = getPerSecondValue("physical reads cache");
49 if (conGetsCache + dbBlocksCache + physReadsCache == 0) {
50 return 100;
51 }
52 if (conGetsCache + dbBlocksCache == 0 && physReadsCache > 0) {
53 return 0;
54 }
55 double buffCacheHitRatio = 1 - (physReadsCache/(conGetsCache + dbBlocksCache));
56 return buffCacheHitRatio * 100;
57 }
58
59 public double getCacheHitRatioPercent() throws Throwable {
60 double conGets = getPerSecondValue("consistent gets");
61 double dbBlocks = getPerSecondValue("db block gets");
62 double physReads = getPerSecondValue("physical reads");
63 if (conGets + dbBlocks + physReads == 0) {
64 return 100;
65 }
66 if (conGets + dbBlocks == 0 && physReads > 0) {
67 return 0;
68 }
69 double cacheHitRatio = 1 - (physReads/(conGets + dbBlocks));
70 return cacheHitRatio * 100;
71 }
72
73 public long getLogicalReadsPerSecond() throws Throwable {
74 return getPerSecondValue("consistent gets") + getPerSecondValue("db block gets");
75 }
76
77 public void getData() throws Throwable {
78 Statement stmt = conn.createStatement();
79 ResultSet rset = null;
80
81 //Get the database name once
82 if(this.dbName == null) {
83 rset = stmt.executeQuery("select value from V$SYSTEM_PARAMETER where name = 'db_name'");
84 rset.next();
85 this.dbName = rset.getString(1);
86 rset.close();
87 }
88
89 //Get values for CPU calculation
90 rset = stmt.executeQuery("select value from V$OSSTAT where STAT_NAME = 'NUM_CPUS'");
91 rset.next();
92 this.numCpus = rset.getInt(1);
93 rset.close();
94
95 cpuTime.update(stmt.executeQuery("select systimestamp, value from V$SYS_TIME_MODEL where stat_name='DB CPU'"), true);
96
97 // Get the entire V_$SYSSTAT table from DB
98 col.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
99
100 stmt.close();
101 }
102
103 public OraMon() {
104 // TODO Auto-generated constructor stub
105 }
106
107 public OraMon(String con, String user, String pass) {
108 this.conString = con;
109 this.conUser = user;
110 this.conPass = pass;
111 }
112
113 public void open() throws Throwable {
114 Class.forName ("oracle.jdbc.OracleDriver");
115 this.conn = DriverManager.getConnection(conString, conUser, conPass);
116 }
117
118 public void open(String con, String user, String pass) throws Throwable {
119 Class.forName ("oracle.jdbc.OracleDriver");
120 if(con != null) this.conString = con;
121 if(user != null) this.conUser = user;
122 if(pass != null) this.conPass = pass;
123 this.conn = DriverManager.getConnection(conString, conUser, conPass);
124 }
125
126 public void close() throws Throwable {
127 if(conn != null) conn.close();
128 }
129 }
130
1 package se.lil.om;
2
3 import java.util.ArrayList;
4
5 public class TestRunner {
6
7 public TestRunner() {
8 // TODO Auto-generated constructor stub
9 }
10
11 /**
12 * @param args
13 */
14 public static void main(String[] args) throws Throwable{
15 // TODO Auto-generated method stub
16
17 ArrayList<OraMon> oraList = new ArrayList<OraMon>();
18
19 OraMon mon1 = new OraMon("jdbc:oracle:thin:@//hostname:1521/SID1","system","passw0rd");
20 OraMon mon2 = new OraMon("jdbc:oracle:thin:@//hostname:1521/SID1","system","passw0rd");
21 mon1.open();
22 mon2.open();
23 oraList.add(mon1);
24 oraList.add(mon2);
25
26 int times = 10;
27 while(times-- > 0) {
28 for(OraMon mon : oraList) {
29 Long ts1 = System.currentTimeMillis();
30 mon.getData();
31 Long time = System.currentTimeMillis() - ts1;
32
33 System.out.println(
34 "Logical reads:" + mon.getLogicalReadsPerSecond()
35 + " Consistent gets: " + mon.getPerSecondValue("consistent gets")
36 + " Block Gets: " + mon.getPerSecondValue("db block gets")
37 + " Block Changes: " + mon.getPerSecondValue("db block changes")
38 + "\n"
39 + "CPUs: " + mon.getNumberOfCPUs()
40 + " CPU Time: " + mon.getCPUTimePerSecond() + "ms"
41 + " CPU Usage: " + String.format("%1$,.2f", mon.getCPUPercent()) + "%"
42 + "\n"
43 + "Cache Hit Ratio: " + String.format("%1$,.2f", mon.getCacheHitRatioPercent()) + "%"
44 + " Buffer Cache Hit Ratio: " + String.format("%1$,.2f", mon.getBufferCacheHitRatioPercent()) + "%"
45 + "\n"
46 + "Redo size: " + mon.getPerSecondValue("redo size")
47 + " Phys Reads: " + mon.getPerSecondValue("physical reads")
48 + " Phys Writes: " + mon.getPerSecondValue("physical writes")
49 + " Redo Writes: " + mon.getPerSecondValue("redo writes")
50 + "\n"
51 + "Non Idle Wait: " + mon.getPerSecondValue("non-idle wait time")
52 + " File IO Wait: " + mon.getPerSecondValue("file io wait time")
53 + "\n"
54 + "Executes: " + mon.getPerSecondValue("execute count")
55 + " User calls: " + mon.getPerSecondValue("user calls")
56 + " Commits: " + mon.getPerSecondValue("user commits")
57 + " Rollbacks: " + mon.getPerSecondValue("user rollbacks")
58 + " Parse tot: " + mon.getPerSecondValue("parse count (total)")
59 + " Parse hard: " + mon.getPerSecondValue("parse count (hard)")
60 + "\nTime: " + time + "ms"
61 );
62
63 }
64 Thread.sleep(15000);
65 }
66
67 // Close all mon objects
68 for(OraMon mon : oraList) {
69 mon.close();
70 }
71 }
72
73 }