You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by khandelwalanuj <kh...@gmail.com> on 2014/01/22 15:40:33 UTC

Current Connection Count for ActiveMQ broker

Hi,

I want to know current connection count for ActiveMQ broker. I am using
below APIs for this:
-------------------------------------------------------------------
BrokerService brokerService = getBrokerService();
connectors = brokerService.getTransportConnectors();
for (int i = 0 ; i < 3; i++)
{
    TransportConnector t = connectors .get(i);
    LOG.info("t.getConnections().size());
}
-------------------------------------------------------------------

Is this the right way or I should use some other approach ?


Thanks,
Anuj




--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Ohh. I explored a little bit and got to know this.

Does your mean by saying JMX is:

*BrokerViewMBean brokerView = (BrokerViewMBean)
getBrokerService().getManagementContext().newProxyInstance(brokerName,
BrokerViewMBean.class, true);*

and I can get transport connector by:

*brokerView.getTransportConnectors();*

and than I can get connections per transport.

Am I correct here ?

Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676743.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Ohh. I explored a little bit and got to know this.

IS your mean by saying JMX is:

*BrokerViewMBean brokerView = (BrokerViewMBean)
getBrokerService().getManagementContext().newProxyInstance(brokerName,
BrokerViewMBean.class, true);*

and I can get transport connector by:

*brokerView.getTransportConnectors();*

and than I can get connections per transport.

Am I correct here ?

Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676744.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Thanks you for the explaination



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676764.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by artnaseef <ar...@artnaseef.com>.
Thanks for the clarification on the embedded broker question.

A broker filter will do the job, as you described.

On the other hand, you could have written a tool that connects to the broker
JVM via JMX and gets the counts that way, without putting custom code into
the broker JVM.  Such a tool can be handy for grabbing all kinds of broker
statistics.

As James mentions, using jconsole or visualvm (JMX clients), are great tools
for a user to quickly and easily get the connection count from a broker.

For automated logging, a good toolset here is OpenTSDB for metrics
collection (where connection count is one metric) and jmxtrans to collect
those statistics and push into OpenTSDB, which gives powerful reporting,
such as graphs of metrics, and can be used with monitoring and alerting
tools.  Then it is possible to collect other stats of high importance with
ActiveMQ, such as average enqueue times.  Note that I would have to check if
connection count specifically can easily be obtained with that toolset.  If
not, it should be a minor enhancement, to either jmxtrans or activemq, to
obtain that stat.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676760.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by artnaseef <ar...@artnaseef.com>.
Ah, looking at the precise method of accessing the Admin View more carefully,
I recommend using BrokerService.getAdminView().

As for performance, I think once per minute is fine.  However, I recommend
measuring as there are many variables that play in.  I would try increasing
the rate (i.e. decrease the delay) until performance is notably impacted,
and then back off from there.  From there, a great picture of the
performance impact and reasonable rates is known.




--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4677281.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Thanks for the suggestions.
I cannot go ahead with the other approaches you specified because of some
reasons. 

So I just want to ask one more thing: 
If I am using plugin to get all the stats.
than is there any other way to get stats without creating
"*ManagementContext*" and "*BrokerViewMBean*". I meant to say some direct
APIs to get all the stats with creating BrokerViewMbeans ? 

And as you have specified :\
>> "It's not a heavy load on the broker unless it's being called rapidly."
How rapid you mean here. I am running this per minute. Will per minute
calling will be load on the broker ?


Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4677278.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by artnaseef <ar...@artnaseef.com>.
Ah, here's that OpenTSDBWriter:

https://github.com/donjohnson/jmxtrans/commit/3f709e34ed3260813f7fcf99605f97884978477d




--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4677149.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by artnaseef <ar...@artnaseef.com>.
Hey Anuj.

The "best" way depends on a lot of factors.  The method you posted will
work.  It's not a heavy load on the broker unless it's being called rapidly. 
I recommend measuring it to be comfortable with the overhead - a tool like
jstat or a JMX client can help you get comfortable.

My recommendation for a path is to avoid adding code to the broker and use
jmxtrans to grab the same statistics using JMX, as described earlier in the
thread.  Or, find and use a similar alternative.  Some advantages to that
route:

* no code to write
* jmxtrans can feed OpenTSDB
* jmstrans also support many other outputs (e.g. Nagios and Ganglia)
* OpenTSDB keeps metrics for a long time and makes it feasible to report on
history

jmxtrans is here: https://github.com/jmxtrans/jmxtrans.  For some reason,
the OpenTSDBWriter for jmxtrans always eludes me when I look for it.  It's
out there somewhere...

That's my idea of a better way to go.  Hope this helps.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4677148.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Please respond 



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4677144.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Hi,

I am trying to do periodic logging of ActiveMQ stats using plugin. I will
log all the stats per minutes.
 
Stats includes: enqueue count, dequeue count, dispatch count, connection
count, Producer/consumer count, Durable subscriber count and Dynamic
Destination producer count etc.

The way I am doing is by creating 
<------------------------------------------------->
*BrokerViewMBean brokerView = (BrokerViewMBean)
getBrokerService().getManagementContext().newProxyInstance(brokerName,
BrokerViewMBean.class, true);
myCurrentDurableSubscriberCount = 
brokerView.getDurableTopicSubscribers().length;
myCurrentDynamicProducerCount = 
brokerView.getDynamicDestinationProducers().length;
.
.
.
(similarly I am getting other values)

*<------------------------------------------------->


Is this the best way way to implement the requirement ? 
Are there any other getter methods available for these stats because it
looks to me a heavy operation which might bring down the broker performance
since it is creating lot of objects and strings in one call and I have to
call this every minute (for periodic logging per minute) 

Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676902.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by James Carman <ja...@carmanconsulting.com>.
Okay, but for what purpose?  What are you trying to do with this
information?

On Friday, January 24, 2014, khandelwalanuj <kh...@gmail.com>
wrote:

> I have a simple requirement where I want to log current number of
> connections
> established to the ActiveMQ broker.
>
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676752.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
I have a simple requirement where I want to log current number of connections
established to the ActiveMQ broker.

 



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676752.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by James Carman <ja...@carmanconsulting.com>.
How about you tell us what exactly it is you are trying to accomplish?

On Friday, January 24, 2014, khandelwalanuj <kh...@gmail.com>
wrote:

> I am not able to understand. Will you please tell me how to get connections
> from JMX ?
> Or what is wrong with my approach (It is working fine even if I am not
> using
> embedded broker)
>
> Thanks,
> Anuj
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676748.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
I am not able to understand. Will you please tell me how to get connections
from JMX ? 
Or what is wrong with my approach (It is working fine even if I am not using
embedded broker) 

Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676748.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by James Carman <ja...@carmanconsulting.com>.
Fire up jconsole.

On Friday, January 24, 2014, khandelwalanuj <kh...@gmail.com>
wrote:

> Hey,
>
> I don't know how to use JMX for broker. Is there any APIs of JMX I should
> use ?
>
>
> Thanks,
> Anuj
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676741.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Hey,

I don't know how to use JMX for broker. Is there any APIs of JMX I should
use ?


Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676741.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by James Carman <ja...@carmanconsulting.com>.
You don't need a plugin for that.  Use JMX.

On Friday, January 24, 2014, khandelwalanuj <kh...@gmail.com>
wrote:

> I think little bit confusion here; let me elaborate:
>
> I am running ActiveMQ broker as a separate java process. And clients are
> connecting from different hosts and client have different java process and
> connecting to the broker using transport connectors (TCP).
>
> I am using this code in my own broker plugin to get the current number of
> connections made to the broker from clients. This code is giving me the
> correct values.
>
>
> Please correct me if I am wrong.
>
> Thanks,
> Anuj
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676729.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
I think little bit confusion here; let me elaborate:

I am running ActiveMQ broker as a separate java process. And clients are
connecting from different hosts and client have different java process and
connecting to the broker using transport connectors (TCP).

I am using this code in my own broker plugin to get the current number of
connections made to the broker from clients. This code is giving me the
correct values.


Please correct me if I am wrong.

Thanks,
Anuj




--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676729.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by artnaseef <ar...@artnaseef.com>.
An embedded broker is a broker in the same JVM process.

It's not possible for the code posted to give connection counts for a broker
in another JVM as the code  is walking the internal data structures of the
broker, which are only accessible from the same JVM (unless some debugging
magic is also involved).




--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676726.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by khandelwalanuj <kh...@gmail.com>.
Hi,

I think here you mean embedded broker by "broker in the same java process as
clients" ? 

I have access to the broker's API. 
But I am *not using *embedded broker. I am using broker in a different java
process and clients are connecting from other places. But still this API is
showing the correct values.  

I am not able to understand why did you say "embedded broker" here ?  
Please correct me if I ma wrong.

Thanks,
Anuj



--
View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635p4676694.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Current Connection Count for ActiveMQ broker

Posted by Christian Posta <ch...@gmail.com>.
Sure, that's one way if you're using an embedded broker and have
direct access to the broker's API.

You could also use JMX to query the stats.

You could also subscribe to the connection advisory topic and count
how many messages about started connections you get back.

On Wed, Jan 22, 2014 at 7:40 AM, khandelwalanuj
<kh...@gmail.com> wrote:
> Hi,
>
> I want to know current connection count for ActiveMQ broker. I am using
> below APIs for this:
> -------------------------------------------------------------------
> BrokerService brokerService = getBrokerService();
> connectors = brokerService.getTransportConnectors();
> for (int i = 0 ; i < 3; i++)
> {
>     TransportConnector t = connectors .get(i);
>     LOG.info("t.getConnections().size());
> }
> -------------------------------------------------------------------
>
> Is this the right way or I should use some other approach ?
>
>
> Thanks,
> Anuj
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Current-Connection-Count-for-ActiveMQ-broker-tp4676635.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.



-- 
Christian Posta
http://www.christianposta.com/blog
twitter: @christianposta