Pages

Showing posts with label Tools. Show all posts
Showing posts with label Tools. Show all posts

Wednesday, May 7, 2014

Salt Stack – a Infrastructure management tool

Managing infrastructure is always complex when dealing with large number of systems and high speed communication between them is always a problem. So what is a “salt Stack?”.

Consider we have a couple of machines that we manage. If we need perform  a couple of operations on them like patching , or perform some command execution on these machine we need to login to each and every machine and then do the appropriate action on them . But what if the machines we handle are large ( may be more than 1000 ) . Managing them is always complex.

Salt Stack comes in here. The salt Stack is a configuration management tool which helps the administrators in performing these sort of operations very easily. Salt Stack also provides us with high speed communications between the infrastructures.

We have other tools like puppet and chef which provide us the same facilities. What makes Salt different is that it is written in Phyton and is light-weight as far as resources and requirements. The implementation is also very simple. Salt uses “ZeroMQ” in its communication layer which is really fast.

All the above tools allow us to perform command executions on multiple machines at once, install and configure software etc.

In this article we will see how we can configure and use salt Stack to perform remote execution. For the article purpose I will use only one system as both master and slave. We can also configure multiple machines and use them as slaves.

One important thing is that Salt tool is a command line tool.

Installation & Configuration

Installing salt is very easy. The salt documentation tells us ways to install salt on various distributions. Check the installation docs ( http://docs.saltstack.com/en/latest/topics/installation/index.html )  on how to install salt on RHEL.

On RHEL, execute


and get the packages necessary for the installation.

Once the packages are available and installed, we can now see a configuration directory in /etc/salt. This location contains 2 files “master” and “minion”.

Now once the files are available, we need to fist do some configuration changes to both the files. The terms master and minion are commonly referred to the controller and the controlled. The master is the center controller for all the minions running. This is much like a master-slave configuration.

Once we confirm these files are available, execute the command “salt-master“ and keep it running in the back ground. lets configure minion.

The first thing we need to configure is a way for minion ( slave ) to communicate with the master. This can be configured in minion configuration file ,
Here are the changes that we need to do in the minion configuration file, uncomment these lines and provide the necessary date,

master: 172.16.101.68 <IP address of the master system >
id: testminion  <Name of the minion >

Once the changes are done , save them and restart the minion using “salt-minion –d” command. The –d flag demonizes the process and starts the minion in the back ground.

The next step is to accept the minion keys. From the above configuration the minion knows where the master is. Salt uses public key encryption to secure the communication between master and minion. We need to notify the master and minion that they can trust each other by accepting minion keys on the master.

[root@vx111a salt]# salt-key -L
Accepted Keys:
Unaccepted Keys:
testminion
Rejected Keys:

Use the “salt-key –L” command to get a list of all pending , accepting and rejected minions information. When I ran the command I see that there is unaccepted keys from testminion which we configured as a minion in our article.

For accepting testminion keys , execute “salt-key -a testminion

[root@vx111a salt]# salt-key -a testminion
The following keys are going to be accepted:
Unaccepted Keys:
testminion
Proceed? [n/Y] y
Key for minion testminion accepted.

Once we accept the keys we can now test the communication using “salt '*' test.ping

[root@vx111a salt]# salt '*' test.ping
testminion:
    True

We can use the command “salt ‘*’ test.ping” to test all the available minions. The wild-card “*” targets every minion and since we have only one minion “testminion” , it gets the status of that. The response is “True” saying that the communication is happened successfully.

The salt command contains the command , targets and action. Now if we want to execute a command on a available minions we can use

Salt ‘*’ cmd.run “service httpd restart”
Salt ‘*’ cmd.run “uptime”

All the commands should be available on minions. In the above case, the httpd should be available if we run the restart command on that. In the next article, we will see the salt stack configuration management options.

Happy Learning, More to come.
Read More

Wednesday, November 27, 2013

Wire Shark : Packet Capturing Tool

Wire-shark is a network analysis tool which captures network packets in real time. They are captured in human readable format. The tool is formally called as Ethereal.

Wire-shark includes filters, color indicators and many other features that lets admin to dig into the network traffic and see what’s going on

This article is a brief introduction of how wire-shark is installed and how one can use to dig the network details.

1. Install the package.
In order to install the Wire-shark package, go to http://www.wireshark.org/download.html  

Select the Correct packages for the installation. I will be explaining how to build the wire-shark in Red hat Linux 6.

Download the Source Code and unzip it a location and execute
yum install bison flex gtk2-devel libpcap-devel c-ares-devel libsmi-devel gnutls-devel libgcrypt-devel krb5-devel GeoIP-devel ortp-devel portaudio-devel*

Linux then tries to install the packages which are dependent for wire-shark

2.Once the packages are installed ,run the following commands
cd wireshark-1.8.11
./autogen.sh
 ./configure --enable-setcap-install
 make
 make install
 wireshark &

If everything goes fine, we can now see the Wire-shark console on the screen.


3. Start Using Wire-Shark

 We can see the Interfaces that are available in our system under the Interface list. Under the Start
Click on the Interface, in this case consider “eth0”.Once we click the interface it starts capturing packets on that interface.

As soon as you click the interface’s name, you’ll see the packets start to appear in real time. Wireshark captures each packet sent to or from your system. It captures all sorts of packets on tcp,udp,http and many more.


Click the stop capture button near the top left corner of the window when you want to stop capturing traffic.

Wire-shark follows colors to represent different information from the above screen. We can see packets highlighted in green, blue and black. Wire-shark uses colors to help you identify the types of traffic at a glance. By default, green is TCP traffic, dark blue is DNS traffic, light blue is UDP traffic and black identifies TCP packets with problems — for example, they could have been delivered out-of-order.

Wire-shark can also allow us to filter packet information based on criteria. We can use the filter option available on the top to select the packet information like



Wire-shark also provides options to select filter. Click on the Analyze menu and select Display Filters to create a new filter.Select the Filter you want to analyze packet information for.

















Another important feature with wire-shark is that it allows you to follow the Packet Stream.
Just right click on a packet and select “Follow TCP Stream” or “Follow UDP Stream”. We can get more information like the full conversation between Client and Server in this request.


Close the window and you’ll find a filter has been applied automatically — Wire shark is showing you the packets that make up the conversation.

We can also inspect packet information by just right clicking on the packet and selecting “view its Details”.

This article is basically an introduction for wire shark.I will be providing more details on the usage of this tool

Happy learning, more To Come J
Read More

Monday, June 3, 2013

Eclipse Memory Analyzer

Analyzing Memory Structure in Java is always Challenging. As a Application Server admin , I use certain tools to find the memory usage of a Server.

Eclipse Memory Analyzer is one such tool which provides a clear understanding of the memory usage in a Java process. In this article we will see the basics of the Eclipse Memory Analyzer and its uses. Eclipse Memory Analyzer is useful for both tracking memory leaks and for periodically reviewing the state of your system.

Getting the Memory Dump

A JVM heap dump is basically a “snapshot” of the Java heap memory at a given time. It is quite different than a JVM thread dump which is a snapshot of the threads.

Generating a Heap Dump can be done by using the “jmap” command available in the java software.

jmap -dump:format=b,file=heap.hprof JAVA_PID

For Oracle Jrocket we can use
jrcmd <JAVA_PID> hprofdump filename=abc.hprof

So Consider generating a heap Dump Files for the Process ID 22979.
Dev:vx1111:jbs002-jas $ jmap -dump:file=my_stack.bin 22979
Dumping heap to /config/jboss/ews/1.0/domains/jas/my_stack.bin ...
Heap dump file created

It’s easy to get an OutOfMememory exception when opening the java heap. The dump file can be very memory consuming if you application was in the moment it was taken. If you experience the problem you should give to the JVM as much memory as you can:
Most of the times the heap dumps are generated with the .hprof extension.

What is HProf?
HProf is a tool built into JDK for profiling the CPU and heap usage within a JVM. A Java process crash may produce an hprof file containing a heap dump of the process at the time of the failure.
So Once the Heap Dump is generated we need to analyze the file

Typical information which can be found in heap dumps (once more - depending on the heap dump type) is:

All Objects
Class, fields, primitive values and references

All Classes
Classloader, name, super class, static fields

Garbage Collection Roots
Objects defined to be reachable by the JVM

Thread Stacks and Local Variables
The call-stacks of threads at the moment of the snapshot, and per-frame information about local objects

A heap dump does not contain allocation information so it cannot resolve questions like who had created the objects and where they have been created.

Details
















When We open the heap dump file using the Memory Analyzer . the Pie Chart shows you the biggest objects. When we click on the areas in Pie Chart , we can see the classes which are taking more usage. This means that if we were able to eliminate the high usage of “java.lang.ref.Finalizer” , we can eliminate 5.4mb of the usage.

Click on the “Leak Suspects” to obtain information about the leak suspects and also about the System


The “Leak Suspects” tells you about the classes that can cause issues and are considered as Suspects for leaking memory. The Memory analyzer displays the couple of Problem Suspects along with the amount of memory they occupy.

Click on the “Table of Contents” below to get more information about the System. The Details include




From this , we can obtain various levels of information including , Heap Dump Overview, thread details, System properties and Top Consumers of Memory e.t.c.

Histogram : Using Histogram we can list the number of instances per class, the shallow size and the retained size .






















The Histogram also shows the number of instances of a particular class and how much memory each one uses.

We can also use the histogram in grouping .We can group by Class,Class loader , Super class and also package.









The Histogram has also a filtered Option by which we can filter the classes accordingly. we can search for specific class like








We can see how many of the classes are loaded from the “com” package structure along with the number of them loaded and also classes.

The amount of memory each object is using can also be viewed.

As you can see there are 2 calculations Shallow Heap and Retained heap.

Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.

Shallow size of an object is the amount of allocated memory to store the object itself, not taking into account the referenced objects

Retained size of an object is its shallow size plus the shallow sizes of the objects that are accessible, directly or indirectly, only from this object. In other words, the retained size represents the amount of memory that will be freed by the garbage collector when this object is collected

Dead objects are shown only with shallow size, as they do not actually retain any other objects.

Generally speaking, shallow size of an object is its "flat" size in the heap whereas the retained size of the same object is the amount of heap memory that will be freed when the object is garbage collected.

For example the shallow size of an instance of java.lang.String will not include the memory needed for the underlying char[].

From Eclipse Documentation
The following diagram represents objects in the Java heap. Objects A and B are garbage collection roots, for example method parameters, locally created objects, or objects that are used for wait(), notify(), or synchronized() methods. The set of objects A and B has a retained set consisting of objects A, B, C, D, E, F, G, and H.












If, for example, object G was referenced by a garbage collection root other than A or B, then object G would remain if objects A and B were removed during garbage collection. Object G would therefore not be in the retained set of objects A and B.

Retained heap, or retained size

The total heap size of all the objects in the retained set. This value is the amount of memory that is consumed by all the objects that are kept alive by the objects at the root of the retained set.
In general terms, the shallow heap of an object is the size of the object in the heap. The retained size of the same object is the amount of heap memory that is freed when the object is garbage collected.

As an Example , if an ArrayList held 100 items, and each item required 16 bytes, then removing the ArrayList would free 16 x 100 + X, where X is the shallow size of the ArrayList.

 


We can see that “java.lang.Class” has more usage with each object taking 57.664 bytes.

This can also be read as , the java.lang.Class in heap dump has exactly 6036 times in memory and has more than >=8004,320 bytes occupied in memory.

Find Duplicate Classes:We can Find the Duplicate Classes being loaded by following ,










And We can see the Duplicate classes like




















The dominator tree

The dominator tree is a data structure that allows you to answer the question about the biggest objects in almost no time

jmap -dump:live,format=b,file=dump.hprof <PID>

To determine who is creating these objects, or find out what the purpose of some structures is, the actual instances with their incoming and outgoing references are required. To get them, choose List Objects with incoming References from the context menu. Now a tree structure is displayed, showing all instances with all incoming references. Those references keep the object alive and prevented them from being garbage collected

Outgoing References are interesting as well, because they show the actual contents of the instances

The dominator tree allows you to identify the largest memory graphs.

Top Consumers

Click on the Top Consumers  from which we can get information about the top Consumers which are  expensive objects grouped by class and by package like












We can Get the Same thing using 













Top Components
Click on the Top Components from which we can get information about the top Consumers which are bigger than 1% of the heap like











When You  Click the “Table Of Contents” below this ,we can find various other Information like

Duplicate String






Information about Empty Collections,Collection Fill Ratios,Soft References,Weak References,Finalizer Statistics and Map Collision Ratios Can be Obtianed by using memory Analyzer.













Immediate Dominators
The Immediate Dominators are very useful to quickly find out who is responsible for a set of objects,as it directly answers the question "who Keeps the Objects alive"





















Once you select the Immediate Dominators , we can see this screen which allows us to enter a pattern which can be ignored while searching . IN the below case , iam skipping java.* and some other making sure only the application related classes are seen





















Querying Heap Objects

Mat Provides a way to Query Heap Objects using QQL Like



















You can see the Rectangle from where you can start the OOL Query Browser

Class Loader Information

Class Loader information is very important since they are the pieces which load objects.
From the Histogram we can 












Next to the class loader name, the table contains the defined classes and the number of live instances. If one and the same component is loaded multiple times, the number of live instances can indicate which class loaders is more alive and which one should be garbage collected.

Thread Details

















You can enter the Query or Thread ID that you need to see.Now from the below image the Thread Ids that belong to com.* will be shown.


















GC Roots : The so-called GC (Garbage Collector) roots are objects special for garbage collector. Garbage collector collects those objects that are not GC roots and are not accessible by references from GC roots.

One object can belong to more than one kind of root. The root kinds are:

Class - class loaded by system class loader. Such classes can never be unloaded. They can hold objects via static fields. Please note that classes loaded by custom class loaders are not roots, unless corresponding instances of java.lang.Class happen to be roots of other kind(s).

Thread - live thread
Stack Local - local variable or parameter of Java method
JNI Local - local variable or parameter of JNI method
JNI Global - global JNI reference
Monitor Used - objects used as a monitor for synchronization

Sample Class For generating OOM 
package com.sample;

import java.util.ArrayList;
import java.util.List;

public class Main {
 public static void main(final String... args) {
 System.out.println("start");
 List<Integer> numbers = new ArrayList<Integer>();
 for (int i = 0; i <= Integer.MAX_VALUE; i++) { // going to fail
 numbers.add(i);
 }
 System.out.println("stop");
 }
}

java -Xmx10M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heap.bin -jar outofmemory.jar start

Much More To Come , Happy learning :-)
Read More