/** 增加一个新的节点(用于发现之后,或者手动增加一个节点) */ public void addNodes(String index, String image, String ip, String alias, String x, String y) { Element eleNode = new Element("node"); Element eleId = new Element("id"); Element eleImg = new Element("img"); Element eleX = new Element("x"); Element eleY = new Element("y"); Element eleAlias = new Element("alias"); Element eleInfo = new Element("info"); Element eleMenu = new Element("menu"); eleId.setText(index); eleImg.setText(image); eleX.setText(x); eleY.setText(y); eleAlias.setText(alias); StringBuffer msg = new StringBuffer(200); msg.append("<font color='green'>索引:"); msg.append(index); msg.append("</font><br>"); msg.append("描述:"); msg.append(alias); msg.append("<br>"); eleInfo.setText(msg.toString()); eleMenu.setText(PanelNodeHelper.getMenuItem(index, ip)); eleNode.addContent(eleId); eleNode.addContent(eleImg); eleNode.addContent(eleX); eleNode.addContent(eleY); eleNode.addContent(eleAlias); eleNode.addContent(eleInfo); eleNode.addContent(eleMenu); nodes.addContent(eleNode); }
public void collect_data(String id, Hashtable gatherHash) { Hashtable data_ht = new Hashtable(); String jvm_utilization = "0"; try { ServerStream serverstream = new ServerStream(); Hashtable returnVal = new Hashtable(); String ipaddress = ""; Tomcat node = new Tomcat(); TomcatDao dao = new TomcatDao(); try { node = (Tomcat) dao.findByID(id); } catch (Exception e) { } finally { dao.close(); } try { com.afunms.polling.node.Tomcat tc = new com.afunms.polling.node.Tomcat(); BeanUtils.copyProperties(tc, node); ipaddress = tc.getIpAddress(); com.afunms.polling.node.Tomcat tnode = (com.afunms.polling.node.Tomcat) PollingEngine.getInstance().getTomcatByIP(ipaddress); Calendar date = Calendar.getInstance(); Date cc = date.getTime(); String tempsenddate = sdf.format(cc); // 初始化Tomcat服务的状态 tnode.setLastTime(tempsenddate); tnode.setAlarm(false); tnode.getAlarmMessage().clear(); tnode.setStatus(0); StringBuffer tmp = new StringBuffer(); tmp.append(tc.getIpAddress()); tmp.append(","); tmp.append(tc.getPort()); tmp.append(","); tmp.append(tc.getUser()); tmp.append(" , "); tmp.append(tc.getPassword()); returnVal.put(String.valueOf(0), tmp.toString()); } catch (Exception e) { e.printStackTrace(); } String liststr = serverstream.validServer(returnVal); if ("".equals(liststr)) { try { com.afunms.polling.node.Tomcat tc = new com.afunms.polling.node.Tomcat(); BeanUtils.copyProperties(tc, node); // if (data_ht==null){ // 需要增加邮件服务所在的服务器是否能连通 Host host = (Host) PollingEngine.getInstance().getNodeByIP(node.getIpAddress()); Vector ipPingData = (Vector) ShareData.getPingdata().get(node.getIpAddress()); if (ipPingData != null) { Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0); Calendar tempCal = (Calendar) pingdata.getCollecttime(); Date cc = tempCal.getTime(); String _time = sdf.format(cc); String lastTime = _time; String pingvalue = pingdata.getThevalue(); if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0"; double pvalue = new Double(pingvalue); if (pvalue == 0) { // 主机服务器连接不上*********************************************** com.afunms.polling.node.Tomcat tnode = (com.afunms.polling.node.Tomcat) PollingEngine.getInstance().getTomcatByIP(ipaddress); tnode.setAlarm(true); tnode.setStatus(1); List alarmList = tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); tnode.getAlarmMessage().add("TOMCAT服务停止"); String sysLocation = ""; try { SmscontentDao eventdao = new SmscontentDao(); String eventdesc = "TOMCAT服务(" + tnode.getAlias() + " IP:" + tnode.getAdminIp() + ")" + "的TOMCAT服务停止"; eventdao.createEventWithReasion( "poll", tnode.getId() + "", tnode.getAdminIp() + "(" + tnode.getAdminIp() + ")", eventdesc, 3, "tomcat", "ping", "所在的服务器连接不上"); } catch (Exception e) { e.printStackTrace(); } } else { com.afunms.polling.node.Tomcat tnode = (com.afunms.polling.node.Tomcat) PollingEngine.getInstance().getTomcatByIP(ipaddress); tnode.setAlarm(true); tnode.setStatus(3); List alarmList = tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); tnode.getAlarmMessage().add("TOMCAT服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("TomcatPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); TomcatDao tomcatdao = new TomcatDao(); try { tomcatdao.createHostData(hostdata); } catch (Exception e) { e.printStackTrace(); } finally { tomcatdao.close(); } } } else { com.afunms.polling.node.Tomcat tnode = (com.afunms.polling.node.Tomcat) PollingEngine.getInstance().getTomcatByIP(ipaddress); tnode.setAlarm(true); tnode.setStatus(3); List alarmList = tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); tnode.getAlarmMessage().add("TOMCAT服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("TomcatPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); TomcatDao tomcatdao = new TomcatDao(); try { tomcatdao.createHostData(hostdata); } catch (Exception e) { e.printStackTrace(); } finally { tomcatdao.close(); } } // } createSMS("tomcat", tc); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("TomcatPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("100"); TomcatDao tomcatdao = new TomcatDao(); try { tomcatdao.createHostData(hostdata); } catch (Exception e) { e.printStackTrace(); } finally { tomcatdao.close(); } } String[] pos_s = liststr.split(","); for (int list_i = 0; list_i < pos_s.length - 1; list_i++) { String tmps = returnVal.get(pos_s[list_i]).toString(); String[] serverinfo = tmps.split(","); serverstream.foundData(serverinfo[0], serverinfo[1], serverinfo[2], serverinfo[3]); data_ht = serverstream.data_ht; TomcatDao tomcatdao = new TomcatDao(); Hashtable sendeddata = ShareData.getSendeddata(); try { Calendar time = Calendar.getInstance(); String lasttime = data_ht.get("mon_time").toString(); String nexttime = data_ht.get("nexttime").toString(); String server = data_ht.get("server").toString(); String jvm = data_ht.get("jvm").toString(); String ip = data_ht.get("ip").toString(); String port = data_ht.get("port").toString(); String portsum1 = data_ht.get("portsum1").toString(); String portsum2 = data_ht.get("portsum2").toString(); String portdetail1 = data_ht.get("portdetail1").toString(); String portdetail2 = data_ht.get("portdetail2").toString(); if (data_ht != null) { int jvm_memoryuiltillize = 0; String[] temjvm = jvm.split(","); double freememory = Double.parseDouble(temjvm[0].trim()); double totalmemory = (double) Double.parseDouble(temjvm[1].trim()); double maxmemory = (double) Double.parseDouble(temjvm[2].trim()); jvm_memoryuiltillize = (int) Math.rint((totalmemory - freememory) * 100 / totalmemory); jvm_utilization = String.valueOf(jvm_memoryuiltillize); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ip); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("tomcat_jvm"); hostdata.setEntity("Utilization"); hostdata.setSubentity("jvm_utilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue(jvm_utilization); try { tomcatdao.createHostData(hostdata); if (sendeddata.containsKey("tomcat" + ":" + ip)) sendeddata.remove("tomcat" + ":" + ip); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { tomcatdao.close(); } } try { data_ht.put("jvm_utilization", jvm_utilization); ShareData.setTomcatdata(node.getIpAddress(), data_ht); } catch (Exception ex) { ex.printStackTrace(); } data_ht = null; } catch (Exception e) { e.printStackTrace(); } finally { } }
public boolean update(BaseVo baseVo) { Oraspaceconfig vo = (Oraspaceconfig) baseVo; boolean result = false; StringBuffer sql = new StringBuffer(); sql.append("update system_oraspaceconf set ipaddress='"); sql.append(vo.getIpaddress()); sql.append("',spacename='"); sql.append(vo.getSpacename()); sql.append("',linkuse='"); sql.append(vo.getLinkuse()); sql.append("',sms="); sql.append(vo.getSms()); sql.append(",bak='"); sql.append(vo.getBak()); sql.append("',reportflag="); sql.append(vo.getReportflag()); sql.append(",alarmvalue="); sql.append(vo.getAlarmvalue()); sql.append(" where id="); sql.append(vo.getId()); try { conn.executeUpdate(sql.toString()); result = true; } catch (Exception e) { result = false; SysLogger.error("OraspaceconfigDao:update()", e); } finally { conn.close(); } return result; }
public boolean save(BaseVo baseVo) { Oraspaceconfig vo = (Oraspaceconfig) baseVo; StringBuffer sql = new StringBuffer(100); sql.append( "insert into system_oraspaceconf(ipaddress,spacename,linkuse,sms,bak,reportflag,alarmvalue)values("); sql.append("'"); sql.append(vo.getIpaddress()); sql.append("','"); sql.append(vo.getSpacename()); sql.append("','"); sql.append(vo.getLinkuse()); sql.append("',"); sql.append(vo.getSms()); sql.append(",'"); sql.append(vo.getBak()); sql.append("',"); sql.append(vo.getReportflag()); sql.append(","); sql.append(vo.getAlarmvalue()); sql.append(")"); return saveOrUpdate(sql.toString()); }
/** 更新所有info项和image项 */ public void updateInfo(boolean isCustom) { I_HostLastCollectData hostlastmanager = new HostLastCollectDataManager(); List list = nodes.getChildren(); for (int i = 0; i < list.size(); i++) { Element eleNode = (Element) list.get(i); int id = Integer.valueOf(eleNode.getChildText("id")).intValue(); int direction = Integer.valueOf(eleNode.getChildText("direction")).intValue(); // Hashtable ipAllData = (Hashtable)ShareData.getSharedata().get(ipaddress); Vector vector = new Vector(); String[] netInterfaceItem = { "index", "ifDescr", "ifSpeed", "ifOperStatus", "OutBandwidthUtilHdx", "InBandwidthUtilHdx" }; try { vector = hostlastmanager.getInterface_share(ipaddress, netInterfaceItem, "index", "", ""); } catch (Exception e) { e.printStackTrace(); } SysLogger.info("######################################"); SysLogger.info("######### " + ipaddress + " ##############"); SysLogger.info("######################################"); if (vector != null && vector.size() > 0) { PortconfigDao dao = new PortconfigDao(); try { for (int m = 0; m < vector.size(); m++) { String[] strs = (String[]) vector.get(m); String ifname = strs[1]; String index = strs[0]; String OutBandwidthUtilHdx = strs[4]; String InBandwidthUtilHdx = strs[5]; String portuse = ""; Portconfig portconfig = null; try { portconfig = dao.getPanelByipandindex(ipaddress, index); } catch (Exception e) { } if (portconfig != null && portconfig.getLinkuse() != null && portconfig.getLinkuse().trim().length() > 0) { portuse = portconfig.getLinkuse(); } if (Integer.parseInt(index) == id) { // 当前端口 if (direction == 1) { // 向上方向的端口 if (strs[3].equalsIgnoreCase("up")) { // 端口启动 SysLogger.info(PanelNodeHelper.getUpUpImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getUpUpImage(1)); } else { // 端口未启动 SysLogger.info(PanelNodeHelper.getUpDownImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getUpDownImage(1)); } } else { // 向下方向的端口 if (strs[3].equalsIgnoreCase("up")) { // 端口启动 SysLogger.info(PanelNodeHelper.getDownUpImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getDownUpImage(1)); } else { // 端口未启动 SysLogger.info(PanelNodeHelper.getDownDownImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getDownDownImage(1)); } } eleNode.getChild("alias").setText(ifname); eleNode.getChild("ip").setText(ipaddress); StringBuffer msg = new StringBuffer(200); msg.append("<font color='green'>索引:"); msg.append(id); msg.append("</font><br>"); msg.append("描述:"); msg.append(ifname); msg.append("<br>"); msg.append("端口应用:"); msg.append(portuse); msg.append("<br>"); msg.append("入口流速:"); msg.append(InBandwidthUtilHdx); msg.append("<br>"); msg.append("出口流速:"); msg.append(OutBandwidthUtilHdx); msg.append("<br>"); SysLogger.info(msg.toString()); eleNode.getChild("info").setText(msg.toString()); eleNode.getChild("menu").setText(PanelNodeHelper.getMenuItem(index, ipaddress)); } } } catch (Exception e) { } finally { dao.close(); } } // nodes.addContent(i, eleNode); } if (isCustom) { writeXml(); return; } writeXml(); }
/** 增加一个新的节点(用于发现之后,或者手动增加一个节点) */ public void addNode( String index, String InBandwidthUtilHdx, String OutBandwidthUtilHdx, String image, String ip, String alias, String portuse, String x, String y) { Element eleNode = new Element("node"); Element eleId = new Element("id"); Element eleImg = new Element("img"); Element eleX = new Element("x"); Element eleY = new Element("y"); Element eleIp = new Element("ip"); Element eleAlias = new Element("alias"); Element eleInfo = new Element("info"); Element eleMenu = new Element("menu"); eleId.setText(index); if (image == null) eleImg.setText(PanelNodeHelper.getMenuItem(index, ipaddress)); else eleImg.setText(image); eleX.setText(x); eleY.setText(y); eleIp.setText(ip); eleAlias.setText(alias); StringBuffer msg = new StringBuffer(200); msg.append("<font color='green'>索引:"); msg.append(index); msg.append("</font><br>"); msg.append("描述:"); msg.append(alias); msg.append("<br>"); msg.append("应用:"); msg.append(portuse); msg.append("<br>"); msg.append("入口流速:"); msg.append(InBandwidthUtilHdx); msg.append("<br>"); msg.append("出口流速:"); msg.append(OutBandwidthUtilHdx); msg.append("<br>"); eleInfo.setText(msg.toString()); eleMenu.setText(PanelNodeHelper.getMenuItem(index, ip)); eleNode.addContent(eleId); eleNode.addContent(eleImg); eleNode.addContent(eleX); eleNode.addContent(eleY); eleNode.addContent(eleIp); eleNode.addContent(eleAlias); eleNode.addContent(eleInfo); eleNode.addContent(eleMenu); nodes.addContent(eleNode); }