2013-12-20 88 views
2

我正在更新監視tomcat7的tomcat線程利用率的nagios插件,並且存在「引號」中所包含值的問題。包含引號的Perl xml

相關的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' 
                  } 
              } 
         }, 

培訓相關的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'}; 

但不幸的是這似乎不工作,當我不填充爲$最大的任何值,$當前或$繁忙。根據要求

完整的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="&#63;" virtualHost="&#63;" method="&#63;" 
       currentUri="&#63;" currentQueryString="&#63;" protocol="&#63;"/> 
      <worker stage="R" requestProcessingTime="0" requestBytesSent="0" 
       requestBytesReceived="0" remoteAddr="&#63;" virtualHost="&#63;" method="&#63;" 
       currentUri="&#63;" currentQueryString="&#63;" protocol="&#63;"/> 
      <worker stage="R" requestProcessingTime="0" requestBytesSent="0" 
       requestBytesReceived="0" remoteAddr="&#63;" virtualHost="&#63;" method="&#63;" 
       currentUri="&#63;" currentQueryString="&#63;" protocol="&#63;"/> 
      <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="&#63;" virtualHost="&#63;" method="&#63;" 
       currentUri="&#63;" currentQueryString="&#63;" protocol="&#63;"/> 
      <worker stage="R" requestProcessingTime="0" requestBytesSent="0" 
       requestBytesReceived="0" remoteAddr="&#63;" virtualHost="&#63;" method="&#63;" 
       currentUri="&#63;" currentQueryString="&#63;" protocol="&#63;"/> 
     </workers> 
    </connector> 
</status> 
+0

你可以顯示原始XML嗎? – David

+0

當然,編輯後。 – user3029353

+0

嘗試逐節點調試。例如,打印Dumper $ xml - > {'connector'} - > {'「ajp-bio-8009」'}然後下一個節點,直到最後一個節點。並檢查你在哪裏缺少價值。 –

回答

3

我想你的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 

所以,我的結論,即您的對象在某種程度上不是您想分析的對象(或者它是您想要遍歷的引用的子結構或子結構)。