Remote monitoring Tomcat Jboss/apache

Source: Internet
Author: User
Tags stub jboss jboss server jconsole

In the%jboss_home%/bin/run.sh file

java_opts= "$JAVA _opts-dprogram.name= $PROGNAME"

Modified to:

java_opts= "$JAVA _opts-dprogram.name= $PROGNAME-dcom.sun.management.jmxremote.port=9999- Dcom.sun.management.jmxremote.authenticate=false-dcom.sun.management.jmxremote.ssl=false "


#-djava.rmi.server.hostname=192.168.2.2 #this must is added for TOMACAT6


For Tomcat ... find #Execut the requested Command in catalina.sh file.




Remote monitoring can be achieved in Jconsole:
Remote Process 192.168.10.31:8950
or Service:jmx:rmi:///jndi/rmi://192.168.10.31:8950/jmxrmi




Note: 9999 indicates the monitored port number, ensures that the specified ports are not occupied, can use Netstat-an to view the ports that are already occupied, and lsof-i:portnum to view the specific applications that occupy the ports, and if firewall services are turned on, Make sure the port is accessible through the firewall; start the JBoss server

./run.sh-b192.168.1.5, the address to which the JBoss server is bound must be specified through the-b parameter (not required ...). Look at the configuration of each server)


Add Jar:

Jbossall-client.jar


Public Mbeanserverconnection Getremotembconn () {

try{
Mbeanserverconnection Mbs=null;
Registry registry=locateregistry.getregistry (IP, Integer.parseint (port));
Rmiserver Stub=null;
Jmxconnector Jmxc=null;
if (stub = null) {
stub = (rmiserver) registry.lookup ("Jmxrmi");
}
JMXC = new Rmiconnector (stub, null);
Jmxc.connect ();
Mbs=jmxc.getmbeanserverconnection ();
return MBS;
catch (Exception e) {
E.printstacktrace ();
}
return null;

}



Main:

Remotemonitor re = new Remotemonitor ("192.168.2.2", "9898");
Mbeanserverconnection rm = Re.getremotembconn ();
ObjectName name;
name = new ObjectName ("Jboss.ws:service=serviceendpointmanager");
System.out.println ("JBoss Host IP =" + re.getip ());
SYSTEM.OUT.PRINTLN ("Host name =" + Rm.getattribute (name, "Webservicehost"));
System.out.println ("HTTP port =" + Rm.getattribute (name, "Webserviceport"));
System.out.println ("Monitor port =" + Re.getlinkport ());


name = new ObjectName ("java.lang:type=threading");
SYSTEM.OUT.PRINTLN ("total number of threads =" + Rm.getattribute (name, "Totalstartedthreadcount"));
System.out.println ("number of active threads =" + Rm.getattribute (name, "ThreadCount"));
System.out.println ("Number of daemons =" + Rm.getattribute (name, "Daemonthreadcount"));


------------------------JVM-------------------------
Heap Use rate
ObjectName heapobjname = new ObjectName ("java.lang:type=memory");
Memoryusage heapmemoryusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (HeapObjName, "heapMemoryUsage "));
Long maxmemory = Heapmemoryusage.getmax ();//Heap Max
Long commitmemory = heapmemoryusage.getcommitted ();//heap Current allocation
Long usedmemory = heapmemoryusage.getused ();
System.out.println ("Heap Maximum value:" + maxmemory);
System.out.println ("Allocated heap:" + commitmemory);
System.out.println ("used heap:" + usedmemory);
System.out.println ("Heap Usage:" + (Double) usedmemory/commitmemory * 100 + "%");//Heap usage
System.out.println ();


Memoryusage nonheapmemoryusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (HeapObjName, " Nonheapmemoryusage "));
Long nonmaxmemory = Nonheapmemoryusage.getmax ();
Long noncommitmemory = nonheapmemoryusage.getcommitted ();
Long nonusedmemory = nonheapmemoryusage.getused ();
System.out.println ("Not heap Maximum:" + nonmaxmemory);
SYSTEM.OUT.PRINTLN ("Allocated Non-heap:" + noncommitmemory);
SYSTEM.OUT.PRINTLN ("Used not heap:" + nonusedmemory);
SYSTEM.OUT.PRINTLN ("Non-heap use rate:" + (Double) nonusedmemory/noncommitmemory * 100 + "%");
System.out.println ();


ObjectName permobjname = new ObjectName ("Java.lang:type=memorypool,name=ps Perm Gen");
if (permobjname!= null) {//only hotspot only
Memoryusage permgenusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (Permobjname, "Usage"));
Long max = Permgenusage.getmax ();
Long committed = permgenusage.getcommitted ();
Long used = permgenusage.getused ();
System.out.println ("Persistent generation Maximum:" + max);
System.out.println ("Allocated persistent generation:" + committed);
System.out.println ("has used persistent generation:" + used);
System.out.println ("Persistent generation heap Utilization:" + (Double) used/committed * 100 + "%");
System.out.println ();
}

ObjectName oldobjname = new ObjectName ("Java.lang:type=memorypool,name=ps old Gen");
Memoryusage oldgenusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (Oldobjname, "Usage"));
Long max1 = Oldgenusage.getmax ();
Long committed1 = oldgenusage.getcommitted ();
Long used1 = oldgenusage.getused ();//
System.out.println ("Old age Max:" + max1);
System.out.println ("Old age Allocated:" + committed1);
System.out.println ("Used old Age:" + used1);
System.out.println ("old age heap utilization Rate:" + (Double) used1/committed1 * 100 + "%");
System.out.println ();

ObjectName edenobjname = new ObjectName ("Java.lang:type=memorypool,name=ps Eden space");
Memoryusage edengenusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (Edenobjname, "Usage"));
Long max2 = Edengenusage.getmax ();
Long committed2 = edengenusage.getcommitted ();
Long used2 = edengenusage.getused ();//
System.out.println ("The greatest value of the New Generation Eden region:" + max2);
System.out.println ("The New Generation of Eden Area:" + committed2);
System.out.println ("has used the Cenozoic Eden area:" + used2);//byte
System.out.println ("The New Generation Eden Area heap utilization Rate:" + (Double) used2/committed2 * 100 + "%");
System.out.println ();

ObjectName survivorobjname = new ObjectName ("Java.lang:type=memorypool,name=ps Survivor space");
Memoryusage survivorgenusage = Memoryusage.from ((compositedatasupport) Rm.getattribute (SurvivorObjName, "Usage"));
Long max3 = Survivorgenusage.getmax ();
Long committed3 = survivorgenusage.getcommitted ();
Long used3 = survivorgenusage.getused ();//
System.out.println ("Cenozoic Survivor Region Maximum:" + max3);
System.out.println ("The New Generation Survivor region:" + committed3);
System.out.println ("has used the Cenozoic Survivor area:" + used3);//byte
System.out.println ("Cenozoic Survivor Area heap utilization Rate:" + (Double) used3/committed3 * 100 + "%");
System.out.println ();



Configure JMX access password

1. Modify the Java_opt parameter in the Catalina script above to
-dcom.sun.management.jmxremote.authenticate= "false" is modified to:
-dcom.sun.management.jmxremote.authenticate= "true"

2. Copy the $jre/lib/management/jmxremote.password.template file in the same directory and rename it to $jre/lib/management/ Jmxremote.password, edit Jmxremote.password, add a user name and password to allow access, such as adding a user zxwh, the password is zxme, then add a line at the end of the file:
ZXWH Zxme
Note that the user password cannot contain spaces, tab, and other characters

3. Edit the $jre_home/lib/management/jmxremote.access file to give certain permissions to the user you just added:
ZXWH readonly (or ReadWrite)

4. Verify that the users in Jmxremote.password and jmxremote.access two files are the same. Note that the configuration is invalid if there is no corresponding user in the jmxremote.access.
Note: The location of the above configuration file can be changed, the specific configuration method here no longer repeat.

5. Because passwords in Jmxremote.password are stored in plaintext, Jmxremote.password, The permissions of the Jmxremote.access file should be set to only owner-readable, and of course the user must be the user who started Tomcat.

6. Start the Jconsole to connect and enter the user and password at the user name and password.

7. Using a Password authentication method to connect can not only improve security, but also set the user's permissions. If you do not use a password authentication method, you cannot restrict the permissions of the user.








Apache:

httpd.conf

Extendedstatus on

<location/server-status>

SetHandler Server-status

Order Allow,deny

Allow from all

</location>


Http://192.168.2.8/server-status




Monitor Tomcat Another way:

In Tomcat-users.xml

<role rolename= "Manager-gui"/> <user username= "manager" password= "1234" roles= "Manager-gui"/>

Then use Shell to get status from Tomcat ...







#!/bin/sh
#$1:port; $2:user; $3:psword; $4:infoparam;
#stty-echo
Status_addr= "Http://localhost:$1/manager/status?xml=true"
User= "$"
Pass= "$"
# sample Rate, Default:5seconds
Sample_rate=5
# if Press ' CTRL + C ', stop monitor
exit_signal=2
# Connector to monitor
Connector= "Http-$1"
# result directory to store data
result_dir= "/tmp"
# Perf Data File
Perf_data= "Perf_data"
# JVM Data File
Jvm_data= "Jvm_data"
# Connector Data file
Connector_data= "Connector_data"
# Thread data File
Thread_data= "Thread_data"
# Request data File
Request_data= "Request_data"
# ===========================output Error message========================
# Show the Error message and exit, get one parameter
ErrorMsg ()
{
if [[$#-eq 1]]; Then
echo "Runtime Error: $"
Exit 1
Else
echo "Function Error: $"
Exit 127
Fi
}
If [$# LT 4]; Then
echo "Miss Args"
Exit 1
Fi
# #freejvm TOTALJVM MAXJVM maxthreads currentthread busythread maxtime processingtime requestcount errorcount Bytesreceived BytesSent
wget--http-user= "$USER"--http-password= "$PASS" "$STATUS _addr"-O "$PERF _data" | | ErrorMsg "Failed to get data, please check the connection"
Case $ in
FREEJVM)
Sed ' s/.*<jvm>//g;s/<\/jvm>.*//g ' $PERF _data | Awk-f \ ' {print $} '
;;
TOTALJVM)
Sed ' s/.*<jvm>//g;s/<\/jvm>.*//g ' $PERF _data | Awk-f \ ' {print $} '
;;
MAXJVM)
Sed ' s/.*<jvm>//g;s/<\/jvm>.*//g ' $PERF _data | Awk-f \ ' {print $} '
;;
MaxThreads)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<threadinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr<2{print $} '
;;
CurrentThread)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<threadinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
Busythread)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<threadinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
MaxTime)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr<2{print $} '
;;
Processingtime)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
RequestCount)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
Errorcount)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
bytesreceived)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;
BytesSent)
Sed ' s/.* ' $CONNECTOR '. >//g;s/<\/connector>.*//g ' $PERF _data >> $CONNECTOR _data
Sed ' s/.*<requestinfo//g;s/\/>.*//g ' $CONNECTOR _data | awk-f \ "' Nr==2{print $} '
;;

Esac




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.