IBM DB2 Manual page 510

Table of Contents

Advertisement

import java.sql.*;
import com.ibm.db2.jcc.*;
public class TestSystemMonitor
{
}
Figure 63. Example of using DB2SystemMonitor methods to collect system monitoring data
To collect system monitoring information using the trace method: Start a JDBC trace,
using configuration properties or Connection or DataSource properties. Include
TRACE_SYSTEM_MONITOR when you set the traceLevel property. For example:
String url = "jdbc:db2://sysmvs1.stl.ibm.com:5021/san_jose" +
The trace records with system monitor information look similar to this:
494
Application Programming Guide and Reference for Java
public static void main(String[] args)
{
String url = "jdbc:db2://sysmvs1.svl.ibm.com:5021/san_jose";
String user="db2adm";
String password="db2adm";
try
{
// Load the IBM Data Server Driver for JDBC and SQLJ
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("**** Loaded the JDBC driver");
// Create the connection using the IBM Data Server Driver for JDBC and SQLJ
Connection conn = DriverManager.getConnection (url,user,password);
// Commit changes manually
conn.setAutoCommit(false);
System.out.println("**** Created a JDBC connection to the data source");
DB2SystemMonitor systemMonitor =
((DB2Connection)conn).getDB2SystemMonitor();
systemMonitor.enable(true);
systemMonitor.start(DB2SystemMonitor.RESET_TIMES);
Statement stmt = conn.createStatement();
int numUpd = stmt.executeUpdate(
"UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'");
systemMonitor.stop();
System.out.println("Server elapsed time (microseconds)="
+ systemMonitor.getServerTimeMicros());
System.out.println("Network I/O elapsed time (microseconds)="
+ systemMonitor.getNetworkIOTimeMicros());
System.out.println("Core driver elapsed time (microseconds)="
+ systemMonitor.getCoreDriverTimeMicros());
System.out.println("Application elapsed time (milliseconds)="
+ systemMonitor.getApplicationTimeMillis());
conn.rollback();
stmt.close();
conn.close();
}
// Handle errors
catch(ClassNotFoundException e)
{
System.err.println("Unable to load the driver, " + e);
}
catch(SQLException e)
{
System.out.println("SQLException: " + e);
e.printStackTrace();
}
}
":traceFile=/u/db2p/jcctrace;" +
"traceLevel=" + com.ibm.db2.jcc.DB2BaseDataSource.TRACE_SYSTEM_MONITOR + ";";
1
2
3
4
5

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents