代码从别出拷来,运行了一下。可以正常运行。以后可以通过这部分代码来扩展监控。
/**
*
*/
package com.monitor.weblogic;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
/**
* @author Administrator
*
*/
public class MonitorWeblogic {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;
/*
* 实例化 DomainRuntimeServiceMBean 对象名,这样可以通过类使用此对象名.
*/
static {
try {
service = new ObjectName(
"com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
} catch (MalformedObjectNameException e) {
throw new AssertionError(e.getMessage());
}
}
public static void main(String[] args) throws Exception {
String hostname = "localhost";
String portString = "7001";
String username = "weblogic";
String password = "weblogic";
MonitorWeblogic weblogic = new MonitorWeblogic();
weblogic.initConnection(hostname, portString, username, password);
// weblogic.printNameAndState(weblogic.getServerRuntimes());
// weblogic.getServletData();
weblogic.printAppNameAndState();
}
/*
* 实例化与 Domain Runtime MBean Server 的连接。
*/
private void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException {
String protocol = "t3";
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();
}
public ObjectName[] getServerRuntimes() throws Exception {
return (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
}
/*
* 迭代 ServerRuntimeMBean,获取名称和状态
*/
public void printNameAndState(ObjectName[] p_objNames) throws Exception {
ObjectName[] serverRT = p_objNames;
System.out.println("got server runtimes");
int length = (int) serverRT.length;
for (int i = 0; i < length; i++) {
print("===================Weblogic运行信息====================", "");
//域名称
String name = (String) connection.getAttribute(serverRT[i], "Name");
System.out.println("Server name: " + name);
//运行状态
String state = (String) connection.getAttribute(serverRT[i], "State");
System.out.println("Server state: " + state);
//开始时间
Long activationTime = (Long) connection.getAttribute(serverRT[i], "ActivationTime");
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
date.setTime(activationTime);
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDateTime = formater.format(date);
System.out.println("Start running time: " + strDateTime);
//weblogic 的版本
String weblogicVersion = (String) connection.getAttribute(serverRT[i], "WeblogicVersion");
System.out.println("Weblogic Version: " + weblogicVersion);
//OS信息
ObjectName jvmServerRT = (ObjectName) connection.getAttribute(serverRT[i], "JVMRuntime");
print("=======================OS信息==========================", "");
print(" 操作系统", connection.getAttribute(jvmServerRT, "OSName").toString());
print(" 操作系统版本", connection.getAttribute(jvmServerRT, "OSVersion").toString());
print(" Java版本", connection.getAttribute(jvmServerRT, "JavaVersion").toString());
print(" Java提供商", connection.getAttribute(jvmServerRT, "JavaVMVendor").toString());
long runTime = (Long) connection.getAttribute(jvmServerRT, "Uptime") / 1000;
long day = runTime / (24 * 60 * 60);
long hour = runTime % (24 * 60 * 60) / (60 * 60);
long minute = runTime % (60 * 60) / 60;
long second = runTime % 60;
System.out.println(" 系统已经运行:" + day + "天" + hour + "小时" + minute + "分" + second + "秒");
}
}
/*
*
* 获取一组 WebApplicationComponentRuntimeMBean 取得应用相关信息比如jdbc
*/
public void getServletData() throws Exception {
print("===================ServletData信息====================", "");
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for (int i = 0; i < length; i++) {
ObjectName[] appRT = (ObjectName[]) connection.getAttribute(serverRT[i], "ApplicationRuntimes");
int appLength = (int) appRT.length;
for (int x = 0; x < appLength; x++) {
System.out.println("Application name: " + (String) connection.getAttribute(appRT[x], "Name"));
ObjectName[] compRT = (ObjectName[]) connection.getAttribute(appRT[x], "ComponentRuntimes");
int compLength = (int) compRT.length;
for (int y = 0; y < compLength; y++) {
System.out.println(" Component name: " + (String) connection.getAttribute(compRT[y], "Name"));
String componentType = (String) connection.getAttribute(compRT[y], "Type");
System.out.println(" type: " + componentType.toString());
if (componentType.toString().equals("WebAppComponentRuntime")) {
ObjectName[] servletRTs = (ObjectName[]) connection.getAttribute(compRT[y], "Servlets");
int servletLength = (int) servletRTs.length;
for (int z = 0; z < servletLength; z++) {
System.out.println(" Servlet name: "
+ (String) connection.getAttribute(servletRTs[z], "Name"));
System.out.println(" Servlet context path: "
+ (String) connection.getAttribute(servletRTs[z], "ContextPath"));
System.out.println(" Invocation Total Count : "
+ (Object) connection.getAttribute(servletRTs[z], "InvocationTotalCount"));
}
}
}
}
}
}
/**
* 取得应用状态
* @throws Exception
*/
public void printAppNameAndState() throws Exception {
print("===================AppNameAndState====================", "");
ObjectName[] serverRT = getServerRuntimes();
for (int k = 0; k < serverRT.length; k++) {
ObjectName[] appRT = (ObjectName[]) connection.getAttribute(serverRT[k], "ApplicationRuntimes");
int length = appRT.length;
for (int i = 0; i < length; i++) {
String appName = (String) connection.getAttribute(appRT[i], "Name");
ObjectName[] compRT = (ObjectName[]) connection.getAttribute(appRT[i], "ComponentRuntimes");
for (int j = 0; j < compRT.length; j++) {
int appState = ((Integer) connection.getAttribute(compRT[j], "DeploymentState")).intValue();
String type = (String) connection.getAttribute(compRT[j], "Type");
System.out.println(k + "|" + j + "|Server name: " + appName + ". Server type: " + type
+ " Server state: " + appState);
}
}
}
}
public void print(String prefix, String content) {
System.out.println(prefix + ": " + content);
}
}
分享到:
相关推荐
JRockit远程监控Linux环境下WebLogic方案
这个插件通过管理控制台通过 JMX 监控 weblogic。 与其他 weblogic 插件不同,它会查询所有信息 1 次,然后使用 XPATH 识别您希望监控的信息。 这允许最大的灵活性。
weblogic 调优策略,前 言 第一章 应用程序调优 1.1.1 通用代码调优 1.1.2 减小没有必要的操作 ...5.4 WebLogic监控 5.4.1 JVM监控 5.4.2 Console监控 5.4.3 实用工具分析 5.5 应用程序分析 总结 参考文献 关于作者
在界面上输入要监控的WebLogic地址,以及登录名和密码,Interval为每隔多长时间请求一次服务器,如果您选中了Alert,则程序会在WebLogic的当前连接数超过ActiveMaxCount文本框中的值的时候以飞鸽的形式向您发送提醒...
Java二进制IO类与文件复制操作实例 16个目标文件 内容索引:Java源码,初学实例,二进制,文件复制 Java二进制IO类与文件复制操作实例,好像是一本书的例子,源代码有的是独立运行的,与同目录下的其它代码文件互不联系...
0x02演示废话不多说,先上效果图,自带CVE-2020-14882 Weblogic远程代码执行攻略0x03编写属于你的图像化突破利用工具3.1项目结构.├── ExpDemo - JavaFX . iml├── pom . xmlmaven工程的基本文件└── src └─...
基于weblogic,应对数据库连接泄漏的解决方法; 包含临时解决方法和数据连接池泄露监控,并可追踪到某个类某行代码。
Java二进制IO类与文件复制操作实例,好像是一本书的例子,源代码有的是独立运行的,与同目录下的其它代码文件互不联系,这些代码面向初级、中级Java程序员。 Java访问权限控制源代码 1个目标文件 摘要:Java源码,...
Tomcat 6(Later)/ (Weblogic 10 later)/GlassFish V2 Later Ant IReport 3.6 报表开发工具 J.Office的总体功能 1 系统设置 系统设置负责整个系统的基础参数配置及管理功能,如系统的账号,角色管理,岗位...
监控原始Java Zabbix Java网关 描述 这是Zabbix Java Gateway的源代码,已更新为允许 jmx.discovery项(使用Mbeans自动发现) JBoss JMX Weblogic T3协议 它是如何工作的 您必须在JMX项目中指定一个用户名,例如“ ...
单一个中间件又分web中间件(apache、IIS),应用中间件(tomcat、weblogic、webSphere)等,虽然都是中间件,每一样拎出来往深了学都不是一朝一夕之功。但调优对于每一项的要求又不仅仅是“知道”或“会使用”这么...
安全监控及审计管理办法.docx 密码使用管理制度.doc 应急预案管理制度.doc 恶意代码防范管理制度.doc 机房安全管理制度.doc 系统安全风险管理制度.docx 网络安全管理制度.doc 网络安全设备配置规范.docx 资产安全...
技术点八:在线流程定义,采用开源Activiti流程引擎,实现在线画流程,自定义表单,表单挂接,业务流转,流程监控,流程跟踪,流程委托等 技术点九:自定义表单,支持用户自定义表单布局,支持单表、列表、Select\\...
简易的图像报表工具和Excel导入导出8、Web容器测试通过的有Jetty和Tomcat,Weblogic9、亮点功能:分布式部署,云平台,移动平台开发,规则引擎10、要求JDK1.6+JEECG技术点总结:技术点一:代码生成器SPA单页面应用...
" " "5、Tomcat、JBoss、WebLogic以及WebSphere技术。 " "软件开发基础 "考核要点 "分值 "30 " "基础知识 "1、数据库基础; " " "2、数据结构; " " "3、程序设计基础; " " "4、网络协议; " " "5、计算机组成原理...
多态性语言具有灵活、抽象、行为共享、代码共享的优势,很好的解决了应用程序函数同名问题。 2、String是最基本的数据类型吗? 基本数据类型包括byte、int、char、long、float、double、boolean和short。 java.lang....
sleep是线程类(Thread)的方法,导致此线程暂停执行指定时间,给执行机会给其他线程,但是监控状态依然保持,到时后会自动恢复。调用sleep不会释放对象锁。 wait是Object类的方法,对此对象调用wait方法导致本线程...
32. OpenServer下的终端监控系统-Spy FileSystem 33.X常用的系统调用 34.X系统下部分控制代码介绍及其应用 35.用工具badtrk检查磁盘坏道? 36.x C 编程问题精粹 37.输入输出函数 38.命令详解及使用技巧 39.LOGIN:...