Tuesday, June 7, 2016

Retrans Percent

Today , I had an interesting issue with the TCP UDP stats and Retrans problem with one of the Active MQ brokers.

The context of the problem is :  Whenever external monitoring tools to find out the status of brokers , they are returning with the no data as a value for ceratin data points. The data point is Retrans Percent and it is 23% which is super high.

Still investigating the issue of high in Retrans percent but in the meantime what is causing this issue ?

TCP retransmissions are usually due to network congestion. Look for a large number of broadcast packets at the time the issue occurs. If the percentage of broadcast traffic in your capture is above about 3% of the total traffic captured, then you definitely have congestion. Look for both physical layer (ARP) and network layer (name resolution) broadcasts on the network. If you find a high volume of broadcast traffic you can trace it to the source from the capture data.

The above paragraph make more sense in case of Network congestion so the solution is fixing the network traffic or making the right inetrval from your external monitor tool to track on the brokers.

Real Encapsulation

There are OOPS concepts in java which needs to be looked into much more deeply on how they are making difference in software development with in the object world.

There are like things Inheritance , Polymorphism and Encapsulation . The interesting part is with the encapsulation since we are dealing with the object states. The object states refers to something where the object got constructed and having so and so default behaviors or properties to be initialized while constructing the object .

So why we need to worry about the object states and where the polymorphism is coming into place ?

In a plain english we are hiding somethings in our home in a safe locker or whatever to protect or hide from the bad people around around the world ..:)

The same way object once created , it should serve the purpose what it is supposed to but not the additional behavior like giving flexibility to the client to change the object behavior according to the client needs. Encapsulation is like a thing where it encapsules or protects or a kind of layer on top of objects data or state.

But it has some cons too , if you won't implement properly ..:)

Here is the good link where you can follow this one to achieve the right implementation of encapsulation.

https://dzone.com/articles/encapsulation-i-dont-think-it-means-what-you-think..

Enjoy Encapsulation ..:)

Wednesday, June 1, 2016

Logic Monitor integration with the REST Service as a Datasource

REST Service as a Datasource for Logic Monitor :

Currently the logic monitor is the tool which is trending a lot in case of Infrastructure log and status management. Usually in LM there is a way to add datasources for different endpoints but we experienced a situation where we have to call the external endpoint which is REST API to get the metrics of the cassandra servers. I  will be creating the datasource where it can consume the REST API in order to display the metrics data in the dashboards and alert services.

Th typical situation is converting the JSON  data to meaningful data where we can pull out the charts from those . So for this we have to make use of LM  JSON parsing mechanisms to do so.


Coming Soon ..!!!

Custom Plugin for Active MQ and Exposing as a JMX MBean.

Active Mq Custom Plugin as a JMX MBean :

The use of plugin approach in Active MQ which allows the  clients to levarage the broker services and make use of different methods with in the Broker object and many others.

We will see how it really helps in getting some custom metrics even those metrics are not exposed as an Mbean. We will write the custom plugin and will expose this custom plugin as Mbean .

We all require is the current version Active MQ distribution , Please find it here.

http://activemq.apache.org/download.html

Once you are done with the downloading and start running the activemq. To start activemq , please go to the bin folder and run the command ./activemq start on MAC but on windows you can just use activemq start. Once you started the activemq you should be able to see the admin console using this URL :

http://localhost:8161/admin . Please use admin / admin as user name and password to get on to the console. You will see the below console ...if everything runs as expected.

Active MQ Console


So once the Active MQ is running on your machine , We need to identify what MBeans are exposed in the Active MQ broker.You can see the below screen shot where it shows all the active mq mbeans got exposed through jconsole.
Jconsole with the exposed Active MQ Mbeans.

So now we are going to write a custom plugin where this plugin is not a plain old activemq plugin but it also serves as an mbean where we can get the required data.

To develop a custom active mq plugin we have to start with the class implementing the broker plugin as a factory class in which where we can provide the body for the install plugin method . The install plugin method you need to override where you can invoke the Mbean Implenatation which extends the broker filter.

Here is what sample Broker plugin looks like :


public class IPAuthenticationPlugin implements BrokerPlugin{

  public Broker installPlugin(Broker broker) throws Exception {
  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    // Construct the ObjectName for the Hello MBean we will register
    ObjectName mbeanName = new ObjectName("com.test:type=Hello");
    // Create the Hello World MBean
    IPAuth ipAuth = new IPAuthenticationBroker(broker);
    StandardMBean mbean = new StandardMBean(ipAuth, IPAuth.class);
    // Register the Hello World MBean
    mbs.registerMBean(mbean, mbeanName);
    return (Broker)ipAuth;
  }

IPAuth is an mbean interface where it contains the only one method called getSessionCount(). It looks like this :

public interface IPAuth {

public int getSessionCount();
}

and coming to the actual IPAuthenticationBroker where it extends the broker filter and implements the Mbean. My Mbean interface is IpAuth and impl class is IPAuthenticationBroker.

It looks like :


public class IPAuthenticationBroker extends BrokerFilter implements IPAuth {

public IPAuthenticationBroker(Broker next) {
super(next);
}

public int getSessionCount() {
RegionBroker rb = null;
try {
rb = (RegionBroker) getBrokerService().getBroker().getAdaptor(RegionBroker.class);
} catch (Exception e) {
e.printStackTrace();
}
Map<ConnectionId, ConnectionState> connStates = rb.getConnectionStates();
Iterator it = connStates.entrySet().iterator();
int totalCount = 0; 
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
ConnectionState connectionState = (ConnectionState) pair.getValue();
totalCount += connectionState.getSessionStates().size();
System.out.println(pair.getKey() + " = " + pair.getValue());
}
return totalCount;
}

Once you create all the above class , please make sure that you expose this project as a jar and place it in the active mq lib folder. Once you placed that you can include this plugin in the active mq xml file to make sure it loads up this plugin while it starts up.

 <plugins>
    <bean id="ipAuthenticationPlugin" class="com.test.plugin.broker.IPAuthenticationPlugin" xmlns="http://www.springframework.org/schema/beans">

    </bean>
  </plugins>

So now when you start the activemq broker , then you can go to jconsole and look for the session count : 


Please start the producer and consumer in your local machine to test this count . Create a sample queue , write a junit or simple java class where you can publish and consume at a time and then you can find the session count as 2.

Will place the code in github.