[Hawkular-dev] using hawkular wildfly agent as a custom java agent

John Mazzitelli mazz at redhat.com
Wed Mar 23 09:28:03 EDT 2016


This is for Matt, but figured post here for public consumption.

The question was asked yesterday, "Can we use the Hawkular WildFly Agent to monitor other things other than WildFly?"

I gave one answer, but forgot there is a second alternative.

====

The first answer that I gave is that you can use the Hawkular Wildfly Agent to collect JMX data via Jolokia interface. There is an integration in the agent that lets you define your resource and metric metadata and your JMX/Jolokia servers. As an example, see here: https://github.com/hawkular/hawkular-agent/blob/b52529823ca3c54d0b8b4aa560d568cd114afdec/hawkular-wildfly-agent-feature-pack/src/main/resources/subsystem-templates/hawkular-wildfly-agent.xml#L736-L817

You define where your JMX servers are via the <remote-jmx> managed server like this:

   <remote-jmx name="Remote JMX" enabled="false" resourceTypeSets="MainJMX,MemoryPoolJMX" url="http://localhost:8080/jolokia-war"/>

OK, that's the JMX integration. Maybe useful, maybe not. But I mention it just in case.

====

The second alternative I forgot to mention was the ability for any component running in WildFly to obtain a Hawkular Agent proxy via JNDI and use that proxy that store inventory and metrics into the Hawkular Server.

There is an example WAR module in the agent git repo that demonstrates how to obtain the proxy via JNDI and how to store inventory and metrics - see here: https://github.com/hawkular/hawkular-agent/tree/master/hawkular-wildfly-agent-itest-parent/hawkular-wildfly-agent-example-jndi

This is just a simple WAR with a servlet. But it shows how a component can get the agent proxy via JNDI here:

https://github.com/hawkular/hawkular-agent/blob/master/hawkular-wildfly-agent-itest-parent/hawkular-wildfly-agent-example-jndi/src/main/java/org/hawkular/agent/example/HawkularWildFlyAgentProvider.java#L32-L35

Here's code that shows the servlet doing things like sending metrics, avail, and creating resources:

https://github.com/hawkular/hawkular-agent/blob/master/hawkular-wildfly-agent-itest-parent/hawkular-wildfly-agent-example-jndi/src/main/java/org/hawkular/agent/example/MyAppServlet.java

No one is using this yet. So there may be issues I am not aware of, but we have integration tests that show this working.

This was put together with the anticipation of someone asking for this capability - that is, "can the agent be used to collect metrics for other things other than WildFly". Essentially, this just gives you a skeleton Java agent that you can extend to collect your own metrics and inventory. So you can write a WAR or EAR, deploy it in any WildFly that has an agent subsystem, and your EAR/WAR can be used as an "agent" for your custom stuff.

Again, maybe useful, maybe not. But I mention it just in case.


More information about the hawkular-dev mailing list