/*
  * 根据IP和是否要显示于日报表的标志位查询
  *
  */
 public Hashtable getByAlarmflag(Integer smsflag) {
   List list = new ArrayList();
   Session session = null;
   Hashtable retValue = new Hashtable();
   try {
     rs =
         conn.executeQuery(
             "select * from system_oraspaceconf where sms=" + smsflag + " order by ipaddress");
     // Query query=session.createQuery("from Oraspaceconfig oraspaceconfig where
     // oraspaceconfig.sms="+smsflag+" order by oraspaceconfig.ipaddress");
     while (rs.next()) list.add(loadFromRS(rs));
     if (list != null && list.size() > 0) {
       for (int i = 0; i < list.size(); i++) {
         Oraspaceconfig oraspaceconfig = (Oraspaceconfig) list.get(i);
         String ipaddr = oraspaceconfig.getIpaddress();
         String[] iparry = ipaddr.split(":");
         IpTranslation tranfer = new IpTranslation();
         String[] tip = tranfer.getIpFromHex(iparry[0]);
         retValue.put(
             tip[0]
                 + "."
                 + tip[1]
                 + "."
                 + tip[2]
                 + "."
                 + tip[3]
                 + ":"
                 + iparry[1]
                 + ":"
                 + oraspaceconfig.getSpacename(),
             oraspaceconfig);
         // SysLogger.info(tip[0]+"."+tip[1]+"."+tip[2]+"."+tip[3]+":"+iparry[1]+":"+oraspaceconfig.getSpacename()+"===="+oraspaceconfig.getSpacename());
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   // TODO Auto-generated method stub
   return retValue;
 }
  /*
   *
   * 从内存和数据库表里获取每个IP的端口信息,存入端口配置表里
   */
  public void fromLastToOraspaceconfig() throws Exception {
    List list = new ArrayList();
    List list1 = new ArrayList();
    List shareList = new ArrayList();
    Hashtable oraspacehash = new Hashtable();
    Session session = null;
    Vector configV = new Vector();
    IpTranslation tranfer = new IpTranslation();
    try {
      // 从ORASPACCE配置表里获取列表
      rs = conn.executeQuery("select * from system_oraspaceconf order by ipaddress");
      while (rs.next()) list1.add(loadFromRS(rs));
      if (list1 != null && list1.size() > 0) {
        for (int i = 0; i < list1.size(); i++) {
          Oraspaceconfig oraspaceconfig = (Oraspaceconfig) list1.get(i);
          // IP:表空间名称

          oraspacehash.put(
              oraspaceconfig.getIpaddress() + ":" + oraspaceconfig.getSpacename(), oraspaceconfig);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    try {

      // 从内存中得到所有ORASPACCE采集信息
      Hashtable sharedata = ShareData.getOraspacedata();

      // 从数据库得到监视ORASPACCE列表
      DBDao dbdao = new DBDao();
      DBTypeDao typedao = new DBTypeDao();
      DBTypeVo typevo = typedao.findByDbtype("oracle");
      shareList = dbdao.getDbByTypeMonFlag(typevo.getId(), 1);
      if (shareList != null && shareList.size() > 0) {
        for (int i = 0; i < shareList.size(); i++) {
          //					OraclePartsDao oracleDao=null;
          try {
            DBVo dbmonitorlist = (DBVo) shareList.get(i);
            //						 oracleDao=new OraclePartsDao();
            //						List<OracleEntity> oracles=oracleDao.findOracleParts(dbmonitorlist.getId());
            //						for(OracleEntity ora:oracles){
            //
            //						}
            if (sharedata.get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId()) != null) {
              Vector tableinfo_v =
                  (Vector)
                      sharedata.get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
              if (tableinfo_v == null) continue;
              Hashtable spaces = new Hashtable();
              spaces.put("ip", dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
              spaces.put("tableinfo_v", tableinfo_v);
              list.add(spaces);
            }
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            //						if(oracleDao!=null)
            //						  oracleDao.close();
          }
        }
      }
      // 判断采集到的ORASPACCE信息是否已经在ORASPACCE配置表里已经存在,若不存在则加入
      if (list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
          Hashtable spaces = (Hashtable) list.get(i);
          if (spaces != null && spaces.size() > 0) {
            String ip = (String) spaces.get("ip");
            Vector tableinfo_v = (Vector) spaces.get("tableinfo_v");
            if (tableinfo_v != null && tableinfo_v.size() > 0) {
              Oraspaceconfig oraspaceconfig = null;
              for (int k = 0; k < tableinfo_v.size(); k++) {
                Hashtable return_value = (Hashtable) tableinfo_v.get(k);
                String spacename = (String) return_value.get("tablespace");
                String[] iparr = ip.split(":");
                String tip = tranfer.formIpToHex(iparr[0]);
                if (!oraspacehash.containsKey(tip + ":" + iparr[1] + ":" + spacename)) {
                  oraspaceconfig = new Oraspaceconfig();
                  oraspaceconfig.setSpacename(spacename);
                  oraspaceconfig.setBak("");
                  oraspaceconfig.setIpaddress(tip + ":" + iparr[1]);
                  oraspaceconfig.setLinkuse("");
                  oraspaceconfig.setAlarmvalue(90);
                  oraspaceconfig.setSms(new Integer(0)); // 0:不告警 1:告警,默认的情况是不发送短信
                  oraspaceconfig.setReportflag(new Integer(0)); // 0:不存在于报表 1:存在于报表,默认的情况是不存在于报表
                  conn = new DBManager();
                  save(oraspaceconfig);
                  // configV.add(oraspaceconfig);
                  oraspacehash.put(tip + ":" + iparr[1] + ":" + spacename, oraspaceconfig);
                }
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    // TODO Auto-generated method stub
  }
Esempio n. 3
0
  private void ajaxUpdate_availability() {
    String buffercache = null;
    DBVo vo = new DBVo();
    DBDao dao = new DBDao();
    String id = getParaValue("id");
    try {
      vo = (DBVo) dao.findByID(id);
    } catch (Exception e) {

    } finally {
      dao.close();
    }
    String sid = getParaValue("sid");
    String pingconavg = "0";
    double avgpingcon = 0;
    Hashtable ConnectUtilizationhash = new Hashtable();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String time1 = sdf.format(new Date());

    String starttime1 = time1 + " 00:00:00";
    String totime1 = time1 + " 23:59:59";
    I_HostCollectData hostmanager = new HostCollectDataManager();
    try {
      ConnectUtilizationhash =
          hostmanager.getCategory(id, "ORAPing", "ConnectUtilization", starttime1, totime1);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    if (ConnectUtilizationhash.get("avgpingcon") != null)
      pingconavg = (String) ConnectUtilizationhash.get("avgpingcon");
    if (pingconavg != null) {
      pingconavg = pingconavg.replace("%", "");
    }
    avgpingcon = new Double(pingconavg + "").doubleValue();
    int percent1 = Double.valueOf(avgpingcon).intValue();
    int percent2 = 100 - percent1;
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("percent1", percent1);
    map.put("percent2", percent2);
    Hashtable memPerfValue = new Hashtable();
    dao = new DBDao();
    String hex = IpTranslation.formIpToHex(vo.getIpAddress());
    String serverip = hex + ":" + sid;
    try {
      memPerfValue = dao.getOracle_nmsoramemperfvalue(serverip);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      dao.close();
    }
    int intbuffercache = 0;
    if (memPerfValue.containsKey("buffercache")) {
      buffercache = (String) memPerfValue.get("buffercache");
      intbuffercache = Integer.parseInt(buffercache);
    }
    if (memPerfValue.containsKey("buffercache") && memPerfValue.get("buffercache") != null) {
      buffercache = (String) memPerfValue.get("buffercache");
    }
    int intdictionarycache = 0;
    if (memPerfValue.containsKey("dictionarycache")
        && memPerfValue.get("dictionarycache") != null) {
      intdictionarycache = (int) (Float.parseFloat(buffercache));
    }
    String librarycache = "0";
    int intlibrarycache = 0;
    if (memPerfValue.containsKey("librarycache") && memPerfValue.get("librarycache") != null) {
      librarycache = (String) memPerfValue.get("librarycache");
      intlibrarycache = (int) (Float.parseFloat(librarycache));
    }
    String pctmemorysorts = "0";
    int intpctmemorysorts = 0;
    if (memPerfValue.containsKey("pctmemorysorts") && memPerfValue.get("pctmemorysorts") != null) {
      pctmemorysorts = (String) memPerfValue.get("pctmemorysorts");
      intpctmemorysorts = (int) (Float.parseFloat(pctmemorysorts));
    }
    String pctbufgets = "0";
    int intpctbufgets = 0;
    if (memPerfValue.containsKey("pctbufgets") && memPerfValue.get("pctbufgets") != null) {
      pctbufgets = (String) memPerfValue.get("pctbufgets");
      intpctbufgets = (int) (Float.parseFloat(pctbufgets));
    }
    map.put("pctbufgets", intpctbufgets);
    map.put("pctmemorysorts", intpctmemorysorts);
    map.put("librarycache", intlibrarycache);
    map.put("dictionarycache", intdictionarycache);
    map.put("buffercache", intbuffercache);
    map.put("cpuper", intbuffercache);
    JSONObject json = JSONObject.fromObject(map);
    out.print(json);
    out.flush();
  }
  @SuppressWarnings("unchecked")
  public Hashtable collect_Data(NodeGatherIndicators nodeGatherIndicators) {
    Hashtable returndata = new Hashtable();
    String htKey = "dbio";
    List dbmonitorlists = new ArrayList();
    dbmonitorlists = ShareData.getDBList();
    DBVo dbmonitorlist = new DBVo();
    if (dbmonitorlists != null && dbmonitorlists.size() > 0) {
      for (int i = 0; i < dbmonitorlists.size(); i++) {
        DBVo vo = (DBVo) dbmonitorlists.get(i);
        if (vo.getId() == Integer.parseInt(nodeGatherIndicators.getNodeid())) {
          dbmonitorlist = vo;
          break;
        }
      }
    }
    if (dbmonitorlist != null) {
      if (dbmonitorlist.getManaged() == 0) {
        // 如果未被管理,不采集,user信息为空
        return returndata;
      }
      String serverip = dbmonitorlist.getIpAddress();
      String[] args = new String[] {"name", "filename", "pyr", "pbr", "pyw", "pbw", "mon_time"};
      returndata = LogParser.parse(this, dbmonitorlist, htKey, args);

      // 更新内存
      if (!(ShareData.getSharedata()
          .containsKey(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId()))) {
        ShareData.getSharedata()
            .put(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId(), returndata);
      } else {
        Hashtable oracleHash =
            (Hashtable)
                ShareData.getSharedata()
                    .get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
        oracleHash.put("dbio", returndata.get(htKey));
      }

      // ----------------------------------保存到数据库及告警 start
      Vector info_v = (Vector) returndata.get(htKey);
      if (info_v != null && !info_v.isEmpty()) {
        String hex = IpTranslation.formIpToHex(dbmonitorlist.getIpAddress());
        serverip = hex + ":" + dbmonitorlist.getId();

        try {
          Calendar tempCal = Calendar.getInstance();
          Date cc = tempCal.getTime();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          String montime = sdf.format(cc);
          String deletesql = "delete from nms_oradbio where serverip='" + serverip + "'";
          GathersqlListManager.Addsql(deletesql);

          String name = null;
          String pyr = null;
          String pbr = null;
          String pyw = null;
          String pbw = null;

          String insertsql = null;

          for (int j = 0; j < info_v.size(); j++) {
            Hashtable dbiohash = (Hashtable) info_v.get(j);
            name = "";
            pyr = "";
            pbr = "";
            pyw = "";
            pbw = "";

            String filename = (String) dbiohash.get("filename");
            filename = filename.replaceAll("\\\\", "/");
            name = (String) dbiohash.get("name");
            pyr = (String) dbiohash.get("pyr");
            pbr = (String) dbiohash.get("pbr");
            pyw = (String) dbiohash.get("pyw");
            pbw = (String) dbiohash.get("pbw");

            insertsql =
                "insert into nms_oradbio(serverip, name, filename, pyr, pbr, pyw, pbw,mon_time) "
                    + "values('"
                    + serverip
                    + "','"
                    + name
                    + "','"
                    + filename
                    + "','"
                    + pyr
                    + "','"
                    + pbr
                    + "','"
                    + pyw
                    + "','"
                    + pbw;
            if ("mysql".equalsIgnoreCase(SystemConstant.DBType)) {
              insertsql = insertsql + "','" + montime + "')";
            } else if ("oracle".equalsIgnoreCase(SystemConstant.DBType)) {
              insertsql = insertsql + "',to_date('" + montime + "','YYYY-MM-DD HH24:MI:SS'))";
            }
            GathersqlListManager.Addsql(insertsql);
          }
          // ---------------------------------dbio不需告警

        } catch (Exception e) {
          e.printStackTrace();
        }

        // ----------------------------------保存到数据库及告警 end
      }
    }
    return returndata;
  }