Welcome, guest | Sign In | My Account | Store | Cart

This script extracts the PMI JVM performance metrics from a WAS 5.1 application server running under ND and writes the data to a Cloudscape database.

Tcl, 393 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# 
# Get JVM PMI info for server. 
# NB: server must be running and PMI must be switched on.
#
####################################################################
# Patrick Finnegan 11/11/2005.  V1. 
####################################################################

####################################################################
# Get Cloudscape connection.
####################################################################
proc dbconnect { databaseName } {

   puts "\n**********"
   puts "dbconnect"
   puts "**********\n"

   global env 
   global null

   foreach x [ lindex [ array get env TCL_CLASSPATH ] 1 ] {

       puts [ format "%-5s %-50s" " " $x ] 

   }

   # import required classes 
   java::import java.sql.Connection
   java::import java.sql.DriverManager
   java::import java.sql.ResultSet
   java::import java.sql.SQLWarning
   java::import java.sql.Statement
   java::import java.sql.ResultSetMetaData 
   java::import org.apache.derby.jdbc.EmbeddedDriver

   puts "imported classes are:\n"
   
   foreach i [java::import] {
       
      puts [ format "%-5s %-50s" " " $i ] 

   }
       
   # load db2 driver .
   java::call Class forName org.apache.derby.jdbc.EmbeddedDriver

   append url jdbc:derby:$databaseName

   puts "\n connection URL is:  $url\n"   

   java::try {
       
       set ConnectionI [ java::call DriverManager getConnection $url ] 

   } catch {SQLException SQLExceptionI } {

     catchSqlException $SQLExceptionI 
	 
   } catch {TclException e } {
       puts "TCl Exception to prepare statement $e"
       return -code error
   }

   puts "transaction isolation level is [ $ConnectionI getTransactionIsolation ] \n"

   java::lock $ConnectionI 

   return $ConnectionI 

}
####################################################################
# proc - get JVM details 
####################################################################
proc getJVMInfo { nodeName serverName ConnectionI } {

   global AdminConfig 
   global AdminControl
   global null
   global Help

   puts "\n**********"
   puts "getJVMInfo"
   puts "**********\n"

   #puts "\nget the performance mbean for the server - should be just one.\n"

   append queryString "WebSphere:*,node="
   append queryString $nodeName
   append queryString ",process="
   append queryString $serverName
   append queryString ",type=Perf"

   #puts "\n query string is: $queryString \n"

   set perfMbean [ $AdminControl queryNames $queryString ]

   if { $perfMbean == $null || [ string length $perfMbean] == 0 } {
       
       puts "\n $serverName is not running or PMI is not enabled for $serverName. \n"

       return -code error

   } else {

       set donothing true 

   }

   #puts "\nget the JVM Bean.\n"

   unset queryString 

   append queryString "WebSphere:*,node="
   append queryString $nodeName
   append queryString ",process="
   append queryString $serverName
   append queryString ",type=JVM"

   #puts "\n query string is: $queryString \n"

   set jvmMbean [ $AdminControl queryNames $queryString ]

   if { $jvmMbean == $null || [ string length $jvmMbean] == 0 } {
       
       puts "\n $serverName jvm is not running \n"

       return -code error

   } else {

       set donothing true 

   }

   set jvmMbeanO [ $AdminControl makeObjectName $jvmMbean ]

   set boolean [ java::new Boolean recursive ]
   # NB: brackets around array object. 
   set parramsArray    [ java::new {Object[]} {2} [ list $jvmMbeanO $boolean ] ]
   set signaturesArray [ java::new {String[]} {2} [ list javax.management.ObjectName java.lang.Boolean ] ]

   set perfMbeanO [ $AdminControl makeObjectName $perfMbean ]

   #get the stats list from the performance bean
   set jvmInfo [ $AdminControl invoke_jmx $perfMbeanO "getStatsString" $parramsArray $signaturesArray   ] 

   set jvmInfoString [ $jvmInfo toString ] 

   #get PMI data sub list.
   set e4        [ lindex $jvmInfoString 3 ]  
   set dataList  [ lindex $e4 1 ]  
   set dataListL [ llength $dataList ]  

   # sort in id order
   set dataList [ lsort -dictionary -index 0 $dataList ] 

   set topParms [ lindex $dataList 0 ]  

   set width 60

   set descriptorIndex [ lsearch -glob $topParms {*Descriptor*} ]
   set descriptor      [ lindex $topParms $descriptorIndex ]
   set x1 "[ lindex [ lindex [ lindex $descriptor 1 ] 0 ] 0 ]"
   set x2 "[ lindex [ lindex [ lindex $descriptor 1 ] 0 ] 1 ]"
   puts    [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2
      
   set x1 "[ lindex [ lindex [ lindex $descriptor 1 ] 1 ] 0 ]"
   set x2 "[ lindex [ lindex [ lindex $descriptor 1 ] 1 ] 1 ]"
   puts    [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2

   set timeIndex [ lsearch -glob $topParms {*Time*} ]
   set time      [ lindex $topParms $timeIndex ]
   set x1        [ lindex [ lindex $topParms $timeIndex ] 0 ]
   set x2        [ clock format [ clock seconds ] -format "%Y-%m-%d %H:%M:%S" ]
   puts          [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2

   set valueIndex [ lsearch -glob $topParms {*Value*} ]
   set value      [ lindex $topParms $valueIndex ]
   set x1         [ lindex [ lindex $value 1 ] 0 ]
   set x2         [ lindex [ lindex $value 1 ] 1 ]
   puts           [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2

   set x1         [ lindex [ lindex $value 2 ] 0 ]
   set x2         [ lindex [ lindex $value 2 ] 1 ]
   puts           [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2

   set x1         [ lindex [ lindex $value 3 ] 0 ]
   set x2         [ lindex [ lindex $value 3 ] 1 ]
   puts           [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2

   set x1         [ lindex [ lindex $value 4 ] 0 ]
   set x2         [ lindex [ lindex $value 4 ] 1 ]
   puts           [ format "%-${width}s %s"  $x1 $x2 ]

   lappend valuesList $x2
   
   set x 1 

   while { $x < $dataListL } {

      set e                [ lindex $dataList $x ]

      set idIndex          [ lsearch -glob $e {*Id*} ]
      set id               [ lindex $e $idIndex ]

      set pmiDataInfoIndex [ lsearch -glob $e {*PmiDataInfo*} ]
      set pmiDataInfo      [ lindex $e $pmiDataInfoIndex ]

      set nl               [ eval concat [ join $e ] ]
      set commentIndex     [ lsearch -glob $nl {*Comment*} ]
      set comment          [ lindex [ lindex $nl $commentIndex ] 1 ]
      
      set valueIndex       [ lsearch -glob $e {*Value*} ]
      set value            [ lindex [ lindex [ lindex $e $valueIndex ] 1 ] 1 ]

      puts [ format "%-${width}s %s"  $comment $value ]

      lappend valuesList $value

      incr x 

   }

   # write data to DB2. 
   
   writeData $ConnectionI $valuesList  

   unset valuesList 
}
####################################################################
# proc - write data to database. 
####################################################################
proc writeData { ConnectionI valuesList } {

   global AdminConfig 
   global AdminControl
   global null

   puts "\n**********"
   puts "writeData"
   puts "**********\n"

   set opt1 [java::field ResultSet TYPE_SCROLL_INSENSITIVE]
   set opt2 [java::field ResultSet CONCUR_READ_ONLY ]

   set statement "insert into prod.wasperformjvm values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

   java::try {
       
       set StatementI [ $ConnectionI prepareStatement $statement ]

   } catch {SQLException SQLExceptionI } {

     catchSqlException $SQLExceptionI 
	 
   } catch {TclException e } {
       puts "TCl Exception to prepare statement $e"
       return -code error
   }

   set x 1

   foreach i $valuesList {

      $StatementI setString $x $i 

      incr x

   }

   #puts "execute sqlQuery"

   java::try {
       
       $StatementI executeUpdate   

   } catch {SQLException SQLExceptionI } {

     catchSqlException $SQLExceptionI 
	 
   } catch {TclException e } {
       puts "TCl Exception to prepare statement $e"
       return -code error
   }

}
####################################################################
# proc - sqlException. 
####################################################################
proc catchSqlException { SQLExceptionI } {

   global AdminConfig 
   global AdminControl
   global Help
   global null

   puts "\n**********"
   puts "catchSqlException"
   puts "**********\n"

   puts "\n*** Exception to prepare statement\n"

   while { [ $SQLExceptionI getNextException ] != $null } {

      set sqlCode       [ $SQLExceptionI toString         ]
      set sqlMessage    [ $SQLExceptionI getMessage       ]
      set errorCode     [ $SQLExceptionI getErrorCode     ] 
      set sqlState      [ $SQLExceptionI getSQLState      ] 
      set nextException [ $SQLExceptionI getNextException ]

      if { $nextException != $null } {
      
         set nextException [ $nextException toString ]

      } else {

         set nextException $null
         
      }

      if { $sqlCode       != $null } { puts "sql code is:       \t$sqlCode" }
      if { $sqlMessage    != $null } { puts "sql message is:    \t$sqlMessage " }
      if { $errorCode     != $null } { puts "error code is:     \t$errorCode" }
      if { $nextException != $null } { puts "next exception is: \t$nextException" }
      if { $sqlState      != $null } { puts "sql state is:      \t$sqlState" }

      return -code error

   }

}
####################################################################
# Main Control.
####################################################################

puts "\n argc = $argc \n"

if {$argc < 1} {
        return -code error "error - no arguments supplied.  Supply server name"
        puts "no arguments"
}

# Assume one cell, one deployment manager node and one application node. 

set cellId [ lindex [ $AdminConfig list Cell ] 0 ]
set nodes  [ $AdminConfig list Node ]

# delete the manager node from the list.

set manIndex   [ lsearch -glob $nodes *Manager* ]
set nodeId     [ lindex [ lreplace $nodes $manIndex $manIndex ] 0 ]

# get name attribute for cell and application node

set cellName [ $AdminConfig showAttribute $cellId name ]
set nodeName [ $AdminConfig showAttribute $nodeId name ]

set serverName [ lindex $argv 0 ]

set null [ java::null ]
global null

set databaseName C:/DERBYDatabases/Test1

if { [ catch { dbconnect $databaseName } r ] == 0 } {

   while {1} { 

     after 30000
     getJVMInfo $nodeName $serverName $r

   }

   $r close

} else {

    puts $r 
    exit 1   

}

The script is run from a top level bat file.

@echo off

set server=yourServer call :GETPMIINFO

goto :EOF

:GETPMIINFO echo ################################################### echo # set PMI info for %server% echo ###################################################

command.com /c

pushd C:\IBM\WebSphere\AppServer2\bin

call C:\IBM\WebSphere\AppServer2\bin\wsadmin -conntype SOAP^ -port 8879^ -host yourHost^ -user wsadminlogon^ -password wsadminlogon^ -f c:\scripts\websphere\jacl\getJVMINFO.tcl %server%

popd

The wsadmin bat file needs to be modified to include the Cloudscape jar files.

.............. ............. :runcmd

set WAS_CLASSPATH=%WAS_HOME%\lib\jacl.jar;%WAS_CLASSPATH% set WAS_CLASSPATH=%WAS_HOME%\lib\tcljava.jar;%WAS_CLASSPATH% set WAS_CLASSPATH=C:\IBM\Cloudscape_10.1\lib\derby.jar;%WAS_CLASSPATH% set WAS_CLASSPATH=C:\IBM\Cloudscape_10.1\lib\derbyclient.jar;%WAS_CLASSPATH% set WAS_CLASSPATH=C:\IBM\Cloudscape_10.1\lib\derbynet.jar;%WAS_CLASSPATH% set WAS_CLASSPATH=C:\IBM\Cloudscape_10.1\lib\derbytools.jar;%WAS_CLASSPATH%

"%JAVA_HOME%\bin\java" %javaoption% %CONSOLE_ENCODING% %DEBUG% "%CLIENTSOAP%" "%CLIENTSAS%" "-Dcom.ibm.ws.scripting.wsadminprops=%WSADMIN_PROPERTIES%" -Dcom.ibm.ws.management.standalone=true "-Duser.install.root=%USER_INSTALL_ROOT%" "-Dwas.install.root=%WAS_HOME%" "-Dwas.repository.root=%CONFIG_ROOT%" "-Dserver.root=%WAS_HOME%" "-Dlocal.cell=%WAS_CELL%" "-Dlocal.node=%WAS_NODE%" "-Dcom.ibm.itp.location=%WAS_HOME%\bin" "-classpath" "%WAS_CLASSPATH%;%WAS_HOME%\lib\jython.jar" "-Dws.ext.dirs=%WAS_EXT_DIRS%" com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.scripting.WasxShell %*

The PMI information logged is:

Node yournode Server yourapp Time 2005-11-11 11:59:54 Current 135002 LowWaterMark 134609 HighWaterMark 135002 MBean 134998.9441625089 Free memory in JVM runtime 51098 Used memory in JVM runtime 83904 The amount of time in seconds the JVM has been running 1551969 Number of garbage collection calls 1729 Average time (in seconds) between two garbage collection calls 1551241913 Average duration of a garbage collection call 358951 Number of objects allocated 1073655485 Number of objects freed 1073229205 Number of objects moved in heap 0 Number of threads started 65372 Number of threads died 65344 Number of times that a thread waits for a lock 11062080 Average time that a thread waits for a lock -939231008

Created by Patrick Finnegan on Thu, 10 Nov 2005 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks