Commit 7ac6bd7b by liuyongshuai

添加监测weblogic方法

parent 01de92c2
......@@ -14,10 +14,39 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 公司的maven仓库 -->
<repositories>
<repository>
<id>founder</id>
<url>http://47.92.108.28:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 指定maven plugin仓库 -->
<pluginRepositories>
<!-- 公司的maven plugin仓库 -->
<pluginRepository>
<id>founder</id>
<url>http://47.92.108.28:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
......@@ -28,6 +57,8 @@
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -76,6 +107,24 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.founder.wljmxclient</groupId>
<artifactId>wljmxclient</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.founder.wlclient</groupId>
<artifactId>wlclient</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.founder.wlfullclient</groupId>
<artifactId>wlfullclient</artifactId>
<version>1.0</version>
</dependency>
<!-- 远程调用 -->
<dependency>
<groupId>org.jvnet.hudson</groupId>
......@@ -97,6 +146,7 @@
<scope>provided</scope>
</dependency>
</dependencies>
<build>
......
package com.cc.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j;
/**
* Created by liuys on 2018/11/19.
*/
@Data
@Log4j
@NoArgsConstructor
@AllArgsConstructor
public class JVMEntity {
/**
* JVM信息
*/
private String ip;
private String post;
private String serviceName;
private Long heapSizeCurrent;
private Long heapFreeCurrent;
private Integer heapFreePercent;
}
package com.cc.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j;
/**
* Created by liuys on 2018/11/19.
*/
@Data
@Log4j
@NoArgsConstructor
@AllArgsConstructor
public class ProgramEntity {
private String serviceName;
private String unitName;
private String state;
private Integer openedSession;
private Integer openedSessionMix;
private Integer openedSessionCount;
private String type;
}
package com.cc.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j;
/**
* Created by liuys on 2018/11/19.
*/
@Data
@Log4j
@NoArgsConstructor
@AllArgsConstructor
public class ThreadEntity {
private String serviceName; private Integer ExecuteThreadTotalCount;
private Integer ExecuteThreadIdleCount;
private Integer StandbyThreadCount;
//等待队列长度
private Integer QueueLength;
//线程吞吐量
private Double Throughput;
//等待的用户请求数
private Integer PendingUserRequestCount;
//活动线程数
private Integer ActiveExeThreadCount;
// 暂停的 Suspended
private Boolean suspended;
// 待处理用户请求计数 PendingUserRequestCount
private Integer pendingUserRequestCount;
// 占用线程计数 HoggingThreadCount
private Integer hoggingThreadCount;
// 队列长度 QueueLength
private Integer queueLength;
//线程状态
private String state;
//是否挂起
private Boolean flag;
}
package com.cc.serviceutil;
import com.cc.bean.JVMEntity;
import com.cc.bean.ProgramEntity;
import com.cc.bean.ThreadEntity;
import weblogic.health.HealthState;
import javax.management.*;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import java.io.*;
import java.net.MalformedURLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
public class Finalweblogicmonit {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static ObjectName runtimeService;
private static final String RUNTIMESERVICEMBEAN = "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
//主机名
private static String hostname;
//控制台端口
private static String portString;
StringBuffer sb = new StringBuffer();
FileOutputStream fos = null;
/**
* 初始化连接
*
* @throws IOException
* @throws MalformedURLException
* @throws MalformedObjectNameException
*/
public static void initConnection(String hostname, String portString,String username, String password) throws IOException,
MalformedURLException, MalformedObjectNameException {
String protocol = "t3";
Finalweblogicmonit.hostname=hostname;
Finalweblogicmonit.portString=portString;
// String hostname = "192.168.161.101";
// String portString = "7001";
// String username = "weblogic";
// String password = "wang1234";
/*String hostname = "127.0.0.1";
String portString = "7001";
String username = "weblogic";
String password = "88888888";*/
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,
jndiroot + mserver);
Hashtable<String, String> h = new Hashtable<String, String>();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();
runtimeService = new ObjectName(RUNTIMESERVICEMBEAN);
}
/**
* 连接池管理
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getConnectorServiceRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// 应用服务运行时 ApplicationRuntimes
ObjectName[] applicationRuntimes = getAttribute(serverRuntime,
"ApplicationRuntimes");
for (int i = 0; i < applicationRuntimes.length; i++) {
ObjectName applicationRuntime = applicationRuntimes[i];
ObjectName[] componentRuntimes = getAttribute(applicationRuntime,
"ComponentRuntimes");
for (int j = 0; j < componentRuntimes.length; j++) {
ObjectName componentRuntime = componentRuntimes[j];
String type = getAttribute(componentRuntime, "Type");
System.out.println(type);
if (!type.equals("ConnectorComponentRuntime")) {
continue;
}
ObjectName[] connectionPools = getAttribute(componentRuntime,
"ConnectionPools");
for (int k = 0; k < connectionPools.length; k++) {
ObjectName connectionPool = connectionPools[k];
// 连接池的状态 State
String state = getAttribute(connectionPool, "State");
// 服务名称 Name
String name = getAttribute(connectionPool, "Name");
// 连接池名称 PoolName
String poolName = getAttribute(connectionPool, "PoolName");
// 连接池中的当前使用的连接数量 ActiveConnectionsCurrentCount
Integer activeConnectionsCurrentCount = getAttribute(
connectionPool, "ActiveConnectionsCurrentCount");
// 等待池中连接的最大客户数 HighestNumWaiters
Long highestNumWaiters = getAttribute(connectionPool,
"HighestNumWaiters");
// 丢失的连接数 ConnectionLeakProfileCount
Integer connectionLeakProfileCount = getAttribute(
connectionPool, "ConnectionLeakProfileCount");
// 连接池最大连接数 MaxCapacity
Integer maxCapacity = getAttribute(connectionPool,
"StMaxCapacityate");
System.out.println(name);
System.out.println(poolName);
System.out.println(state);
System.out.println(activeConnectionsCurrentCount);
System.out.println(highestNumWaiters);
System.out.println(connectionLeakProfileCount);
System.out.println(maxCapacity);
}
}
}
}
/**
* 执行队列运行时
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getExecuteQueueRuntimes(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// 执行队列运行时 ExecuteQueueRuntimes
ObjectName[] executeQueueRuntimes = getAttribute(serverRuntime,
"ExecuteQueueRuntimes");
for (int i = 0; i < executeQueueRuntimes.length; i++) {
ObjectName executeQueueRuntime = executeQueueRuntimes[i];
// 队列的名称 Name
String name = getAttribute(executeQueueRuntime, "Name");
// 执行线程的总数目 ExecuteThreadTotalCount
Integer executeThreadTotalCount = getAttribute(executeQueueRuntime,
"ExecuteThreadTotalCount");
// 队列中当前空闲线程数 ExecuteThreadCurrentIdleCount
Integer executeThreadCurrentIdleCount = getAttribute(
executeQueueRuntime, "ExecuteThreadCurrentIdleCount");
// 队列中最长的等待时间 PendingRequestOldestTime
// 取出相应毫秒值
Long pendingTime = getAttribute(executeQueueRuntime,
"PendingRequestOldestTime");
// 获取毫秒值对应的日期,并转换成指定格式
Date pendingDate = new Date(pendingTime);
String pendingRequestOldestTime = formatDate(pendingDate,
"yyyy/MM/dd HH:mm:ss");
// 队列中等待的请求数 PendingRequestCurrentCount
Integer pendingRequestCurrentCount = getAttribute(
executeQueueRuntime, "PendingRequestCurrentCount");
// 被本队列处理的请求总数 ServicedRequestTotalCount
Integer servicedRequestTotalCount = getAttribute(
executeQueueRuntime, "ServicedRequestTotalCount");
// TODO
System.out.println(name);
System.out.println(executeThreadTotalCount);
System.out.println(executeThreadCurrentIdleCount);
System.out.println(pendingRequestOldestTime);
System.out.println(pendingRequestCurrentCount);
System.out.println(servicedRequestTotalCount);
}
}
/**
* JDBC数据源运行时
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// JDBC运行时 JDBCServiceRuntime
ObjectName jdbcServiceRuntime = getAttribute(serverRuntime,
"JDBCServiceRuntime");
// TODO
// System.out.println(getAttribute(
// jdbcServiceRuntime, "Name"));
// JDBC数据源运行时 JDBCDataSourceRuntimeMBeans
ObjectName[] jdbcDataSourceRuntimeMBeans = getAttribute(
jdbcServiceRuntime, "JDBCDataSourceRuntimeMBeans");
//获取配置
ObjectName domainConfig = (ObjectName) getAttribute(runtimeService, "DomainConfiguration");
ObjectName[] objJDBCSystemResources = (ObjectName[]) getAttribute(domainConfig, "JDBCSystemResources");
ObjectName objJdbcResource = null;
ObjectName objPoolPrms = null;
for (int i = 0; i < jdbcDataSourceRuntimeMBeans.length; i++) {
ObjectName jdbcDataSourceRuntimeMBean = jdbcDataSourceRuntimeMBeans[i];
// 判断JDBCSystemResources对象是否为null
if (objJDBCSystemResources[i] != null) {
objJdbcResource = (ObjectName) getAttribute(objJDBCSystemResources[i], "JDBCResource");
objPoolPrms = (ObjectName) getAttribute(objJdbcResource, "JDBCConnectionPoolParams");
}
// 数据源名称 Name
String name = getAttribute(jdbcDataSourceRuntimeMBean, "Name");
//数据源状态
String state=getAttribute(jdbcDataSourceRuntimeMBean, "State");
//驱动版本
String versionJDBCDriver=getAttribute(jdbcDataSourceRuntimeMBean, "VersionJDBCDriver");
//最大容量
Integer maxCapacity=getAttribute(objPoolPrms, "MaxCapacity");
//当前活动连接数
Integer activeConnectionsCurrentCount=getAttribute(jdbcDataSourceRuntimeMBean, "ActiveConnectionsCurrentCount");
//历史最大活跃数
Integer activeConnectionsHighCount=getAttribute(jdbcDataSourceRuntimeMBean, "ActiveConnectionsHighCount");
//当前连接数
Integer currCapacity=getAttribute(jdbcDataSourceRuntimeMBean, "CurrCapacity");
//活动连接平均数
Integer activeConnectionsAverageCount=getAttribute(jdbcDataSourceRuntimeMBean, "ActiveConnectionsAverageCount");
//池内空闲连接数
Integer numAvailable=getAttribute(jdbcDataSourceRuntimeMBean, "NumAvailable");
//历史最大连接数
Integer highestNumUnavailable=getAttribute(jdbcDataSourceRuntimeMBean, "HighestNumUnavailable");
//泄漏的连接数
Integer leakedConnectionCount=getAttribute(jdbcDataSourceRuntimeMBean, "LeakedConnectionCount");
//失败重新连接数
Integer failuresToReconnectCount=getAttribute(jdbcDataSourceRuntimeMBean, "FailuresToReconnectCount");
//返回当前等待连接的总数 WaitingForConnectionCurrentCount
Integer waitingForConnectionCurrentCount = getAttribute(
jdbcDataSourceRuntimeMBean,
"WaitingForConnectionCurrentCount");
// 部署状态 DeploymentState
Integer deploymentState = getAttribute(jdbcDataSourceRuntimeMBean,
"DeploymentState");
sb.append("<td>" + hostname+":"+portString+"</td>"+
"<td>" + name+ "</td>" +
"<td>" + state + "</td>" +
"<td>" +versionJDBCDriver+ "</td>" +
"<td>" +maxCapacity+ "</td>" +
"<td>" +activeConnectionsCurrentCount+ "</td>" +
"<td>" +activeConnectionsHighCount+ "</td>" +
"<td>" +currCapacity+ "</td>" +
"<td>" +activeConnectionsAverageCount+ "</td>" +
"<td>" +numAvailable+ "</td>" +
"<td>" +highestNumUnavailable+ "</td>" +
"<td>" +leakedConnectionCount+ "</td>" +
"<td>" + failuresToReconnectCount + "</td>"+ "</tr>");
}
}
/**
* JVM运行时
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getJVMRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
JVMEntity jvmEntity = new JVMEntity();
// JVM运行时 JVMRuntime
ObjectName JVMRuntime = getAttribute(serverRuntime, "JVMRuntime");
// 名称 Name
String name = getAttribute(JVMRuntime, "Name");
// 堆大小最大值 HeapSizeMax
Long heapSizeMax = getAttribute(JVMRuntime, "HeapSizeMax");
// 返回当前JVM堆中空闲内存数,单位时字节 HeapFreePercent
Integer heapFreePercent = getAttribute(JVMRuntime, "HeapFreePercent");
// 当前堆的总空间
Long heapSizeCurrent = getAttribute(JVMRuntime, "HeapSizeCurrent");
// 当前堆已使用的空间 HeapFreeCurrent
Long heapFreeCurrent = getAttribute(JVMRuntime, "HeapFreeCurrent");
getAttribute(JVMRuntime, "HeapFreeCurrent");
jvmEntity.setIp(Finalweblogicmonit.hostname);
jvmEntity.setPost(Finalweblogicmonit.portString );
jvmEntity.setServiceName(name);
jvmEntity.setHeapSizeCurrent(heapSizeCurrent);
jvmEntity.setHeapFreeCurrent(heapFreeCurrent);
jvmEntity.setHeapFreePercent(heapFreePercent);
sb.append("<td>" + Finalweblogicmonit.hostname + "</td>" +
"<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
System.out.println(name);
System.out.println(byteToMB(heapSizeMax));
System.out.println(heapFreePercent);
System.out.println(byteToMB(heapSizeCurrent));
System.out.println(byteToMB(heapFreeCurrent));*/
}
/**
* 服务器运行时
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getServerRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// 服务名称 Name
String name = getAttribute(serverRuntime, "Name");
// 返回服务器激活时间ActivationTime
Long activationTime = getAttribute(serverRuntime, "ActivationTime");
Date date = new Date(activationTime);
String time = formatDate(date, "yyyy/MM/dd HH:mm:ss");
// 返回当前服务器监听连接的端口 ListenPort
Integer listenPort = getAttribute(serverRuntime, "ListenPort");
// 返回当前服务器监听连接的IP地址 ListenAddress
String listenAddress = getAttribute(serverRuntime, "ListenAddress");
// 状态 State
String state = getAttribute(serverRuntime, "State");
// 应用服务器的健康状态 HealthState
HealthState healthState = (HealthState) connection.getAttribute(
serverRuntime, "HealthState");
// 当前打开的Socket数量 OpenSocketsCurrentCount
Integer openSocketsCurrentCount = getAttribute(serverRuntime,
"OpenSocketsCurrentCount");
// 打开的Socket的总数 SocketsOpenedTotalCount
Long socketsOpenedTotalCount = getAttribute(serverRuntime,
"SocketsOpenedTotalCount");
// 当前连接数 TODO
System.out.println(healthState.getState());
System.out.println(healthState.getMBeanName());
System.out.println(healthState.getMBeanType());
System.out.println(healthState.getSubsystemName());
// TODO
// System.out.println(name);
// System.out.println(time);
// System.out.println(listenPort);
// System.out.println(listenAddress);
// System.out.println(state);
// System.out.println(healthState.getState());
// System.out.println(openSocketsCurrentCount);
// System.out.println(socketsOpenedTotalCount);
}
/**
* web应用程序运行时组件
*
* @param serverRuntime
* @throws AttributeNotFoundException
* @throws InstanceNotFoundException
* @throws MBeanException
* @throws ReflectionException
* @throws IOException
*/
public void getWebAppComponentRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// 获取web应用程序运行时组件
ObjectName[] applicationRuntimes = getAttribute(serverRuntime,
"ApplicationRuntimes");
for (int i = 0; i < applicationRuntimes.length; i++) {
ObjectName applicationRuntime = applicationRuntimes[i];
ObjectName[] componentRuntimes = getAttribute(applicationRuntime,
"ComponentRuntimes");
for (int j = 0; j < componentRuntimes.length; j++) {
ObjectName componentRuntime = componentRuntimes[j];
String componentType = getAttribute(componentRuntime, "Type");
// web应用程序运行时组件 WebAppComponentRuntime
if (componentType.equals("WebAppComponentRuntime")) {
// 单元名 Name
String name = getAttribute(componentRuntime, "Name");
// 部署状态 DeploymentState
Integer deploymentState = getAttribute(componentRuntime,
"DeploymentState");
// 当前打开的Session数 OpenSessionsCurrentCount
Integer openSessionsCurrentCount = getAttribute(
componentRuntime, "OpenSessionsCurrentCount");
// Web应用程序名称
// 打开的Session最高数 OpenSessionsHighCount
Integer openSessionsHighCount = getAttribute(
componentRuntime, "OpenSessionsHighCount");
// 打开的Session的总数 SessionsOpenedTotalCount
Integer sessionsOpenedTotalCount = getAttribute(
componentRuntime, "SessionsOpenedTotalCount");
// 应用状态 Status
String status = getAttribute(componentRuntime, "Status");
ProgramEntity programEntity = new ProgramEntity();
programEntity.setServiceName(hostname+":"+portString);
programEntity.setUnitName(name);
programEntity.setState(status);
programEntity.setOpenedSession(openSessionsCurrentCount);
programEntity.setOpenedSessionMix(openSessionsHighCount);
programEntity.setOpenedSessionCount(sessionsOpenedTotalCount);
programEntity.setType(status);
sb.append("<td>" + hostname+":"+portString+"</td>"+
"<td>" + name+ "</td>" +
"<td>" + status + "</td>" +
"<td>" +openSessionsCurrentCount+ "</td>" +
"<td>" +openSessionsHighCount+ "</td>" +
"<td>" + sessionsOpenedTotalCount + "</td>"
);
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();
}
}
}
}
/**
* 线程池运行时
*
* @throws IOException
* @throws ReflectionException
* @throws MBeanException
* @throws InstanceNotFoundException
* @throws AttributeNotFoundException
*/
public void getThreadPoolRuntime(ObjectName serverRuntime)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
// 获取线程池运行时
ObjectName threadPoolRuntime = getAttribute(serverRuntime,
"ThreadPoolRuntime");
//线程总数
Integer ExecuteThreadTotalCount = getAttribute(threadPoolRuntime,
"ExecuteThreadTotalCount");
//空闲线程数
Integer ExecuteThreadIdleCount = getAttribute(threadPoolRuntime,
"ExecuteThreadIdleCount");
//备用线程数
Integer StandbyThreadCount = getAttribute(threadPoolRuntime,
"StandbyThreadCount");
//等待队列长度
Integer QueueLength = getAttribute(threadPoolRuntime,
"QueueLength");
//线程吞吐量
Double Throughput = getAttribute(threadPoolRuntime,
"Throughput");
//等待的用户请求数
Integer PendingUserRequestCount = getAttribute(threadPoolRuntime,
"PendingUserRequestCount");
//活动线程数
Integer ActiveExeThreadCount=ExecuteThreadTotalCount-StandbyThreadCount;
// 暂停的 Suspended
Boolean suspended = (Boolean) getAttribute(threadPoolRuntime,
"Suspended");
// 待处理用户请求计数 PendingUserRequestCount
Integer pendingUserRequestCount = getAttribute(threadPoolRuntime,
"PendingUserRequestCount");
// 占用线程计数 HoggingThreadCount
Integer hoggingThreadCount = getAttribute(threadPoolRuntime,
"HoggingThreadCount");
// 队列长度 QueueLength
Integer queueLength = getAttribute(threadPoolRuntime, "QueueLength");
//健康状态
HealthState healthState=getAttribute(threadPoolRuntime, "HealthState");
ThreadEntity threadEntity = new ThreadEntity();
threadEntity.setServiceName(hostname+":"+portString);
threadEntity.setExecuteThreadTotalCount(ExecuteThreadTotalCount);
threadEntity.setExecuteThreadIdleCount(ExecuteThreadIdleCount);
threadEntity.setStandbyThreadCount(StandbyThreadCount);
threadEntity.setQueueLength(QueueLength);
threadEntity.setThroughput(Throughput);
threadEntity.setPendingUserRequestCount(PendingUserRequestCount);
threadEntity.setHoggingThreadCount(hoggingThreadCount);
threadEntity.setActiveExeThreadCount(ActiveExeThreadCount);
threadEntity.setState(returnState(healthState.getState()));
threadEntity.setFlag(suspended);
sb.append("<td>" + hostname+":"+portString+"</td>"+
"<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);
}
/**
* 获取weblogic属性参数
*
* @param objectName
* @param name
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAttribute(ObjectName objectName, String name) {
Object obj = null;
try {
obj = connection.getAttribute(objectName, name);
} catch (Exception e) {
// TODO
e.printStackTrace();
}
return (T) obj;
}
/**
* 日期格式转换
*
* @param date
* @param format
* @return
*/
public static String formatDate(Date date, String format) {
DateFormat df = new SimpleDateFormat(format);
return df.format(date);
}
/**
* 字节转换成MB
*
* @param bytes
* @return
*/
public static String byteToMB(long bytes) {
double mb = (double) bytes / 1024 / 1024;
DecimalFormat df = new DecimalFormat("#.00");
return df.format(mb);
}
public static ObjectName[] getServerRuntimes() throws Exception {
return (ObjectName[]) connection.getAttribute(runtimeService, "ServerRuntimes");
}
public void outputHtmlHead(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sb.append("<html>");
sb.append("<head>");
sb.append("<style type=text/css charset=gbk>");
sb.append("table.gridtable {font-family:微软雅黑,Consolas; font-size:12px; color:#333333; border-width:1px; border-color:#666666; border-collapse:collapse; }");
sb.append("table.gridtable th { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#dedede; }");
sb.append("table.gridtable td { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#ffffff; }");
sb.append("table.gridtable1 {font-family:微软雅黑,Consolas; font-size:12px; color:#333333; border-width:1px; border-color:#666666; border-collapse:collapse; }");
sb.append("table.gridtable1 th { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#dedede; }");
sb.append("table.gridtable1 td { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#ffffff; }");
sb.append("table.gridtable2 {font-family:微软雅黑,Consolas; font-size:12px; color:#333333; border-width:1px; border-color:#666666; border-collapse:collapse; }");
sb.append("table.gridtable2 th { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#dedede; }");
sb.append("table.gridtable2 td { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#ffffff; }");
sb.append("table.gridtable3 {font-family:微软雅黑,Consolas; font-size:12px; color:#333333; border-width:1px; border-color:#666666; border-collapse:collapse; }");
sb.append("table.gridtable3 th { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#dedede; }");
sb.append("table.gridtable3 td { border-width:1px; padding:8px; border-style:solid; border-color:#666666; background-color:#ffffff; }");
sb.append("</style><p style=font-family:verdana,arial,sans-serif; font-size:11px;></p></head>");
sb.append("<body><p><center><h3>本地WebLogic 中间件堆内存使用情况<h3></center></p><br>");
sb.append("<p><center><b>巡检日期:</b>" + sdf.format(new Date()) + "</center></p>");
sb.append("<hr style='FILTER: alpha(opacity=100,finishopacity=0,style=3)' width='60%' color=#987cb9 SIZE=3>");
sb.append("<h3 align='center'>JVM状态</h3>");
sb.append("<table class='gridtable' align='center'><tr>");
sb.append("<th><b>主机名</b></th>"
+ "<th><b>控制台端口</b></th>"
+ "<th><b>Server名称</b></th>"
+ "<th><b>当前堆大小(byte)</b></th>"
+ "<th><b>当前空闲堆(byte)</b></th>"
+ "<th><b>堆空闲百分比</b></th>");
sb.append("</tr><tr>");
}
//线程html头
public void outputThreadHead(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sb.append("</table>");
sb.append("<h3 align='center'>线程池状态</h3>");
sb.append("<table class='gridtable1' align='center'><tr>");
sb.append("<th><b>主机名/控制台端口</b></th>"
+"<th><b>线程总数</b></th>"
+ "<th><b>空闲线程数 </b></th>"
+ "<th><b>备用线程数</b></th>"
+ "<th><b>等待队列长度</b></th>"
+ "<th><b>线程吞吐量</b></th>"
+ "<th><b>等待的用户请求数</b></th>"
+ "<th><b>占用的线程数</b></th>"
+ "<th><b>活动线程数</b></th>"
+ "<th><b>线程状态</b></th>"
+ "<th><b>是否挂起</b></th>");
sb.append("</tr><tr>");
}
//jdbc html头
public void outputJdbcHead(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sb.append("</table>");
sb.append("<h3 align='center'>JDBC状态</h3>");
sb.append("<table class='gridtable2' align='center'><tr>");
sb.append("<th><b>主机名/控制台端口</b></th>"
+ "<th><b>数据源名称</b></th>"
+ "<th><b>数据源状态</b></th>"
+ "<th><b>驱动版本</b></th>"
+ "<th><b>最大容量</b></th>"
+ "<th><b>当前活动连接数</b></th>"
+ "<th><b>历史最大活跃数</b></th>"
+ "<th><b>当前连接数</b></th>"
+ "<th><b>活动连接平均数</b></th>"
+ "<th><b>池内空闲连接数</b></th>"
+ "<th><b>历史最大连接数</b></th>"
+ "<th><b>泄漏的连接数</b></th>"
+ "<th><b>失败重新连接数</b></th>"
);
sb.append("</tr><tr>");
}
//应用程序hmtl头
public void outputAppHead(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sb.append("</table>");
sb.append("<h3 align='center'>应用程序状态</h3>");
sb.append("<table class='gridtable3' align='center'><tr>");
sb.append("<th><b>主机名/控制台端口</b></th>"
+ "<th><b>单元名</b></th>"
+ "<th><b>部署状态</b></th>"
+ "<th><b>当前打开的Session数</b></th>"
+ "<th><b>打开的Session最高数</b></th>"
+ "<th><b>打开的Session的总数 </b></th>"
+ "<th><b>应用状态 </b></th>"
);
sb.append("</tr><tr>");
}
public void outputHtmlTail() throws Exception{
sb.append("</table></body></html>");
}
public void outputtofile() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
String createDate = sdf.format(new Date());
String root = "d:\\weblogic\\" + createDate;
File dir = new File(root);
if(!dir.exists()){
dir.mkdirs();
}
String newFile = "Weblogic_Info.html";
File file = new File(dir + File.separator+ newFile);
if(file.exists()){
file.delete();
}
file.createNewFile();
// new FileOutputStream(file,true)
// param:true 表示追加输出,不加则会被最后一条记录覆盖之前的所有记录;
fos = new FileOutputStream(file,true);
fos.write(sb.toString().getBytes("GBK"));
fos.flush();
fos.close();
}
/**
* ObjName Mbean服务器实例
* return 返回状态名
*/
private String returnState(int i)
{
String states="";
switch (i) {
case 0:
states = "OK";
break;
case 1:
states ="Warning";
break;
case 2:
states = "CRITICAL";
break;
case 3:
states ="FAILED";
break;
case 4:
states = "OVERLOADED";
break;
}
return states;
}
// TODO
public static void main(String[] args) throws Exception {
try {
FileReader reader = new FileReader("D:\\Console\\list.txt");
FileReader reader1 = new FileReader("D:\\Console\\list.txt");
FileReader reader2 = new FileReader("D:\\Console\\list.txt");
FileReader reader3= new FileReader("D:\\Console\\list.txt");
BufferedReader br = new BufferedReader(reader);
BufferedReader br1 = new BufferedReader(reader1);
BufferedReader br2 = new BufferedReader(reader2);
BufferedReader br3=new BufferedReader(reader3);
String s1 = null;
String[] str = new String[20];
long optStartTime = System.currentTimeMillis();
Finalweblogicmonit heapinfo = new Finalweblogicmonit();
//jvm
heapinfo.outputHtmlHead();
while ((s1 = br.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " ");
str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo.getJVMRuntime(serverRT[j]);
}
heapinfo.outputtofile();
}
}
//线程状态
heapinfo.outputThreadHead();
while ((s1 = br1.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " ");
str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo.getThreadPoolRuntime(serverRT[j]);
}
heapinfo.outputtofile();
}
}
//jdbc状态
heapinfo.outputJdbcHead();
while ((s1 = br2.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " ");
str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo.getJDBCDataSourceRuntime(serverRT[j]);
}
heapinfo.outputtofile();
}
}
//应用程序状态
heapinfo.outputAppHead();
while ((s1 = br3.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " ");
str = s1.split(" ");
initConnection(str[0], str[1], str[2], str[3]);
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo.getWebAppComponentRuntime(serverRT[j]);
}
heapinfo.outputtofile();
connector.close();
}
}
heapinfo.outputHtmlTail();
heapinfo.outputtofile();
br.close();
br1.close();
br2.close();
br3.close();
reader.close();
reader1.close();
reader2.close();
reader3.close();
long optEndTime = System.currentTimeMillis();
long time = optEndTime - optStartTime;
if(time == 1000 || time > 1000){
System.out.println("Total Running time is: "+time/1000 + "s" );
} else {
System.out.println("Total Running time is: "+time + "ms" );
}
} catch (Exception e) {
e.printStackTrace();
}
//weblogic.getConnectorServiceRuntime(serverRuntime);
/*weblogic.getJVMRuntime(serverRuntime);
weblogic.getWebAppComponentRuntime(serverRuntime);
*/
}
}
\ No newline at end of file
package com.cc.serviceutil;
/**
* Created by liuys on 2018/11/20.
*/
public class PoinTest {
public static void main(String[] args){
System.out.println("sfdf");
}
}
package com.cc.serviceutil;
import com.cc.bean.Services;
import com.cc.bean.ServicesRest;
import com.cc.service.CrudService;
import com.cc.service.ServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by changc on 2018/9/11.
*/
@Slf4j
@Component
public class WeblogicReport {
@Autowired
CrudService crudService;
//监控weblogic
//@Scheduled(cron = "*/30 * * * * ?") //30秒
@Scheduled(cron = "0 */1 * * * ?") //一分钟
@Async("taskExecutor")
public void WeblogicReport(){
//System.out.println("心跳开始------------------------------------》");
List<Services> ServiceList= (List<Services>) crudService.SelectServiceList().getData();
System.out.println(ServiceList);
int i=1;
System.out.println(i++);
}
}
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