You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by janne mattila <fr...@gmail.com> on 2014/03/07 16:44:50 UTC

how to create/ publish a new JMX MBean from a Camel route (blueprint)

I am trying to add JMX based healthcheck monitoring to my routes. I
followed instructions from
http://michalwarecki.blogspot.fi/2012/08/monitoring-and-managing-apache-camel.html("Custom
MBean"). My custom MBean looks like:

@ManagedResource(description = "Statictics Processor")
public class TestMBean implements Processor {

    private int totalRequests;

    private int totalCharacters;

    @ManagedAttribute
    public int getAvgChar() {
        return totalCharacters / totalRequests;
    }

    @ManagedAttribute
    public int getTotalChar() {
        return totalCharacters;
    }

    public void process(Exchange exchange) throws Exception {
       ++totalRequests;
       totalCharacters += ((String)
exchange.getIn().getBody(String.class)).length();
    }
}

and it has been added to my route. When I use hawtio web console to inspect
my routes, the processor is there but it does not have the getAvgChar /
getTotalChar operations. Only the default operations, available for all
processors, are there.

What is wrong and should I do something else completely to publish a new
JMX MBean from a Camel route running inside ServiceMix container?

Also, this mbean is published in jmx hierarchy in

my-host-name/290-xyroutename/processors/mybeansName

where 290 is the bundle ID (so not static). How can I configure the mbean
to be registered with some specific name?

Re: how to create/ publish a new JMX MBean from a Camel route (blueprint)

Posted by janne mattila <fr...@gmail.com>.
Ooops, sorry:
http://camel.apache.org/camel-jmx.html#CamelJMX-Managementnamingpattern

It's clearly documented there.


2014-03-10 8:58 GMT+02:00 janne mattila <fr...@gmail.com>:

> Thanks, adding "implements Service" did the trick. Pretty easy to add JMX
> management features this way!
>
> Any advice on this part of the question?:
>
>
> > Also, this mbean is published in jmx hierarchy in
> >
> > my-host-name/290-xyroutename/
> processors/mybeansName
> >
> > where 290 is the bundle ID (so not static). How can I configure the mbean
> > to be registered with some specific name?
>
> I want to create a programmatic health checker which tests my mbean, so I
> would need it's name to be something predefined.
>
>
>
> 2014-03-07 17:50 GMT+02:00 Claus Ibsen <cl...@gmail.com>:
>
> Hi
>>
>> If I remember you need to implement Service too for custom mbeans.
>> Or extend ServiceSupport.
>>
>>
>> On Fri, Mar 7, 2014 at 4:44 PM, janne mattila <fr...@gmail.com>
>> wrote:
>> > I am trying to add JMX based healthcheck monitoring to my routes. I
>> > followed instructions from
>> >
>> http://michalwarecki.blogspot.fi/2012/08/monitoring-and-managing-apache-camel.html(
>> "Custom
>> > MBean"). My custom MBean looks like:
>> >
>> > @ManagedResource(description = "Statictics Processor")
>> > public class TestMBean implements Processor {
>> >
>> >     private int totalRequests;
>> >
>> >     private int totalCharacters;
>> >
>> >     @ManagedAttribute
>> >     public int getAvgChar() {
>> >         return totalCharacters / totalRequests;
>> >     }
>> >
>> >     @ManagedAttribute
>> >     public int getTotalChar() {
>> >         return totalCharacters;
>> >     }
>> >
>> >     public void process(Exchange exchange) throws Exception {
>> >        ++totalRequests;
>> >        totalCharacters += ((String)
>> > exchange.getIn().getBody(String.class)).length();
>> >     }
>> > }
>> >
>> > and it has been added to my route. When I use hawtio web console to
>> inspect
>> > my routes, the processor is there but it does not have the getAvgChar /
>> > getTotalChar operations. Only the default operations, available for all
>> > processors, are there.
>> >
>> > What is wrong and should I do something else completely to publish a new
>> > JMX MBean from a Camel route running inside ServiceMix container?
>> >
>> > Also, this mbean is published in jmx hierarchy in
>> >
>> > my-host-name/290-xyroutename/processors/mybeansName
>> >
>> > where 290 is the bundle ID (so not static). How can I configure the
>> mbean
>> > to be registered with some specific name?
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> Make your Camel applications look hawt, try: http://hawt.io
>>
>
>

Re: how to create/ publish a new JMX MBean from a Camel route (blueprint)

Posted by janne mattila <fr...@gmail.com>.
Thanks, adding "implements Service" did the trick. Pretty easy to add JMX
management features this way!

Any advice on this part of the question?:

> Also, this mbean is published in jmx hierarchy in
>
> my-host-name/290-xyroutename/
processors/mybeansName
>
> where 290 is the bundle ID (so not static). How can I configure the mbean
> to be registered with some specific name?

I want to create a programmatic health checker which tests my mbean, so I
would need it's name to be something predefined.



2014-03-07 17:50 GMT+02:00 Claus Ibsen <cl...@gmail.com>:

> Hi
>
> If I remember you need to implement Service too for custom mbeans.
> Or extend ServiceSupport.
>
>
> On Fri, Mar 7, 2014 at 4:44 PM, janne mattila <fr...@gmail.com>
> wrote:
> > I am trying to add JMX based healthcheck monitoring to my routes. I
> > followed instructions from
> >
> http://michalwarecki.blogspot.fi/2012/08/monitoring-and-managing-apache-camel.html(
> "Custom
> > MBean"). My custom MBean looks like:
> >
> > @ManagedResource(description = "Statictics Processor")
> > public class TestMBean implements Processor {
> >
> >     private int totalRequests;
> >
> >     private int totalCharacters;
> >
> >     @ManagedAttribute
> >     public int getAvgChar() {
> >         return totalCharacters / totalRequests;
> >     }
> >
> >     @ManagedAttribute
> >     public int getTotalChar() {
> >         return totalCharacters;
> >     }
> >
> >     public void process(Exchange exchange) throws Exception {
> >        ++totalRequests;
> >        totalCharacters += ((String)
> > exchange.getIn().getBody(String.class)).length();
> >     }
> > }
> >
> > and it has been added to my route. When I use hawtio web console to
> inspect
> > my routes, the processor is there but it does not have the getAvgChar /
> > getTotalChar operations. Only the default operations, available for all
> > processors, are there.
> >
> > What is wrong and should I do something else completely to publish a new
> > JMX MBean from a Camel route running inside ServiceMix container?
> >
> > Also, this mbean is published in jmx hierarchy in
> >
> > my-host-name/290-xyroutename/processors/mybeansName
> >
> > where 290 is the bundle ID (so not static). How can I configure the mbean
> > to be registered with some specific name?
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> Make your Camel applications look hawt, try: http://hawt.io
>

Re: how to create/ publish a new JMX MBean from a Camel route (blueprint)

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If I remember you need to implement Service too for custom mbeans.
Or extend ServiceSupport.


On Fri, Mar 7, 2014 at 4:44 PM, janne mattila <fr...@gmail.com> wrote:
> I am trying to add JMX based healthcheck monitoring to my routes. I
> followed instructions from
> http://michalwarecki.blogspot.fi/2012/08/monitoring-and-managing-apache-camel.html("Custom
> MBean"). My custom MBean looks like:
>
> @ManagedResource(description = "Statictics Processor")
> public class TestMBean implements Processor {
>
>     private int totalRequests;
>
>     private int totalCharacters;
>
>     @ManagedAttribute
>     public int getAvgChar() {
>         return totalCharacters / totalRequests;
>     }
>
>     @ManagedAttribute
>     public int getTotalChar() {
>         return totalCharacters;
>     }
>
>     public void process(Exchange exchange) throws Exception {
>        ++totalRequests;
>        totalCharacters += ((String)
> exchange.getIn().getBody(String.class)).length();
>     }
> }
>
> and it has been added to my route. When I use hawtio web console to inspect
> my routes, the processor is there but it does not have the getAvgChar /
> getTotalChar operations. Only the default operations, available for all
> processors, are there.
>
> What is wrong and should I do something else completely to publish a new
> JMX MBean from a Camel route running inside ServiceMix container?
>
> Also, this mbean is published in jmx hierarchy in
>
> my-host-name/290-xyroutename/processors/mybeansName
>
> where 290 is the bundle ID (so not static). How can I configure the mbean
> to be registered with some specific name?



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io