Commit 745d8cce by liuyongshuai

修改完善weblogic的监测方法

parent ea6450ab
package com.cc.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j;
/**
* Created by liuys on 2018/11/20.
*/
@Data
@Log4j
@NoArgsConstructor
@AllArgsConstructor
public class JDBCEntity {
private String ServiceName;
private String name;
private String state;
private String versionJDBCDriver;
private Integer maxCapacity;
private Integer activeConnectionsCurrentCount;
//历史最大活跃数
private Integer activeConnectionsHighCount;
//当前连接数
private Integer currCapacity;
//活动连接平均数
private Integer activeConnectionsAverageCount;
//池内空闲连接数
private Integer numAvailable;
//历史最大连接数
private Integer highestNumUnavailable;
//泄漏的连接数
private Integer leakedConnectionCount;
//失败重新连接数
private Integer failuresToReconnectCount;
//返回当前等待连接的总数 WaitingForConnectionCurrentCount
private Integer waitingForConnectionCurrentCount;
}
package com.cc.serviceutil; package com.cc.serviceutil;
import com.cc.bean.JVMEntity; import com.cc.bean.*;
import com.cc.bean.ProgramEntity;
import com.cc.bean.ThreadEntity;
import weblogic.health.HealthState; import weblogic.health.HealthState;
import javax.management.*; import javax.management.*;
...@@ -15,8 +13,10 @@ import java.net.MalformedURLException; ...@@ -15,8 +13,10 @@ import java.net.MalformedURLException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
public class Finalweblogicmonit { public class Finalweblogicmonit {
...@@ -40,7 +40,7 @@ FileOutputStream fos = null; ...@@ -40,7 +40,7 @@ FileOutputStream fos = null;
* @throws MalformedObjectNameException * @throws MalformedObjectNameException
*/ */
public static void initConnection(String hostname, String portString,String username, String password) throws IOException, public static void initConnection(String hostname, String portString,String username, String password) throws IOException,
MalformedURLException, MalformedObjectNameException { MalformedObjectNameException {
String protocol = "t3"; String protocol = "t3";
Finalweblogicmonit.hostname=hostname; Finalweblogicmonit.hostname=hostname;
Finalweblogicmonit.portString=portString; Finalweblogicmonit.portString=portString;
...@@ -198,7 +198,7 @@ public void getExecuteQueueRuntimes(ObjectName serverRuntime) ...@@ -198,7 +198,7 @@ public void getExecuteQueueRuntimes(ObjectName serverRuntime)
* @throws ReflectionException * @throws ReflectionException
* @throws IOException * @throws IOException
*/ */
public void getJDBCDataSourceRuntime(ObjectName serverRuntime) public List<JDBCEntity> getJDBCDataSourceRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException, throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException { MBeanException, ReflectionException, IOException {
// JDBC运行时 JDBCServiceRuntime // JDBC运行时 JDBCServiceRuntime
...@@ -216,6 +216,8 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime) ...@@ -216,6 +216,8 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
ObjectName objJdbcResource = null; ObjectName objJdbcResource = null;
ObjectName objPoolPrms = null; ObjectName objPoolPrms = null;
List<JDBCEntity> list = new ArrayList<JDBCEntity>();
for (int i = 0; i < jdbcDataSourceRuntimeMBeans.length; i++) { for (int i = 0; i < jdbcDataSourceRuntimeMBeans.length; i++) {
ObjectName jdbcDataSourceRuntimeMBean = jdbcDataSourceRuntimeMBeans[i]; ObjectName jdbcDataSourceRuntimeMBean = jdbcDataSourceRuntimeMBeans[i];
// 判断JDBCSystemResources对象是否为null // 判断JDBCSystemResources对象是否为null
...@@ -255,8 +257,23 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime) ...@@ -255,8 +257,23 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
// 部署状态 DeploymentState // 部署状态 DeploymentState
Integer deploymentState = getAttribute(jdbcDataSourceRuntimeMBean, Integer deploymentState = getAttribute(jdbcDataSourceRuntimeMBean,
"DeploymentState"); "DeploymentState");
JDBCEntity jdbcEntity = new JDBCEntity();
sb.append("<td>" + hostname+":"+portString+"</td>"+
jdbcEntity.setServiceName(hostname+":"+portString);
jdbcEntity.setName(name);
jdbcEntity.setState(state);
jdbcEntity.setVersionJDBCDriver(versionJDBCDriver);
jdbcEntity.setMaxCapacity(maxCapacity);
jdbcEntity.setActiveConnectionsCurrentCount(activeConnectionsCurrentCount);
jdbcEntity.setActiveConnectionsHighCount(activeConnectionsHighCount);
jdbcEntity.setCurrCapacity(currCapacity);
jdbcEntity.setActiveConnectionsAverageCount(activeConnectionsAverageCount);
jdbcEntity.setNumAvailable(numAvailable);
jdbcEntity.setHighestNumUnavailable(highestNumUnavailable);
jdbcEntity.setLeakedConnectionCount(leakedConnectionCount);
jdbcEntity.setFailuresToReconnectCount(failuresToReconnectCount);
list.add(jdbcEntity);
/* sb.append("<td>" + hostname+":"+portString+"</td>"+
"<td>" + name+ "</td>" + "<td>" + name+ "</td>" +
"<td>" + state + "</td>" + "<td>" + state + "</td>" +
"<td>" +versionJDBCDriver+ "</td>" + "<td>" +versionJDBCDriver+ "</td>" +
...@@ -268,8 +285,12 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime) ...@@ -268,8 +285,12 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
"<td>" +numAvailable+ "</td>" + "<td>" +numAvailable+ "</td>" +
"<td>" +highestNumUnavailable+ "</td>" + "<td>" +highestNumUnavailable+ "</td>" +
"<td>" +leakedConnectionCount+ "</td>" + "<td>" +leakedConnectionCount+ "</td>" +
"<td>" + failuresToReconnectCount + "</td>"+ "</tr>"); "<td>" + failuresToReconnectCount + "</td>"+ "</tr>");*/
} }
return list;
} }
...@@ -283,7 +304,7 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime) ...@@ -283,7 +304,7 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
* @throws ReflectionException * @throws ReflectionException
* @throws IOException * @throws IOException
*/ */
public void getJVMRuntime(ObjectName serverRuntime) public JVMEntity getJVMRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException, throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException { MBeanException, ReflectionException, IOException {
JVMEntity jvmEntity = new JVMEntity(); JVMEntity jvmEntity = new JVMEntity();
...@@ -307,16 +328,7 @@ public void getJVMRuntime(ObjectName serverRuntime) ...@@ -307,16 +328,7 @@ public void getJVMRuntime(ObjectName serverRuntime)
jvmEntity.setHeapSizeCurrent(heapSizeCurrent); jvmEntity.setHeapSizeCurrent(heapSizeCurrent);
jvmEntity.setHeapFreeCurrent(heapFreeCurrent); jvmEntity.setHeapFreeCurrent(heapFreeCurrent);
jvmEntity.setHeapFreePercent(heapFreePercent); jvmEntity.setHeapFreePercent(heapFreePercent);
sb.append("<td>" + Finalweblogicmonit.hostname + "</td>" + return jvmEntity;
"<td>" + Finalweblogicmonit.portString + "</td>" +
"<td>" +name+ "</td>" +
"<td>" +heapSizeCurrent+ "</td>" +
"<td>" + heapFreeCurrent + "</td>");
if(heapFreePercent < 30){
sb.append("<td><font color=red>" +heapFreePercent+ "%<font></td>" + "</tr>");
} else {
sb.append("<td>" + heapFreePercent + "%</td>" + "</tr>");
}
/* //TODO /* //TODO
System.out.println(name); System.out.println(name);
System.out.println(byteToMB(heapSizeMax)); System.out.println(byteToMB(heapSizeMax));
...@@ -391,12 +403,13 @@ public void getServerRuntime(ObjectName serverRuntime) ...@@ -391,12 +403,13 @@ public void getServerRuntime(ObjectName serverRuntime)
* @throws ReflectionException * @throws ReflectionException
* @throws IOException * @throws IOException
*/ */
public void getWebAppComponentRuntime(ObjectName serverRuntime) public List<ProgramEntity> getWebAppComponentRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException, throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException { MBeanException, ReflectionException, IOException {
// 获取web应用程序运行时组件 // 获取web应用程序运行时组件
ObjectName[] applicationRuntimes = getAttribute(serverRuntime, ObjectName[] applicationRuntimes = getAttribute(serverRuntime,
"ApplicationRuntimes"); "ApplicationRuntimes");
List<ProgramEntity> list = new ArrayList<ProgramEntity>();
for (int i = 0; i < applicationRuntimes.length; i++) { for (int i = 0; i < applicationRuntimes.length; i++) {
ObjectName applicationRuntime = applicationRuntimes[i]; ObjectName applicationRuntime = applicationRuntimes[i];
ObjectName[] componentRuntimes = getAttribute(applicationRuntime, ObjectName[] componentRuntimes = getAttribute(applicationRuntime,
...@@ -431,7 +444,8 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime) ...@@ -431,7 +444,8 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
programEntity.setOpenedSessionMix(openSessionsHighCount); programEntity.setOpenedSessionMix(openSessionsHighCount);
programEntity.setOpenedSessionCount(sessionsOpenedTotalCount); programEntity.setOpenedSessionCount(sessionsOpenedTotalCount);
programEntity.setType(status); programEntity.setType(status);
sb.append("<td>" + hostname+":"+portString+"</td>"+ list.add(programEntity);
/* sb.append("<td>" + hostname+":"+portString+"</td>"+
"<td>" + name+ "</td>" + "<td>" + name+ "</td>" +
"<td>" + status + "</td>" + "<td>" + status + "</td>" +
"<td>" +openSessionsCurrentCount+ "</td>" + "<td>" +openSessionsCurrentCount+ "</td>" +
...@@ -439,18 +453,11 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime) ...@@ -439,18 +453,11 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
"<td>" + sessionsOpenedTotalCount + "</td>" "<td>" + sessionsOpenedTotalCount + "</td>"
); );
sb.append("<td>" + status + "</td>" + "</tr>"); sb.append("<td>" + status + "</td>" + "</tr>");*/
// TODO
System.out.println("name = " + name + ", status = "
+ deploymentState);
System.out.println(openSessionsCurrentCount);
System.out.println(openSessionsHighCount);
System.out.println(sessionsOpenedTotalCount);
System.out.println(status);
System.out.println();
} }
} }
} }
return list;
} }
/** /**
...@@ -462,7 +469,7 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime) ...@@ -462,7 +469,7 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
* @throws InstanceNotFoundException * @throws InstanceNotFoundException
* @throws AttributeNotFoundException * @throws AttributeNotFoundException
*/ */
public void getThreadPoolRuntime(ObjectName serverRuntime) public ThreadEntity getThreadPoolRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException, throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException { MBeanException, ReflectionException, IOException {
// 获取线程池运行时 // 获取线程池运行时
...@@ -518,26 +525,7 @@ public void getThreadPoolRuntime(ObjectName serverRuntime) ...@@ -518,26 +525,7 @@ public void getThreadPoolRuntime(ObjectName serverRuntime)
threadEntity.setActiveExeThreadCount(ActiveExeThreadCount); threadEntity.setActiveExeThreadCount(ActiveExeThreadCount);
threadEntity.setState(returnState(healthState.getState())); threadEntity.setState(returnState(healthState.getState()));
threadEntity.setFlag(suspended); threadEntity.setFlag(suspended);
sb.append("<td>" + hostname+":"+portString+"</td>"+ return threadEntity;
"<td>" + ExecuteThreadTotalCount+ "</td>" +
"<td>" + ExecuteThreadIdleCount + "</td>" +
"<td>" +StandbyThreadCount+ "</td>" +
"<td>" +QueueLength+ "</td>" +
"<td>" + Throughput + "</td>"+
"<td>" +PendingUserRequestCount+ "</td>" +
"<td>" +hoggingThreadCount+ "</td>" +
"<td>" +ActiveExeThreadCount+ "</td>"+
"<td>" +returnState(healthState.getState())+ "</td>"
);
sb.append("<td>" + suspended + "</td>" + "</tr>");
System.out.println(suspended);
System.out.println(pendingUserRequestCount);
System.out.println(hoggingThreadCount);
System.out.println(queueLength);
} }
/** /**
...@@ -747,7 +735,7 @@ private String returnState(int i) ...@@ -747,7 +735,7 @@ private String returnState(int i)
// TODO // TODO
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try { try {
FileReader reader = new FileReader("D:\\Console\\list.txt"); /* FileReader reader = new FileReader("D:\\Console\\list.txt");
FileReader reader1 = new FileReader("D:\\Console\\list.txt"); FileReader reader1 = new FileReader("D:\\Console\\list.txt");
FileReader reader2 = new FileReader("D:\\Console\\list.txt"); FileReader reader2 = new FileReader("D:\\Console\\list.txt");
FileReader reader3= new FileReader("D:\\Console\\list.txt"); FileReader reader3= new FileReader("D:\\Console\\list.txt");
...@@ -762,27 +750,28 @@ try { ...@@ -762,27 +750,28 @@ try {
Finalweblogicmonit heapinfo = new Finalweblogicmonit(); Finalweblogicmonit heapinfo = new Finalweblogicmonit();
//jvm //jvm
heapinfo.outputHtmlHead(); //heapinfo.outputHtmlHead();
while ((s1 = br.readLine()) != null) { while ((s1 = br.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) { if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " "); s1 = s1.replace("\t", " ");
str = s1.split(" "); str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]); initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes(); ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length; int length = (int) serverRT.length;
for(int j=0;j<length;j++){ for(int j=0;j<length;j++){
heapinfo.getJVMRuntime(serverRT[j]); JVMEntity jvmEntity = heapinfo.getJVMRuntime(serverRT[j]);
} }
heapinfo.outputtofile(); //heapinfo.outputtofile();
} }
} }
//线程状态 //线程状态
heapinfo.outputThreadHead(); // heapinfo.outputThreadHead();
while ((s1 = br1.readLine()) != null) { while ((s1 = br1.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) { if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " "); s1 = s1.replace("\t", " ");
...@@ -792,56 +781,59 @@ try { ...@@ -792,56 +781,59 @@ try {
int length = (int) serverRT.length; int length = (int) serverRT.length;
for(int j=0;j<length;j++){ for(int j=0;j<length;j++){
heapinfo.getThreadPoolRuntime(serverRT[j]); ThreadEntity threadEntity = heapinfo.getThreadPoolRuntime(serverRT[j]);
} }
heapinfo.outputtofile(); // heapinfo.outputtofile();
} }
} }
//jdbc状态 //jdbc状态
heapinfo.outputJdbcHead(); //heapinfo.outputJdbcHead();
while ((s1 = br2.readLine()) != null) { while ((s1 = br2.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) { if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " "); s1 = s1.replace("\t", " ");
str = s1.split(" "); str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]); initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes(); ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length; int length = (int) serverRT.length;
for(int j=0;j<length;j++){ for(int j=0;j<length;j++){
heapinfo.getJDBCDataSourceRuntime(serverRT[j]); System.out.println("jdbc"+serverRT[j]);
List<JDBCEntity> jdbcEntities = heapinfo.getJDBCDataSourceRuntime(serverRT[j]);
} }
heapinfo.outputtofile(); //heapinfo.outputtofile();
} }
} }
//应用程序状态 //应用程序状态
heapinfo.outputAppHead(); // heapinfo.outputAppHead();
while ((s1 = br3.readLine()) != null) { while ((s1 = br3.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) { if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " "); s1 = s1.replace("\t", " ");
str = s1.split(" "); str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]); initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes(); ObjectName[] serverRT = getServerRuntimes();
System.out.println(serverRT.toString());
int length = (int) serverRT.length; int length = (int) serverRT.length;
for(int j=0;j<length;j++){ for(int j=0;j<length;j++){
heapinfo.getWebAppComponentRuntime(serverRT[j]); List<ProgramEntity> programEntities = heapinfo.getWebAppComponentRuntime(serverRT[j]);
} }
heapinfo.outputtofile(); //heapinfo.outputtofile();
connector.close(); connector.close();
} }
} }
heapinfo.outputHtmlTail(); //heapinfo.outputHtmlTail();
heapinfo.outputtofile(); // heapinfo.outputtofile();
br.close(); br.close();
br1.close(); br1.close();
br2.close(); br2.close();
...@@ -858,7 +850,14 @@ try { ...@@ -858,7 +850,14 @@ try {
System.out.println("Total Running time is: "+time/1000 + "s" ); System.out.println("Total Running time is: "+time/1000 + "s" );
} else { } else {
System.out.println("Total Running time is: "+time + "ms" ); System.out.println("Total Running time is: "+time + "ms" );
} }*/
Services services = new Services();
services.setServiceIp("192.168.1.129");
services.setPort("7001");
services.setIpUsername("weblogic");
services.setIpPassword("weblogic123");
List<Object> list = getWebLogicInfo(services,"detail");
System.out.println(list);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -867,4 +866,50 @@ try { ...@@ -867,4 +866,50 @@ try {
weblogic.getWebAppComponentRuntime(serverRuntime); weblogic.getWebAppComponentRuntime(serverRuntime);
*/ */
} }
//获取weblogic的详细信息
public static List<Object> getWebLogicInfo(Services service,String type) {
Finalweblogicmonit heapinfo = new Finalweblogicmonit();
String ip = service.getServiceIp();
String port = service.getPort();
String userName = service.getIpUsername();
String passWord = service.getIpPassword();
List<Object> list = new ArrayList<>();
try {
initConnection(ip, port, userName, passWord);
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
if("detail".equals(type)){
//JVM信息
JVMEntity jvmEntity = heapinfo.getJVMRuntime(serverRT[j]);
System.out.println(jvmEntity.toString());
list.add(jvmEntity);
//线程信息
ThreadEntity threadEntity = heapinfo.getThreadPoolRuntime(serverRT[j]);
System.out.println(threadEntity.toString());
list.add(threadEntity);
//jdbc信息
/* List<JDBCEntity> jdbcEntities = heapinfo.getJDBCDataSourceRuntime(serverRT[j]);
System.out.println(jdbcEntities.toString());*/
// list.add(jdbcEntities);
//应用信息
List<ProgramEntity> programEntities = heapinfo.getWebAppComponentRuntime(serverRT[j]);
System.out.println(programEntities.toString());
list.add(programEntities);
}else if("programState".equals(type)){
//应用信息
List<ProgramEntity> programEntities = heapinfo.getWebAppComponentRuntime(serverRT[j]);
list.add(programEntities);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
} }
\ No newline at end of file
package com.cc.serviceutil; package com.cc.serviceutil;
import com.cc.bean.Services; import com.cc.bean.Services;
import com.cc.bean.ServicesRest;
import com.cc.service.CrudService; import com.cc.service.CrudService;
import com.cc.service.ServiceService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by changc on 2018/9/11. * Created by changc on 2018/9/11.
...@@ -22,7 +17,7 @@ import java.util.Map; ...@@ -22,7 +17,7 @@ import java.util.Map;
@Component @Component
public class WeblogicReport { public class WeblogicReport {
@Autowired @Autowired
CrudService crudService; CrudService crudService;
//监控weblogic //监控weblogic
...@@ -32,10 +27,13 @@ public class WeblogicReport { ...@@ -32,10 +27,13 @@ public class WeblogicReport {
public void WeblogicReport(){ public void WeblogicReport(){
//System.out.println("心跳开始------------------------------------》"); //System.out.println("心跳开始------------------------------------》");
List<Services> ServiceList= (List<Services>) crudService.SelectServiceList().getData(); List<Services> ServiceList= (List<Services>) crudService.SelectServiceList().getData();
System.out.println(ServiceList); for (Services ser:ServiceList){
int i=1; String name = ser.getApplyName();
System.out.println(i++); System.out.println(name);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment