Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service-rest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
常超
service-rest
Commits
745d8cce
Commit
745d8cce
authored
Nov 21, 2018
by
liuyongshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改完善weblogic的监测方法
parent
ea6450ab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
75 deletions
+160
-75
src/main/java/com/cc/bean/JDBCEntity.java
+41
-0
src/main/java/com/cc/serviceutil/Finalweblogicmonit.java
+113
-67
src/main/java/com/cc/serviceutil/WeblogicReport.java
+6
-8
No files found.
src/main/java/com/cc/bean/JDBCEntity.java
0 → 100644
View file @
745d8cce
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
;
}
src/main/java/com/cc/serviceutil/Finalweblogicmonit.java
View file @
745d8cce
package
com
.
cc
.
serviceutil
;
import
com.cc.bean.JVMEntity
;
import
com.cc.bean.ProgramEntity
;
import
com.cc.bean.ThreadEntity
;
import
com.cc.bean.*
;
import
weblogic.health.HealthState
;
import
javax.management.*
;
...
...
@@ -15,8 +13,10 @@ import java.net.MalformedURLException;
import
java.text.DateFormat
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Hashtable
;
import
java.util.List
;
public
class
Finalweblogicmonit
{
...
...
@@ -40,7 +40,7 @@ FileOutputStream fos = null;
* @throws MalformedObjectNameException
*/
public
static
void
initConnection
(
String
hostname
,
String
portString
,
String
username
,
String
password
)
throws
IOException
,
Malformed
URLException
,
Malformed
ObjectNameException
{
MalformedObjectNameException
{
String
protocol
=
"t3"
;
Finalweblogicmonit
.
hostname
=
hostname
;
Finalweblogicmonit
.
portString
=
portString
;
...
...
@@ -198,7 +198,7 @@ public void getExecuteQueueRuntimes(ObjectName serverRuntime)
* @throws ReflectionException
* @throws IOException
*/
public
void
getJDBCDataSourceRuntime
(
ObjectName
serverRuntime
)
public
List
<
JDBCEntity
>
getJDBCDataSourceRuntime
(
ObjectName
serverRuntime
)
throws
AttributeNotFoundException
,
InstanceNotFoundException
,
MBeanException
,
ReflectionException
,
IOException
{
// JDBC运行时 JDBCServiceRuntime
...
...
@@ -216,6 +216,8 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
ObjectName
objJdbcResource
=
null
;
ObjectName
objPoolPrms
=
null
;
List
<
JDBCEntity
>
list
=
new
ArrayList
<
JDBCEntity
>();
for
(
int
i
=
0
;
i
<
jdbcDataSourceRuntimeMBeans
.
length
;
i
++)
{
ObjectName
jdbcDataSourceRuntimeMBean
=
jdbcDataSourceRuntimeMBeans
[
i
];
// 判断JDBCSystemResources对象是否为null
...
...
@@ -255,8 +257,23 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
// 部署状态 DeploymentState
Integer
deploymentState
=
getAttribute
(
jdbcDataSourceRuntimeMBean
,
"DeploymentState"
);
sb
.
append
(
"<td>"
+
hostname
+
":"
+
portString
+
"</td>"
+
JDBCEntity
jdbcEntity
=
new
JDBCEntity
();
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>" + state + "</td>" +
"<td>" +versionJDBCDriver+ "</td>" +
...
...
@@ -268,8 +285,12 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
"<td>" +numAvailable+ "</td>" +
"<td>" +highestNumUnavailable+ "</td>" +
"<td>" +leakedConnectionCount+ "</td>" +
"<td>"
+
failuresToReconnectCount
+
"</td>"
+
"</tr>"
);
"<td>" + failuresToReconnectCount + "</td>"+ "</tr>");*/
}
return
list
;
}
...
...
@@ -283,7 +304,7 @@ public void getJDBCDataSourceRuntime(ObjectName serverRuntime)
* @throws ReflectionException
* @throws IOException
*/
public
void
getJVMRuntime
(
ObjectName
serverRuntime
)
public
JVMEntity
getJVMRuntime
(
ObjectName
serverRuntime
)
throws
AttributeNotFoundException
,
InstanceNotFoundException
,
MBeanException
,
ReflectionException
,
IOException
{
JVMEntity
jvmEntity
=
new
JVMEntity
();
...
...
@@ -307,16 +328,7 @@ public void getJVMRuntime(ObjectName serverRuntime)
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>"
);
}
return
jvmEntity
;
/* //TODO
System.out.println(name);
System.out.println(byteToMB(heapSizeMax));
...
...
@@ -391,12 +403,13 @@ public void getServerRuntime(ObjectName serverRuntime)
* @throws ReflectionException
* @throws IOException
*/
public
void
getWebAppComponentRuntime
(
ObjectName
serverRuntime
)
public
List
<
ProgramEntity
>
getWebAppComponentRuntime
(
ObjectName
serverRuntime
)
throws
AttributeNotFoundException
,
InstanceNotFoundException
,
MBeanException
,
ReflectionException
,
IOException
{
// 获取web应用程序运行时组件
ObjectName
[]
applicationRuntimes
=
getAttribute
(
serverRuntime
,
"ApplicationRuntimes"
);
List
<
ProgramEntity
>
list
=
new
ArrayList
<
ProgramEntity
>();
for
(
int
i
=
0
;
i
<
applicationRuntimes
.
length
;
i
++)
{
ObjectName
applicationRuntime
=
applicationRuntimes
[
i
];
ObjectName
[]
componentRuntimes
=
getAttribute
(
applicationRuntime
,
...
...
@@ -431,7 +444,8 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
programEntity
.
setOpenedSessionMix
(
openSessionsHighCount
);
programEntity
.
setOpenedSessionCount
(
sessionsOpenedTotalCount
);
programEntity
.
setType
(
status
);
sb
.
append
(
"<td>"
+
hostname
+
":"
+
portString
+
"</td>"
+
list
.
add
(
programEntity
);
/* sb.append("<td>" + hostname+":"+portString+"</td>"+
"<td>" + name+ "</td>" +
"<td>" + status + "</td>" +
"<td>" +openSessionsCurrentCount+ "</td>" +
...
...
@@ -439,18 +453,11 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
"<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
();
sb.append("<td>" + status + "</td>" + "</tr>");*/
}
}
}
return
list
;
}
/**
...
...
@@ -462,7 +469,7 @@ public void getWebAppComponentRuntime(ObjectName serverRuntime)
* @throws InstanceNotFoundException
* @throws AttributeNotFoundException
*/
public
void
getThreadPoolRuntime
(
ObjectName
serverRuntime
)
public
ThreadEntity
getThreadPoolRuntime
(
ObjectName
serverRuntime
)
throws
AttributeNotFoundException
,
InstanceNotFoundException
,
MBeanException
,
ReflectionException
,
IOException
{
// 获取线程池运行时
...
...
@@ -518,26 +525,7 @@ public void getThreadPoolRuntime(ObjectName serverRuntime)
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
);
return
threadEntity
;
}
/**
...
...
@@ -747,7 +735,7 @@ private String returnState(int i)
// TODO
public
static
void
main
(
String
[]
args
)
throws
Exception
{
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 reader2 = new FileReader("D:\\Console\\list.txt");
FileReader reader3= new FileReader("D:\\Console\\list.txt");
...
...
@@ -762,27 +750,28 @@ try {
Finalweblogicmonit heapinfo = new Finalweblogicmonit();
//jvm
heapinfo
.
outputHtmlHead
();
//
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
]);
JVMEntity jvmEntity =
heapinfo.getJVMRuntime(serverRT[j]);
}
heapinfo
.
outputtofile
();
//
heapinfo.outputtofile();
}
}
//线程状态
heapinfo
.
outputThreadHead
();
//
heapinfo.outputThreadHead();
while ((s1 = br1.readLine()) != null) {
if (!s1.substring(0, 1).equals("#")) {
s1 = s1.replace("\t", " ");
...
...
@@ -792,56 +781,59 @@ try {
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo
.
getThreadPoolRuntime
(
serverRT
[
j
]);
ThreadEntity threadEntity =
heapinfo.getThreadPoolRuntime(serverRT[j]);
}
heapinfo
.
outputtofile
();
//
heapinfo.outputtofile();
}
}
//jdbc状态
heapinfo
.
outputJdbcHead
();
//
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
]);
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) {
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();
System.out.println(serverRT.toString());
int length = (int) serverRT.length;
for(int j=0;j<length;j++){
heapinfo
.
getWebAppComponentRuntime
(
serverRT
[
j
]);
List<ProgramEntity> programEntities =
heapinfo.getWebAppComponentRuntime(serverRT[j]);
}
heapinfo
.
outputtofile
();
//
heapinfo.outputtofile();
connector.close();
}
}
heapinfo
.
outputHtmlTail
();
heapinfo
.
outputtofile
();
//
heapinfo.outputHtmlTail();
//
heapinfo.outputtofile();
br.close();
br1.close();
br2.close();
...
...
@@ -858,7 +850,14 @@ try {
System.out.println("Total Running time is: "+time/1000 + "s" );
} else {
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
)
{
e
.
printStackTrace
();
}
...
...
@@ -867,4 +866,50 @@ try {
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
src/main/java/com/cc/serviceutil/WeblogicReport.java
View file @
745d8cce
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.
...
...
@@ -32,10 +27,13 @@ public class WeblogicReport {
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
++);
for
(
Services
ser:
ServiceList
){
String
name
=
ser
.
getApplyName
();
System
.
out
.
println
(
name
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment