package com.sitech.ismp.coll; /** * * * * 编号 KPI_ID KPI名称 KPI描述 1 PM-00-04-003-01 当前应用服务器的内存堆使用比率 当前应用服务器的内存堆使用比率 2 * PM-00-04-003-02 当前数据库连接池使用比率 当前数据库连接池使用比率 3 PM-00-04-001-03 消息队列等待请求数量 * PM-00-04-003-03 ---------当前连接池数目 * * * 编号 KPI_ID KPI名称 KPI描述 1 FM-00-04-003-01 异常主机地址或主机名 * 如果应用服务器采用群集系统,其中某台机器出现异常,则反映该机器的地址或名称 2 FM-00-04-003-02 异常事务数 * 在采样周期内未能正常完成的事务个数 10分钟 数值型 major 3 FM-00-04-001-01 服务运行状态 (UP-----运行正常 * DOWN------不正常运行 2006-08-15) * * 编号 KPI_ID KPI名称 KPI描述 1 CM-00-04-003-01 应用服务器运行模式 应用服务器群集还是单机 2 * CM-00-04-003-02 允许应用服务器支配的内存堆大小(MB) 允许应用服务器支配的内存堆大小(MB) 3 CM-00-04-003-03 * 配置的总线程数 配置的总线程数 4 CM-00-04-003-04 配置的数据库连接池大小 配置的数据库连接池大小 5 CM-00-04-003-05 * 应用服务器的系统日志路径 应用服务器的系统日志路径 6 CM-00-04-003-06 应用服务器的用户日志路径 应用服务器的用户日志路径 7 * */ /* * 说明:普通类,主要用snmp方法实现weblogic7.0的采集 * */ import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Vector; import org.apache.log4j.Logger; import com.adventnet.snmp.beans.SnmpTarget; import com.adventnet.snmp.snmp2.SnmpOID; import com.sitech.ismp.app.coll.RPCTarget; import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL; import com.sitech.util.Formater; public class CollWeblogicWithSNMP implements CollWeblogicWithSNMPMBean { SnmpTarget target = null; String ObjectIP = null; private boolean DEBUG = false; RPCTarget rpctarget = null; static Logger logger = Logger.getLogger("LOGER"); String hostname = ""; String community = null; String ip = null; int port = 0; String servicename = null; private Vector result = new Vector(); public Vector coll(HashMap params) { String community = "public"; String ip = (String) params.get("IP"); // 要采集的weblogic7.0 IP String hostname = ip; int port = Integer.parseInt((String) params.get("PORT")); // SNMP端口 String servicename = (String) params.get("SERVICENAME"); // weblogic7.0所开的server this.hostname = hostname; this.ip = ip; this.port = port; this.community = community; this.servicename = servicename; logger.info(ip); // 记录日志 // 与weblogic7.0建立初始化连接 initWeblogic(ip, servicename, port, hostname, community); // 进行采集操作 collWeblogic7(); // 将采集到的数据写入文件 version 2 // 2006-08-07 callCollBase(); // 返回操作 return result; } private void setResult(String value, String unitID, String kpiID) { try { TblATO_KPIDETAIL record; record = new TblATO_KPIDETAIL(); record.setCLL_TIME(new java.util.Date()); // 采集所消耗的时间 record.setKPI_ID(kpiID); // kpi编号 record.setKPI_VALUE(value); // 具体采集得到的值信息 record.setUNIT_ID(unitID); // unit record.setCLL_TIME(new Date()); // 日期 result.add(record); } catch (Exception e) { logger.error(e); } } private void callCollBase() { CollBase coll = new CollBase(); coll.addKPISet(result); coll.saveKPI2File(); coll.displayKPI(); } private void noneffective() { String unitID = "10-12-11-10-10:" + hostname + "-total"; // CM-00-04-003-03 配置的总线程数 setResult("noneffective", unitID, "CM-00-04-003-03"); // FM-00-04-003-01 异常主机地址或主机名 setResult("noneffective", unitID, "FM-00-04-003-01"); // FM-00-04-003-02 异常事务数 setResult("noneffective", unitID, "FM-00-04-003-02"); } private void collWeblogic7() { try { // 采集连接池情况 collConnPoolValues(); // 采集日志路径 collLog(); // 采集内存堆相关 collHeap(); // 采集JTA相关 collJTA(); // 采集群集相关 collCluser(); // 采集消息队列 collQueue(); // noneffective(); // 服务运行状态 collRunState(); String unitID = "10-12-11-10-10:" + hostname + "-total"; // FM-00-04-003-03 主机状态 true 连接正常 false 连接失败可能宕机 setResult("true", unitID, "FM-00-04-003-03"); release(); } catch (Exception e) { // 10-12-11-10-10------->10-12-11-11-10 String unitID = "10-12-11-10-10:" + hostname + "-total"; // FM-00-04-003-03 主机状态 true 连接正常 false 连接失败可能宕机 setResult("false", unitID, "FM-00-04-003-03"); logger.error(e); } } private void collConnPoolValues() { try { HashMap hs = new HashMap(); hs.put("JDBCPOOL.NUM", "1"); getjdbcConnectionPoolMaxCapacity(); getJdbcPoolUseRate(hs); getjdbcConnectionPoolActiveConnectionsCurrentCount(); } catch (Exception e) { e.printStackTrace(); } } private void collJTA() { getserverRuntimeName(); getserverRuntimeListenAddress(); getserverRuntimeListenPort(); getserverRuntimeAdminServerHost(); getserverRuntimeAdminServerListenPort(); } /** * serverRuntimeName: .1.3.6.1.4.1.140.625.360.1.15 weblogic 运行的服务器的名称: * .1.3.6.1.4.1.140.625.360.1.15 */ private void getserverRuntimeName() { // System.out.println("Begin getserverRuntimeName"); String unitid = "10-12-11-11-12:"; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); String domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name String hostName = (String) vc_hostName.elementAt(0); unitid = unitid + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-serverName"; boolean bool = true; Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.15", bool); if (vc_active.size() > 0) { String count = (String) vc_active.elementAt(0); setResult(count, unitid, "CM-00-04-003-07"); } // System.out.println("End getserverRuntimeName"); } /** * the address on which this server is listening for * connections(boss/172.16.9.1): .1.3.6.1.4.1.140.625.360.1.30 * weblogic运行的服务器的侦听地址(boss/172.16.9.1): .1.3.6.1.4.1.140.625.360.1.30 */ private void getserverRuntimeListenAddress() { System.out.println("Begin getserverRuntimeListenAddress"); // System.out.println("Begin getserverRuntimeName"); String unitid = "10-12-11-11-12:"; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); String domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name String hostName = (String) vc_hostName.elementAt(0); unitid = unitid + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-hostAddress"; boolean bool = true; Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.30", bool); if (vc_active.size() > 0) { String count = (String) vc_active.elementAt(0); setResult(count, unitid, "CM-00-04-003-08"); // setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11"); } System.out.println("End getserverRuntimeListenAddress"); } /** * port on which this server is listening for connections: * .1.3.6.1.4.1.140.625.360.1.35 weblogic 运行的服务器的侦听端口: * .1.3.6.1.4.1.140.625.360.1.35 */ private void getserverRuntimeListenPort() { System.out.println("Begin getserverRuntimeListenPort"); String unitid = "10-12-11-11-12:"; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); String domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name String hostName = (String) vc_hostName.elementAt(0); unitid = unitid + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-servicePort"; boolean bool = true; Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.35", bool); if (vc_active.size() > 0) { String count = (String) vc_active.elementAt(0); setResult(count, unitid, "CM-00-04-003-09"); } System.out.println("End getserverRuntimeListenPort"); } /** * the address on which admin server is listening for connections(boss or * 172.16.9.1): .1.3.6.1.4.1.140.625.360.1.70 weblogic * 运行的服务器的管理服务器的侦听地址(boss or 172.16.9.1): .1.3.6.1.4.1.140.625.360.1.70 */ private void getserverRuntimeAdminServerHost() { System.out.println("Begin getserverRuntimeAdminServerHost"); String unitid = "10-12-11-11-12:"; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); String domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name String hostName = (String) vc_hostName.elementAt(0); unitid = unitid + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-serviceAddress"; boolean bool = true; Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", bool); if (vc_active.size() > 0) { String count = (String) vc_active.elementAt(0); setResult(count, unitid, "CM-00-04-003-10"); } System.out.println("End getserverRuntimeAdminServerHost"); } /** * the port on which admin server is listening for connections: * .1.3.6.1.4.1.140.625.360.1.75 weblogic 运行的服务器的管理服务器的侦听短端口: * .1.3.6.1.4.1.140.625.360.1.75 */ private void getserverRuntimeAdminServerListenPort() { System.out.println("Begin getserverRuntimeAdminServerListenPort"); String unitid = "10-12-11-11-12:"; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); String domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name String hostName = (String) vc_hostName.elementAt(0); unitid = unitid + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-serverListenPort"; boolean bool = true; Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.75", bool); if (vc_active.size() > 0) { String count = (String) vc_active.elementAt(0); setResult(count, unitid, "CM-00-04-003-11"); } System.out.println("End getserverRuntimeAdminServerListenPort"); } private void collCluster() { String domainName = ""; boolean bool = true; Vector clusters = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.31", bool);// Cluster if (clusters.size() > 0) { domainName = (String) clusters.elementAt(0); } // // 1 CM-00-04-003-01 应用服务器运行模式 应用服务器群集还是单机 1天 字符型 String cluster = "false"; if (!clusters.isEmpty()) { cluster = "true"; } String unitID = "10-12-11-10-10:" + hostname + "-" + Formater.neatenunitid(domainName) + "-" + "runmodel"; setResult(cluster, unitID, "CM-00-04-003-01"); } /** * @author pc103 * @date 2006-07-21 * @exception * @exp 说明:采集内存堆 通过该采集可以知道JVM堆中可用的内存数量,OID等相关信息 1 PM-00-04-003-01 * 当前应用服务器的内存堆使用比率 当前应用服务器的内存堆使用比率 10分钟 数值型 2 2 CM-00-04-003-02 * 允许应用服务器支配的内存堆大小(MB) 允许应用服务器支配的内存堆大小(MB) 1天 数值型 */ private void collHeap() { getJVMMEM(); // getFreeJVMMEM(); // getUsedJVMMEM(); getJVMMEMUseRate(); } /** * 当前总情况 The current size of the JVM heap in bytes: * .1.3.6.1.4.1.140.625.340.1.30 当前JVM中的堆内存值: .1.3.6.1.4.1.140.625.340.1.30 * * ==========unitID有变,unitID=10-12-11-10-10--->10-12-11-11-10 */ private void getJVMMEM() { String unitID = "10-12-11-11-10:"; String hostName = ""; String domainName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-HeapSize"; System.out.println("Begin getJVMMEM"); Vector JVMMEM = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.30", false); if (JVMMEM.size() > 0) { String state = String.valueOf(JVMMEM.elementAt(0)); setResult(state, unitID, "CM-00-04-003-02"); } } catch (Exception e) { logger.error(e); } System.out.println("End getJVMMEM"); } /** * 允许使用的 The current amount of free memory in the JVM heap in bytes: * .1.3.6.1.4.1.140.625.340.1.25 JVM 中free memory值: * .1.3.6.1.4.1.140.625.340.1.25 */ private void getFreeJVMMEM() { System.out.println("Begin getFreeJVMMEM"); Vector FreeJVMMEM = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.25", false); if (FreeJVMMEM.size() > 0) { String state = String.valueOf(FreeJVMMEM.elementAt(0)); System.out.println("FreeJVM==" + state); setResult(state, "FreeJVM", "CM-00-04-003-02"); } System.out.println("End getFreeJVMMEM"); } /** * 使用过的 The current size of the JVM heap in bytes: * .1.3.6.1.4.1.140.625.340.1.30 当前JVM中的堆内存值: .1.3.6.1.4.1.140.625.340.1.30 * The current amount of free memory in the JVM heap in bytes: * .1.3.6.1.4.1.140.625.340.1.25 JVM 中free memory值: * .1.3.6.1.4.1.140.625.340.1.25 JVM 中的使用的内存值=JVM中的堆内存值 - JVM 中的剩余内存 = * (.1.3.6.1.4.1.140.625.340.1.30)-(.1.3.6.1.4.1.140.625.340.1.25) */ private void getUsedJVMMEM() { System.out.println("Begin getJVMMEMUseRate"); Vector JVMMEM = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.30", false); if (JVMMEM.size() > 0) { int state_all = Integer.parseInt((String) JVMMEM.elementAt(0)); Vector FreeJVMMEM = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.25", false); if (FreeJVMMEM.size() > 0) { int state_free = Integer.parseInt((String) FreeJVMMEM .elementAt(0)); int state_use = state_all - state_free; setResult(String.valueOf(state_use), "UsedJvm", "CM-00-04-003-03"); } } System.out.println("End getJVMMEMUseRate"); } /** * The current size of the JVM heap in bytes: .1.3.6.1.4.1.140.625.340.1.30 * 当前JVM中的堆内存值: .1.3.6.1.4.1.140.625.340.1.30 The current amount of free * memory in the JVM heap in bytes: .1.3.6.1.4.1.140.625.340.1.25 JVM 中free * memory值: .1.3.6.1.4.1.140.625.340.1.25 JVM 中的使用的内存值=JVM中的堆内存值 - JVM * 中的剩余内存 JVM中的内存使用率= JVM 中的使用的内存值*100/JVM中的堆内存值 = * (.1.3.6.1.4.1.140.625.340.1.30)-(.1.3.6.1.4.1.140.625.340.1.25)*100F/(.1.3.6.1.4.1.140.625.340.1.30) * * ==============10-12-11-10-10----->10-12-11-11-10 */ private void getJVMMEMUseRate() { String unitID = "10-12-11-11-10:"; String hostName = ""; String domainName = ""; System.out.println("Begin getJVMMEMUseRate"); try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + hostName + "-" + this.servicename + "-" + domainName + "-" + this.servicename + "-HeapPercent"; Vector JVMMEM = walkKPIInfo(".1.3.6.1.4.1.140.625.340.1.30", false); if (JVMMEM.size() > 0) { int state_all = Integer.parseInt((String) JVMMEM.elementAt(0)); Vector FreeJVMMEM = walkKPIInfo( ".1.3.6.1.4.1.140.625.340.1.25", false); if (FreeJVMMEM.size() > 0) { int state_free = Integer.parseInt((String) FreeJVMMEM .elementAt(0)); int state_use = state_all - state_free; if (state_all != 0) { float userate = state_use * 100F / state_all; setResult(String.valueOf(userate), unitID, "PM-00-04-003-01"); System.out.println("JVMMEMUseRate=" + userate); } } } } catch (Exception e) { logger.error(e); } System.out.println("End getJVMMEMUseRate"); } /** * @author pc103 * @date 2006-07-21 * @param 采集日志文件 * 5 CM-00-04-003-05 应用服务器的系统日志路径 应用服务器的系统日志路径 1天 字符串型 6 * CM-00-04-003-06 应用服务器的用户日志路径 应用服务器的用户日志路径 1天 字符串型 * */ private void collSysLog() { String unitID = "10-12-11-11-12:"; String hostName = ""; String domainName = ""; boolean bool = true; String logPath = ""; String serverName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + hostName + "-" + servicename + "-" + domainName + "-" + this.servicename + "-log"; Vector LogPath = walkKPIInfo(".1.3.6.1.4.1.140.625.700.1.25.32", bool);// logPath and logFileName for (Iterator it = LogPath.iterator(); it.hasNext();) { System.out.println("--------" + it.next().toString()); } if (LogPath.size() > 0) { setResult((String) LogPath.elementAt(0), unitID, "CM-00-04-003-06"); } } catch (Exception e) { logger.error(e); } } private void collUsrLog() { String unitID = "10-12-11-11-12:"; String hostName = ""; String domainName = ""; boolean bool = true; String logPath = ""; String serverName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + hostName + "-" + domainName + "-" + "log"; Vector LogPath = walkKPIInfo(".1.3.6.1.4.1.140.625.700.1.25.32", bool);// logPath and logFileName if (LogPath.size() > 0) { setResult((String) LogPath.elementAt(0), unitID, "CM-00-04-003-07"); } } catch (Exception e) { logger.error(e); } } /** * "10-12-11-10-10:";----------> "10-12-11-11-10:"; * */ private void collUsrLogTwo() { String unitID = "10-12-11-11-10:"; String hostName = ""; String domainName = ""; boolean bool = true; String logPath = ""; String serverName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + hostName + "-" + servicename + "-" + domainName + "-" + "log"; Vector LogPath = walkKPIInfo( ".1.3.6.1.4.1.140.625.700.1.25.32.100", bool);// logPath // and // logFileName if (LogPath.size() > 0) { setResult((String) LogPath.elementAt(0), unitID, "CM-00-04-003-05"); } } catch (Exception e) { logger.error(e); } } private void collLog() { this.collSysLog(); // this.collUsrLog(); this.collUsrLogTwo(); } /** * 服务器运行状态 * */ private void collRunState() { String unitID = "10-12-11-11-13:"; String hostName = ""; String domainName = ""; boolean bool = true; String logPath = ""; String serverName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); unitID = unitID + this.hostname + "-" + this.servicename; // hostName + "-" + domainName + "-" + "RunState"; Vector stateRun = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.60", bool);// logPath // and // logFileName String state = (String) stateRun.elementAt(0); if (state != null && state.length() > 0 && state.equals("RUNNING")) { state = "UP"; } else { state = "DOWN"; } if (stateRun.size() > 0) { setResult(state, unitID, "FM-00-04-001-01"); } } catch (Exception e) { logger.error(e); } } /** * @author pc103 * @date 2006-07-21 * @exception * @exp 说明:采集消息队列等待消息队列的请求数量 kpi_id= PM-00-04-001-03 * */ private void collQueue() { boolean bool = true; String unitID = "10-12-11-11-12:" + hostname + "-"; String domainName = ""; try { Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); domainName = domain[domain.length - 2]; // get Domain Vector queueName = walkKPIInfo(".1.3.6.1.4.1.140.625.180.1.35.32", false); unitID = unitID + this.servicename; // + "-PendingQueue"; setResult(queueName.elementAt(0).toString(), unitID, "PM-00-04-001-03"); } catch (Exception e) { logger.error(e); } } /** * The maximum capacity of this JDBC pool: 1.3.6.1.4.1.140.625.190.1.15 JDBC * 连接池的最大容量: 1.3.6.1.4.1.140.625.190.1.15 PM-00-04-003-02 当前数据库连接池使用比率 * CM-00-04-003-04配置的数据库连接池大小 配置的数据库连接池大小 * CM-00-04-003-04-----jdbcConnectionPoolRuntimeConnectionsTotalCount * * */ private void getjdbcConnectionPoolMaxCapacity() { String unitID = "10-12-11-11-11"; String connPoolName = ""; String connDomain = ""; String connServerName = ""; String hostName = ""; String count[] = null; int poolNum = 1; int i = 0; int j = 0; try { if (poolNum == 1) { Vector vc_Max = walkKPIInfo(".1.3.6.1.4.1.140.625.190.1.55", false); count = new String[vc_Max.size()]; for (Iterator tt = vc_Max.iterator(); tt.hasNext();) { count[i] = (String) tt.next(); i++; } Vector vc_ConnPollName = walkKPIInfo( ".1.3.6.1.4.1.140.625.190.1.15", false); // connPool // Name Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); connDomain = domain[domain.length - 2]; // get Domain Vector vc_ServerName = walkKPIInfo( ".1.3.6.1.4.1.140.625.360.1.15.32", false); // server // name. connServerName = (String) vc_ServerName.elementAt(0); Vector vc_hostName = walkKPIInfo( ".1.3.6.1.4.1.140.625.360.1.70", false); // host // name hostName = (String) vc_hostName.elementAt(0); this.hostname = hostName; for (Iterator connName = vc_ConnPollName.iterator(); connName .hasNext();) { String temp = (String) connName.next(); unitID = unitID + ":" + hostName + "-" + connServerName + "-" + connDomain + "-" + connServerName + "-" + temp; setResult(count[j], unitID, "CM-00-04-003-04"); unitID = "10-12-11-11-11"; j++; } } } catch (Exception e) { e.printStackTrace(); } // System.out.println("End getjdbcConnectionPoolMaxCapacity"); } /** * The The current total active connections of this JDBC pool: * .1.3.6.1.4.1.140.625.190.1.25 JDBC 连接池的已经激活的连接数: * .1.3.6.1.4.1.140.625.190.1.25 */ private void getjdbcConnectionPoolActiveConnectionsCurrentCount() { String unitID = "10-12-11-11-11"; String connDomain = ""; String connServerName = ""; String hostName = ""; String[] active = null; System.out .println("Begin getjdbcConnectionPoolActiveConnectionsCurrentCount"); Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.140.625.190.1.25", true); Vector vc_ConnPollName = walkKPIInfo(".1.3.6.1.4.1.140.625.190.1.15", false); // connPool // Name int k = 0; active = new String[vc_active.size()]; for (Iterator activee = vc_active.iterator(); activee.hasNext();) { active[k] = (String) activee.next(); k++; } int j = 0; Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain // name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); connDomain = domain[domain.length - 2]; // get Domain Vector vc_ServerName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.15.32", false); // server // name. connServerName = (String) vc_ServerName.elementAt(0); Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host // name hostName = (String) vc_hostName.elementAt(0); this.hostname = hostName; for (Iterator connName = vc_ConnPollName.iterator(); connName.hasNext();) { String temp = (String) connName.next(); unitID = unitID + ":" + hostName + "-" + connServerName + "-" + connDomain + "-" + connServerName + "-" + temp; setResult(active[j], unitID, "PM-00-04-003-03"); unitID = "10-12-11-11-11"; j++; } for (Iterator d = vc_active.iterator(); d.hasNext();) { System.out.println("vc_active-----" + (String) d.next().toString()); } // String count = (String) vc_active.elementAt(0); // System.out.println("ActiveConncount=" + count); // setResult(count, "unitID", "PM-00-04-003-03"); System.out .println("End getjdbcConnectionPoolActiveConnectionsCurrentCount"); } /** * 1. 函数说明: The using rate of the current JDBC pool: JDBC 连接池的连接使用率=JDBC * 连接池的已经激活的连接数/JDBC 连接池的最大容量*100 = (.1.3.6.1.4.1.140.625.190.1.25) * * 100F/(.1.3.6.1.4.1.140.625.190.1.60) 2. JDBC * 连接池的已经激活的连接数:.1.3.6.1.4.1.140.625.190.1.25 3. JDBC * 连接池的最大容量:.1.3.6.1.4.1.140.625.190.1.60 * */ private void getJdbcPoolUseRate(HashMap params) { try { String connPoolName = ""; String connDomain = ""; String connServerName = ""; String hostName = ""; String[] max_ = null; String[] active_ = null; System.out.println("Begin getJdbcPoolUseRate"); /* * int poolNum = * Integer.parseInt(weblogicconfig.getString("JDBCPOOL.NUM.WEBLOGIC.server."+i).trim()); * System.out.println("poolNum="+poolNum+","+"JDBCPOOL.NUM.WEBLOGIC.server."+i); */ int poolNum = Integer .parseInt(((String) params.get("JDBCPOOL.NUM")).trim()); if (poolNum == 1) { Vector vc_Max = walkKPIInfo(".1.3.6.1.4.1.140.625.190.1.55", false); Vector vc_ConnPollName = walkKPIInfo( ".1.3.6.1.4.1.140.625.190.1.15", false); // connPool // Name connPoolName = (String) vc_ConnPollName.elementAt(0); Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); connDomain = domain[domain.length - 2]; // get Domain Vector vc_ServerName = walkKPIInfo( ".1.3.6.1.4.1.140.625.360.1.15.32", false); // server // name String[] connName = new String[vc_ConnPollName.size()]; int m = 0; for (Iterator itera = vc_ConnPollName.iterator(); itera .hasNext();) { connName[m] = itera.next().toString(); m++; } // name. connServerName = (String) vc_ServerName.elementAt(0); Vector vc_hostName = walkKPIInfo( ".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); String unitID = "10-12-11-11-11:"; max_ = new String[vc_Max.size()]; int i = 0; int j = 0; if (vc_Max.size() > 0) { int Max_num = Integer.parseInt(((String) vc_Max .elementAt(0)).trim());// get max conn count Vector vc_Active = walkKPIInfo( ".1.3.6.1.4.1.140.625.190.1.25", false); active_ = new String[vc_Active.size()]; for (Iterator active = vc_Active.iterator(); active .hasNext();) { active_[i] = (String) active.next(); System.out.println("active--" + active_[i]); i++; } for (Iterator max = vc_Max.iterator(); max.hasNext();) { max_[j] = (String) max.next(); System.out.println("max--" + max_[j]); j++; } if (vc_Active.size() > 0) { int Active_num = Integer.parseInt(((String) vc_Active .elementAt(0)).trim());// get active conn count float userate = 0; if (Max_num != 0) { for (int k = 0, l = 0; k < max_.length; k++) { unitID = unitID + hostName + "-" + connServerName + "-" + connDomain + "-" + connServerName + "-" + connName[k]; System.out.println("active_[k]--" + Float.parseFloat(active_[k])); System.out.println("max_[k]]--" + Float.parseFloat(max_[k])); userate = Float.parseFloat(active_[k]) * 100F / Float.parseFloat(max_[k]); setResult(String.valueOf(userate), unitID, "PM-00-04-003-02"); unitID = "10-12-11-11-11:"; System.out.println("userrate=" + userate); } System.out.println("JdbcPoolUseRate=" + userate); } } } }// end of " if(poolNum ==1)": I have to configure one connection // pool // of one server for testing. System.out.println("End getJdbcPoolUseRate"); } catch (Exception e) { e.printStackTrace(); } } /** * 执行队列的名字(一个table4个值): .1.3.6.1.4.1.140.625.361.1.15 * 10-12-11-10-10:-->10-12-11-11-10: */ private void collCluser() { String hostName = ""; String connDomain = ""; String flag = "true"; // String oid = // ((String)hs.get("executeQueuePendingRequestCount.OID")).trim(); try { Vector rc = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.80", false); Vector vc_Domain = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.45", false); // domain name String[] domain = ((String) vc_Domain.elementAt(0)).split("/"); connDomain = domain[domain.length - 2]; // get Domain Vector vc_hostName = walkKPIInfo(".1.3.6.1.4.1.140.625.360.1.70", false); // host name hostName = (String) vc_hostName.elementAt(0); String unitID = "10-12-11-11-10:" + hostName + "-" + this.servicename + "-" + Formater.neatenunitid(connDomain) + "-runmodel"; String requestNum = (String) rc.elementAt(0); if (((String) rc.elementAt(0)).endsWith("ClusterRuntime")) { flag = "false"; } setResult(flag, unitID, "CM-00-04-003-01"); } catch (Exception e) { logger.error(e); } } /** * @author pc103 * @date 2006-07-21 * @param oid * @param bool * @return vector 参数说明书: oid-----对应weblogic控制台监控的性能指标id(关键) bool----无多大用处 * 功能:储存各采集结果 返回类型:vector * */ public Vector walkKPIInfo(String oid, boolean bool) { Vector tmp_result = new Vector(); try { Vector tmp_oid = new Vector(); target.setObjectID(oid); target.oidList[0] = new com.adventnet.snmp.snmp2.SnmpOID(oid);// .1.3.6.1.4.1.11.2.3.1.2.2.1 // Each // entry // contains // objects // for a // particular // file // system.(HP) int maxtry = 0; com.adventnet.snmp.snmp2.SnmpOID[] oidList = target .getSnmpOIDList(); // System.out.println("oidList.length="+oidList.length); if (oidList == null) { System.out.println("oidList is null"); return null; } else { SnmpOID rootoid = oidList[0]; SnmpOID curroid = null; while (maxtry++ < 3000) { // limit the max getnexts to 5000 String result1[] = target.snmpGetNextList(); if (result1 == null) { target.oidList[0] = curroid; continue; // break; } if (!SnmpTarget.isInSubTree(rootoid, target.getSnmpOID())) break; // check first column // System.out.println("result1.length=" +result1.length); for (int i = 0; i < result1.length; i++) { // print the // values // System.out.println(target.getObjectID(i) + ": " // + result1[i]); tmp_result.add(result1[i]); tmp_oid.add(target.getObjectID(i)); } if (result1[0].compareTo("NULL") == 0) break; } if (maxtry == 1) { // we did not get a valid row System.err .println("Request failed, timed out or no available data(" + oid + "). \n " + target.getErrorString()); } } } catch (Exception e) { e.printStackTrace(); } return tmp_result; } /** * 1. 得到OID中特有的惟一标识的那部分 2. */ String getQueueString(String str1, int i) { String str_unique = str1.substring(i); return str_unique; } /** * @param weblogicip * @param servername * @param port * @param hostname * @param community * @exception * @express 建立与weblogic7.0的初始连接,特别注意port指的是 * weblogic的snmp的port,并非weblogic所开服务监听的port */ public void initWeblogic(String weblogicip, String servername, int port, String hostname, String community) { try { this.ObjectIP = weblogicip; System.out.println("weblogicip=" + weblogicip); // this.KBP_ID = kbp_id; // String authProtocol = new String("NO_AUTH"); // Use an SNMP target bean to perform SNMP operations target = new SnmpTarget(); // target.setLoadFromCompiledMibs(true); target.setDebug(DEBUG); target.setSnmpVersion(SnmpTarget.VERSION1); target.setTargetHost(ObjectIP); // set the agent hostname // target.setTargetHost(hostname); // set the agent hostname(ip or // hostname):ip of HP workstation System.out.println("hostname=" + hostname); // target.setTargetHost( "SUNE450" ); // set the agent hostname: // solaris // target.setTargetHost( "iona" ); // set the agent hostname: // windows /* SUNE450 是主机的hostname. */ String weblogic_COMMUNITY = community.trim() + "@".trim() + servername.trim(); System.out.println("weblogic_COMMUNITY=" + weblogic_COMMUNITY); target.setCommunity(weblogic_COMMUNITY); // target.setCommunity( COMMUNITY); /** * 关于weblogic多多服务器情况下,如何采集不同的server的值的方法,主要 * 就是设置COMMUNITY的值,在这个我以admin server with clustered servers的 * 情况来说明,domain name=mydomain2,administrtation server = myserver, * managed server = server1. * 1.如果取myserver的相关的OID的值,COMMUNITY="public"; * 2.如果取server1的相关的OID的值,COMMUNITY="public@server1"; * 3.如果取整个domain的所有server的相关的OID的值,COMMUNITY="public@mydomain2"; */ target.setTargetPort(port); System.out.println("port=" + port); // target.setRetries( RETRIES ); // target.setTimeout( TIMEOUT ); // if (target.getSnmpVersion() == target.VERSION3) { // target.create_v3_tables(); // } } catch (Exception e) { e.printStackTrace(); } } /** * 释放initWeblogic(String weblogicip,String servername,int port, String * hostname,String community) 申请的资源 */ public void release() { target.releaseResources(); } }