2012/03/23

troubleshooting

Halfway through the week I realised that I might have overreached myself just a little by promising to deliver the future and then most of the fun I had this week was still to come.

So, I'll postphone the future to next week and give you a short troubleshooting tip this week. For sometimes things go wrong. Networks can flap, disks can fail, processors can overheat. And then there's the OS, the JVM, ... Sometimes it is just amazing that anything works at all.

There is of course the Status tab in the HTTPBackend Fulcrum that has live graphs to study, but there is also the Requests and Threads page in the Developer tab.

Now this is a static page and I needed the information on just one specific thread at a more frequent interval. So I wrote a new tool :

<mapper>
  <config>
    <endpoint>
      <grammar>res:/tools/kerneldetail/
        <group name="threadname">
          <regex type="anything"/>
        </group>
      </grammar>
      <request>
        <identifier>active:xslt</identifier>
        <argument name="operand">netkernel:/k</argument>
        <argument name="operator">res:/resources/stylesheets/kerneldetail.xsl</argument>
        <argument name="threadname" method="as-string">arg:threadname</argument>
      </request>
    </endpoint>
  </config>
  <space>
    <fileset>
      <regex>res:/resources/stylesheets/.*</regex>
    </fileset>
    <import>
      <uri>urn:org:netkernel:xml:core</uri>
      <private/>
    </import>
    <import>
      <uri>urn:org:netkernel:ext:system</uri>
      <private/>
    </import>
  </space>
</mapper>


Did I say write ? No code (after no sql it is now time for the new paradigm, no code) of course. The netkernel:/k resource provides the raw data and I filter that with xslt :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:nk="http://netkernel.org" 
                version="1.0">
  <xsl:output method="xml" 
              indent="yes" 
              encoding="UTF-8" 
              omit-xml-declaration="yes"/>
  <xsl:param name="threadname" nk:class="java.lang.String" />


  <xsl:template match="/k">
    <xsl:copy-of select="threads/thread[name=$threadname]"/>
  </xsl:template>
</xsl:stylesheet>

And that's it. Put in a small script ... for example like this :
#!/bin/sh
while true
do
 curl http://localhost:1060/tools/kerneldetail/ConcurrentCacheCullThread >> /var/tmp/culler.out
 sleep 10
done
And collect all the data you want with minimum system impact.

So, next week I will deliver the future as promised.