vCenter

 View Only
  • 1.  Custom plugin dev problems

    Posted Dec 19, 2008 01:11 PM
    Hi,
    I have a few problems developing custom plugins:

    #1: My autodiscovery works, but even when I delete the resources from the server, the dashboard auto-autodiscovers them immediately, making it impossible to remove these resources from the server.

    #2: I want to monitor firefox. My autodiscovery looks like:


    public class AutoDiscovery extends ServerDetector implements

    AutoServerDetector {

    public List getServerResources(ConfigResponse platformConfig)

    throws PluginException {

    List servers = new ArrayList();

    ServerResource server;// = createServerResource("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    long[] pID=getPids("State.Name.eq=firefox"); //Name.state.eq=
    getLog().error("PTQL query in autodiscovery plugin done");

    String exe= getProcExe(pID[0]);
    server= createServerResource(new File(exe).getAbsolutePath());
    server.setDescription("M FFox3");
    server.setName("Mozilla Firefox server3");

    ConfigResponse productConfig = new ConfigResponse();
    productConfig.setValue("process.query", "State.Name.eq=firefox");


    ConfigResponse cprop= new ConfigResponse();
    cprop.setValue("process.query", "State.Name.eq=firefox");

    ConfigResponse customProperties= new ConfigResponse();

    server.setProductConfig(productConfig);
    server.setMeasurementConfig(cprop);
    server.setCustomProperties(customProperties);

    servers.add(server);

    getLog().error("----> plugin DONE!<-----");
    return servers;


    This was working fine till sometime back, when it abruptly decided to stop working. These things are not autodiscovered now.

    #3: Even in the good old times when it used to work, I never got the availability etc, (grey mark on the UI next to the server)

    My hq-plugin.xml is like:

    <?xml version="1.0"?>
    <plugin package="kt" name="kttwo">

    <filter name="domain" value="My Auto Discovery" />
    <property name="process.query" value="firefox"/>
    <metrics name="Generic Metric">

    <metric alias="Availability" category="AVAILABILITY"
    collectionType="dynamic" indicator="true" name="Availability"
    template="generic:Type=ProcState,Arg=%process.query%:State"
    units="percentage" />
    </metrics>

    <server name="Mozilla Firefox server">

    <plugin type="autoinventory" class="AutoDiscovery" />
    <!--
    <plugin class="org.hyperic.hq.plugin.generic.GenericMeasurementPlugin"
    type="measurement" /> -->
    <metrics include="Generic Metric" />


    </server>

    </plugin>

    and my measurement.java is:


    import org.hyperic.hq.product.Metric;
    import org.hyperic.hq.product.MetricNotFoundException;
    import org.hyperic.hq.product.MetricUnreachableException;
    import org.hyperic.hq.product.MetricValue;
    import org.hyperic.hq.product.PluginException;
    import org.hyperic.hq.product.SigarMeasurementPlugin;

    public class Measurement extends SigarMeasurementPlugin{

    public Measurement() {
    // TODO Auto-generated constructor stub
    }

    @Override
    public MetricValue getValue(Metric arg0) throws PluginException,
    MetricNotFoundException, MetricUnreachableException {
    // TODO Auto-generated method stub
    getLog().error("Collecting metrics");

    return super.getValue(arg0);
    }

    }


    Nothing of importance seen in either log (both when the autodiscovery used to work, and now when it doesn't), except that the getLog().error("Collecting metrics"); never shows up in the log.

    Thanks


  • 2.  RE: Custom plugin dev problems

    Posted Dec 19, 2008 04:55 PM
    #1
    Yes, this is the way it works. That is how auto discover works. If you don't want servers or services not to re-discover, discard those from the ui dashboard when they show up. Later if you want them back, is another issue...

    #2 and #3
    I'll see few problems, but please... could you post complete files as attachments. All java and hq-plugin.xml files.


  • 3.  RE: Custom plugin dev problems

    Posted Dec 20, 2008 04:39 AM
    Attaching files.

    Thanks


  • 4.  RE: Custom plugin dev problems
    Best Answer

    Posted Dec 20, 2008 01:32 PM
    OK, this was almost right... Here's little modification of hq-plugin.xml:

    --clip--
    <?xml version="1.0"?>
    <plugin package="kt" name="kttwo">

    <filter name="domain" value="My Auto Discovery" />
    <property name="process.query" value="firefox"/>
    <metrics name="Generic Metric">
    <metric alias="Availability" category="AVAILABILITY"
    collectionType="dynamic" indicator="true" name="Availability"
    template="sigar:Type=ProcState,Arg=%process.query%:State"
    units="percentage" />
    </metrics>

    <server name="Mozilla Firefox server">
    <plugin type="autoinventory" class="AutoDiscovery" />
    <plugin class="org.hyperic.hq.product.MeasurementPlugin"
    type="measurement" />
    <metrics include="Generic Metric" />
    <config>
    <option name="process.query"
    description="Process query for firefox"
    default="State.Name.eq=named"/>
    </config>
    </server>

    </plugin>
    --clip--

    When checking processes like you are now trying to do, use sigar. You had 'template="generic'.
    Then you may want to add option to server where this process query is stored and you can modify it from ui. Now the default value is 'named', so you can see that it's changed from your own autodiscovery class.
    To get measurement working, you kind of need to tell that to plugin. So I added measurement plugin. You had something but it was commented out.
    To use you own special classes for measurement collection, you need to tell plugin which is the new class to be used.

    Then one good advice. When you do plugin development, do it in the host where you are in position to re-install the HQ environment. Sometimes wrongly coded or configured plugins will mess the database, and you can't get your plugin work again. That is something what I always do. If I know that my plugin should work, but it doesn't, I will re-install HQ.


  • 5.  RE: Custom plugin dev problems

    Posted Dec 20, 2008 12:54 PM
    Hi,
    I have progressed a bit. I get the availability as 100% now. No issues there. but I have one more custom metric which is not getting returned. I can see from the log that the code is getting executed and the agent is returning the data. Attaching my plugin.xml and measurement.java. Also pasting the relevant bits here:


    plugin.xml:

    <metric alias="myMetric" category="UTILIZATION"
    collectionType="dynamic" indicator="true" name="myMetric"
    template="myDomain:Type=ProcState,Arg=%process.query%:State"
    units="percentage" />

    measurement.java


    if (arg0.getDomainName().equals("myDomain")){

    MetricValue metricValue= new MetricValue();
    metricValue.setValue(50);

    getLog().error("kt in the IF, collecting myMteric. Value is"+ metricValue.getValue());
    return metricValue;


    }

    I can see the kt in the IF, collecting myMteric. Value is"+ metricValue.getValue()
    in the log, but no metrics returned to the server.
    Thanks


  • 6.  RE: Custom plugin dev problems

    Posted Dec 20, 2008 01:54 PM
    Metric value is wrong. If your units is percentage, your values should be between 0.0 and 1.0. This may not be the problem. Also when creating new MetricValue, I usually set the timestamp:

    Double d = new Double(1.0)
    return new MetricValue(d, System.currentTimeMillis());

    Is your HQ ui showing that new metric field, even if it's empty?


  • 7.  RE: Custom plugin dev problems

    Posted Dec 22, 2008 09:04 AM
    Thanks guys, I got it working now!


  • 8.  RE: Custom plugin dev problems

    Posted May 25, 2009 02:21 PM
    Hello,
    i couldn't suucees executing this plugin, in the agent: Plugin-Name - Unable to load org.hyperic.hq.plugin.Autodiscovery for plugin Plugin-Name

    Any Help?