2 Replies Latest reply on Jul 3, 2012 2:09 AM by freelancr

    Customizing the Script-Plugin

    freelancr

      Hello,

      for the last few days I am trying to edit or create my own Script plugin for several resources that have a CLI.

      The initial setup was successfulI after following this Demo:

      https://docs.jboss.org/author/display/RHQ/Demo-ScriptPlugin

       

      Now I am at the point where I want to add metrics based on regexs but I ran out of ideas where to define custom metrics. Has someone an idea where to define metrics?

       

      Here is what I done so far:

       

      1. Import a Script Server to the Platform resources.

      2. Succesfully setup the environment (executable, availability checks etc.)

       

      In my understanding in order to add metrics to this new resource I have to locate this resources' xml decription file ( see http://management-platform.blogspot.de/2009/04/managing-resources-that-have-cli.html) but I can't find it anywhere.

      I looked in the agent's plugin subdirectory. There I only found the generic plugin jars.

      My next try was to copy the rhq-script-plugin-4.4.0.jar to a new jar-file and edit the contents of such jars' "/META-INF/rhq-plugin.xml" file and then importing the jar as a new plug-in. However I had no success so far.

       

       

      Best,

      Thomas

        • 1. Re: Customizing the Script-Plugin
          mazz

          > In my understanding in order to add metrics to this new resource I have to locate this resources' xml decription file

          > ( see http://management-platform.blogspot.de/2009/04/managing-resources-that-have-cli.html) but I can't find it anywhere.

          >  looked in the agent's plugin subdirectory. There I only found the generic plugin jars.

           

          I seems as though you misunderstood how plugins work. You can't on-the-fly edit "resource xml description files". The XML descriptors come with plugins. Plugin XML descriptors define the resource types that that plugin can monitor. You don't edit an existing plugin's own XML descriptor - if you do, you most likely will break the plugin.

           

          The generic "script plugin" that ships with RHQ allows you to do basic things but out of box it does not monitor metrics because its XML plugin descriptor does not define any  definitions. This is to be expected - we don't know what kind of metrics your specific CLI/script can collect.  However, you CAN extend that plugin and reuse its Java code by doing as you said you were going to try - that is, "copy the rhq-script-plugin-4.4.0.jar to a new jar-file and edit the contents of such jars' "/META-INF/rhq-plugin.xml" file and then importing the jar as a new plug-in".

           

          You could conceivable use the plugin extension mechanisms so you don't even have to copy the Java code, just create a plugin jar with a single XML file descriptor.

           

          Your plugin would be for YOUR own script - and in your plugin, you know what metrics you want to collect so in your XML descriptor you WOULD define  definitions for your own resource type that will represent your script. See the generic script plugin and its XML descriptor that ships with RHQ for a commented-out <metric> definition as an example.

           

          There is javadoc documenation on what syntax is for the metric property value in your XML (see ScriptServerComponent.java source code), but I'll copy-n-paste it here:

           

              /**

               * Executes the CLI and based on the measurement property, collects the appropriate measurement value.

               * This supports measurement data and traits.

               * A metric property can be a string that is assumed the arguments to pass to the CLI. However, if

               * the property is in the form "{arguments}|regex", the arguments are passed to the CLI and the metric

               * value is taken from the regex match. Examples of metric properties:

               * 

               * <ul>

               * <li>"-a --arg2=123" - passes that string as the arguments list, the metric value is the output of the CLI</li>

               * <li>"{}|exitcode" - no arguments are passed to the CLI and the metric value is the exit code of the CLI</li>

               * <li>"{-a}|[lL]abel(\p{Digit}+)[\r\n]*" - "-a" is the argument passed to the CLI and the metric value is the digits following the label of the output</li>

               * <li>"{}|[ABC]+" - no arguments are passed and the value is the output of the CLI assuming it matches the regex</li>

               * <li>"{--foobar}|foobar (.*) blah" - passes "--foobar" as the argument and the metric value is the string that matches the regex group</li>

               * </ul>

               *

               */

          1 of 1 people found this helpful
          • 2. Re: Customizing the Script-Plugin
            freelancr

            Thank you John for pointing me in the right direction.