
achen
New User
Sep 30, 2009, 7:30 AM
Post #1 of 9
(1742 views)
|
|
is this greedy?
|
Can't Post
|
|
here is a snippet of a data file i have: ============================================================================= JDBC Runtimes rd7_datasource ============================================================================= -r-- ActiveConnectionsAverageCount 0 -r-- ActiveConnectionsCurrentCount 0 -r-- ActiveConnectionsHighCount 5 -r-- ConnectionDelayTime 91 -r-- ConnectionsTotalCount 70 -r-- CurrCapacity 70 -r-- CurrCapacityHighCount 0 -r-- DeploymentState 2 -r-- Enabled true -r-- FailedReserveRequestCount 0 -r-- FailuresToReconnectCount 0 -r-- HighestNumAvailable 70 -r-- HighestNumUnavailable 0 -r-- LastTask null -r-- LeakedConnectionCount 0 -r-- ModuleId rd7_datasource -r-- Name rd7_datasource -r-- NumAvailable 70 -r-- NumUnavailable 0 -r-- PrepStmtCacheAccessCount 60337 -r-- PrepStmtCacheAddCount 6796 -r-- PrepStmtCacheCurrentSize 77 -r-- PrepStmtCacheDeleteCount 6719 -r-- PrepStmtCacheHitCount 53541 -r-- PrepStmtCacheMissCount 6796 -r-- Properties {user=spd_user} -r-- ReserveRequestCount 86107 -r-- State Running -r-- Type JDBCDataSourceRuntime -r-- VersionJDBCDriver oracle.jdbc.OracleDriver -r-- WaitSecondsHighCount 0 -r-- WaitingForConnectionCurrentCount 0 -r-- WaitingForConnectionFailureTotal 0 -r-- WaitingForConnectionHighCount 0 -r-- WaitingForConnectionSuccessTotal 0 -r-- WaitingForConnectionTotal 0 -r-- WorkManagerRuntimes null ============================================================================= JDBC Runtimes fgrlog ============================================================================= -r-- ActiveConnectionsAverageCount 0 -r-- ActiveConnectionsCurrentCount 0 -r-- ActiveConnectionsHighCount 0 -r-- ConnectionDelayTime 119 -r-- ConnectionsTotalCount 30 -r-- CurrCapacity 30 -r-- CurrCapacityHighCount 0 -r-- DeploymentState 2 -r-- Enabled true -r-- FailedReserveRequestCount 0 -r-- FailuresToReconnectCount 0 -r-- HighestNumAvailable 30 -r-- HighestNumUnavailable 0 -r-- LastTask null -r-- LeakedConnectionCount 0 -r-- ModuleId fgrlog -r-- Name fgrlog -r-- NumAvailable 30 -r-- NumUnavailable 0 -r-- PrepStmtCacheAccessCount 0 -r-- PrepStmtCacheAddCount 0 -r-- PrepStmtCacheCurrentSize 0 -r-- PrepStmtCacheDeleteCount 0 -r-- PrepStmtCacheHitCount 0 -r-- PrepStmtCacheMissCount 0 -r-- Properties {user=log_user} -r-- ReserveRequestCount 0 -r-- State Running -r-- Type JDBCDataSourceRuntime -r-- VersionJDBCDriver oracle.jdbc.OracleDriver -r-- WaitSecondsHighCount 0 -r-- WaitingForConnectionCurrentCount 0 -r-- WaitingForConnectionFailureTotal 0 -r-- WaitingForConnectionHighCount 0 -r-- WaitingForConnectionSuccessTotal 0 -r-- WaitingForConnectionTotal 0 -r-- WorkManagerRuntimes null I want to extract each data source and its following attributes: ActiveConnectionsAverageCount ActiveConnectionsCurrentCount ActiveConnectionsHighCount WaitingForConnectionCurrentCount WaitingForConnectionFailureTotal WaitingForConnectionHighCount WaitingForConnectionTotal Here is my program: #!/usr/bin/perl $savedate = ""; open (LOG, "<test.log") or die "can't open log file: $!\n"; while (<LOG>) { chomp; if (/(^2009-09-29.*)/) { $date = $1; if ($savedate) { print "--------------------------\n"; print "$savedate\n"; print "--------------------------\n"; print "$jvmruntime\n"; print "$heapfreepercent\n"; print "--------------------------\n"; print "$rd7_datasource\n"; print "$rd7_activeconnavgcount\n"; print "$rd7_activeconncurrcount\n"; print "$rd7_activeconnhighcount\n"; print "$rd7_waitingforconncurrcount\n"; print "$rd7_waitingforconnhighcount\n"; print "$rd7_waitingforconntotal\n"; print "--------------------------\n"; print "$fgrlog_datasource\n"; print "$fgrlog_activeconnavgcount\n"; print "$fgrlog_activeconncurrcount\n"; print "$fgrlog_activeconnhighcount\n"; print "$fgrlog_waitingforconncurrcount\n"; print "$fgrlog_waitingforconnhighcount\n"; print "$fgrlog_waitingforconntotal\n"; print "--------------------------\n"; $savedate = $date; $jvmruntime = ""; $heapfreepercent = ""; $rd7_datasource = ""; $rd7_activeconnavgcount = ""; $rd7_activeconncurrcount = ""; $rd7_activeconnhighcount = ""; $rd7_waitingforconncurrcount = ""; $rd7_waitingforconnhighcount = ""; $rd7_waitingforconntotal = ""; $fgrlog_datasource = ""; $fgrlog_activeconnavgcount = ""; $fgrlog_activeconncurrcount = ""; $fgrlog_activeconnhighcount = ""; $fgrlog_waitingforconncurrcount = ""; $fgrlog_waitingforconnhighcount = ""; $fgrlog_waitingforconntotal = ""; next; } else { $savedate = $date; next; } } if (/(.*JVMRuntime.*)/) { $jvmruntime = $1; next; } if (/(.*HeapFreePercent.*)/) { $heapfreepercent = $1; next; } if (/(.*JDBC Runtimes rd7_datasource.*)/) { $rd7_datasource = $1; next; } if (/(.*ActiveConnectionsAverageCount.*)/) { $rd7_activeconnavgcount = $1; next; } if (/(.*ActiveConnectionsCurrentCount.*)/) { $rd7_activeconncurrcount = $1; next; } if (/(.*?ActiveConnectionsHighCount.*)/) { $rd7_activeconnhighcount = $1; next; } if (/(.*WaitingForConnectionCurrentCount.*)/) { $rd7_waitingforconncurrcount = $1; next; } if (/(.*WaitingForConnectionHighCount.*)/) { $rd7_waitingforconnhighcount = $1; next; } if (/(.*WaitingForConnectionTotal.*)/) { $rd7_waitingforconntotal = $1; next; } if (/(.*JDBC Runtimes fgrlog.*)/) { $fgrlog_datasource = $1; next; } if (/(.*ActiveConnectionsAverageCount.*)/) { $fgrlog_activeconnavgcount = $1; next; } if (/(.*ActiveConnectionsCurrentCount.*)/) { $fgrlog_activeconncurrcount = $1; next; } if (/(.*ActiveConnectionsHighCount.*)/) { $fgrlog_activeconnhighcount = $1; next; } if (/(.*WaitingForConnectionCurrentCount.*)/) { $fgrlog_waitingforconncurrcount = $1; next; } if (/(.*WaitingForConnectionHighCount.*)/) { $fgrlog_waitingforconnhighcount = $1; next; } if (/(.*WaitingForConnectionTotal.*)/) { $fgrlog_waitingforconntotal = $1; next; } } close LOG; Problem is, when I run the program, it finds "JDBC Runtimes rd7_datasource" and the picks up alll the attributes for "JDBC Runtimes fgrlog" instead. So I get the following output: -------------------------- 2009-09-29 22:54:41 -------------------------- -r-- Type JVMRuntime -r-- HeapFreePercent 33 -------------------------- JDBC Runtimes rd7_datasource -r-- ActiveConnectionsAverageCount 0 -r-- ActiveConnectionsCurrentCount 0 -r-- ActiveConnectionsHighCount 0 -r-- WaitingForConnectionCurrentCount 0 -r-- WaitingForConnectionHighCount 0 -r-- WaitingForConnectionTotal 0 -------------------------- JDBC Runtimes fgrlog -------------------------- How can I stop this greedy behavior - so the rd7_datasource properties get selected for rd7_datasource, instead of the fgrlog properties? Thanks for any help.
|