我正在更新我的 nagios 插件,该插件监控 tomcat7 的 tomcat 线程利用率,并且遇到"引号"括在"引号"中的值的问题。
来自 Dumper 的相关 XML:
$VAR1 = {
'connector' => {
'"ajp-bio-8009"' => {
'requestInfo' => {
'maxTime' => '0',
'errorCount' => '0',
'bytesSent' => '0',
'processingTime' => '0',
'requestCount' => '0',
'bytesReceived' => '0'
},
'workers' => {},
'threadInfo' => {
'currentThreadCount' => '0',
'maxThreads' => '500',
'currentThreadsBusy' => '0'
}
}
},
Relevent Perl:
$max = $xml->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'maxThreads'};
$current = $xml->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'currentThreadCount'};
$busy = $xml->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'currentThreadsBusy'};
但不幸的是,这似乎不起作用,因为我没有为 $max、$current 或$busy填充任何值。
根据要求的完整 XML:
<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/manager/xform.xsl" ?>
<status>
<jvm>
<memory free="70176624" total="165605376" max="2534080512"/>
<memorypool name="Eden Space" type="Heap memory" usageInit="12582912"
usageCommitted="45744128" usageMax="699072512" usageUsed="23043760"/>
<memorypool name="Survivor Space" type="Heap memory" usageInit="1572864"
usageCommitted="5701632" usageMax="87359488" usageUsed="5545632"/>
<memorypool name="Tenured Gen" type="Heap memory" usageInit="31588352"
usageCommitted="114159616" usageMax="1747648512" usageUsed="66839360"/>
<memorypool name="Code Cache" type="Non-heap memory" usageInit="2555904"
usageCommitted="5505024" usageMax="50331648" usageUsed="5395264"/>
<memorypool name="Perm Gen" type="Non-heap memory" usageInit="21757952"
usageCommitted="51904512" usageMax="1048576000" usageUsed="51657456"/>
</jvm>
<connector name='"ajp-bio-8009"'>
<threadInfo maxThreads="500" currentThreadCount="0" currentThreadsBusy="0"/>
<requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0"
bytesReceived="0" bytesSent="0"/>
<workers/>
</connector>
<connector name='"http-bio-8080"'>
<threadInfo maxThreads="200" currentThreadCount="10" currentThreadsBusy="1"/>
<requestInfo maxTime="1596" processingTime="4078" requestCount="416" errorCount="64"
bytesReceived="0" bytesSent="639904"/>
<workers>
<worker stage="R" requestProcessingTime="0" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="?" virtualHost="?" method="?"
currentUri="?" currentQueryString="?" protocol="?"/>
<worker stage="R" requestProcessingTime="0" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="?" virtualHost="?" method="?"
currentUri="?" currentQueryString="?" protocol="?"/>
<worker stage="R" requestProcessingTime="0" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="?" virtualHost="?" method="?"
currentUri="?" currentQueryString="?" protocol="?"/>
<worker stage="S" requestProcessingTime="3" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="38.88.49.38" virtualHost="blah01.blah.com"
method="GET" currentUri="/manager/status" currentQueryString="XML=true"
protocol="HTTP/1.1"/>
<worker stage="R" requestProcessingTime="0" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="?" virtualHost="?" method="?"
currentUri="?" currentQueryString="?" protocol="?"/>
<worker stage="R" requestProcessingTime="0" requestBytesSent="0"
requestBytesReceived="0" remoteAddr="?" virtualHost="?" method="?"
currentUri="?" currentQueryString="?" protocol="?"/>
</workers>
</connector>
</status>
我认为你的xml很好。您已经从转储器中得到了结果。也许你没有追求你的 acutal xml 对象。
如果您查看转储器输出,然后再次检查它,然后得到所需的值:
$max = $VAR1->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'maxThreads'};
$current = $VAR1->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'currentThreadCount'};
$busy = $VAR1->{'connector'}->{'"ajp-bio-8009"'}->{'threadInfo'}->{'currentThreadsBusy'};
print $max."n"; print $current."n"; print $busy."n";
这给了:
500
0
0
因此,我得出的结论是,您的$xml对象在某种程度上不是您要分析的对象(或者它是您要遍历的引用的上层或子结构)。