Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 207710

Accessing ConfigResponse values from MeasurementPlugin

$
0
0

Hello all,

 

How do we access values from the ConfigResponse class with in a custom MeasurmentPlugin.

 

The getValue(Metric metric) does not seem to have a reference to ConfigResponse class.

 

Even overriding the 'translate' method is not helping as this not being called by the Hq framework before the getValue() method call.

 

Please let me if there are any workarounds or what is the correct approach in such cases?

 

Sample code give below:

 

public class SampleMeasurement extends MeasurementPlugin
{
    private String nodePort;
    private String nodeName;
    private String adminRMIPort;

    private static Log   log = LogFactory.getLog(SampleMeasurement.class.getName());

    @Override
    public MetricValue getValue(Metric metric)
    {
        MetricValue res = null;
        double doubleVal = 0d;
        log.debug("Within getValue <=> " + nodeName + "---------" + nodePort + "---------------" + adminRMIPort);
        String objectName = metric.getObjectName();
        String attributeName = metric.getAttributeName();
        log.debug("Object Name ... = " + objectName + "lllll" + attributeName);
        String JMXStringURL = "service:jmx:rmi:///jndi/rmi://localhost";
        String adminPortInfo = ":" + adminRMIPort + "/dsearch";

        JMXStringURL +=adminPortInfo;

 

        try
        {
            final ObjectName objName = new ObjectName(objectName);
            final JMXServiceURL jmxServiceURL = new JMXServiceURL(JMXStringURL);
            final JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL);
            MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();

            List<String> nodeStatus = (ArrayList)mbeanServerConnection.getAttribute(objName,attributeName);
            log.debug("Status -------------------------- " + nodeStatus);
            String statusForNode = "";
            for(String status:nodeStatus)
            {
                if(status.split(":")[0].equalsIgnoreCase(nodeName))
                {
                    statusForNode = status.split(":")[1];
                    log.debug("Status For Node --------------- " + statusForNode);
                    if(statusForNode.equalsIgnoreCase("normal"))
                    {
                        doubleVal = Metric.AVAIL_UP;
                    }
                    else
                    {
                        doubleVal = Metric.AVAIL_DOWN;
                    }
                    break;
                }
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        return new MetricValue(doubleVal);
    }

    @Override
    public String translate(String template, ConfigResponse config)
    {
        log.debug("TRANSLATE method called ----------------");
        if(template.contains("%port%") && template.contains("%nodename%") && template.contains("%rmiport%"))
        {
            String port = config.getValue("port");
            String node = config.getValue("nodename");
            String rmiPort = config.getValue("rmiport");

            template =template.replace("%port%",port);
            template = template.replace("%nodename%",node);
            template = template.replace("%rmiport%",rmiPort);

            log.debug("Template after replacement ------------------ " + template);
            nodePort = port;
            nodeName = node;
            adminRMIPort = rmiPort;
        }
        return super.translate(template,config);
    }
}

 

The config values like 'port', 'nodename' which are set in autodetector code is not available with in the getValue(Metric) shown above.


Viewing all articles
Browse latest Browse all 207710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>