afunms

My Software,My Dream—Forge a more perfect NMS product.

tomcat监视

        今天要做一个tomcat监视,参考了ens和华中电力的相关代码,发现他们的做法都是先取到html代码,然后从这html代码中提取自己想要的数据,这太麻烦了,我在想有没有更好的办法。
        研究了tomcat的源码后,终于有了发现。我要的数据可以通过以下代码得到:
       --------server information------------------ 
       服务器信息:ServerInfo.getServerInfo()
        jvm版本:System.getProperty("java.runtime.version")
        jvm vendor:System.getProperty("java.vm.vendor")
        操作系统:System.getProperty("os.name")
        操作系统版本:System.getProperty("os.version")

       --------jvm information------------------
       free_memory:Runtime.getRuntime().freeMemory()
       total_memory:Runtime.getRuntime().totalMemory()
       max_memory:Runtime.getRuntime().maxMemory()

       ---------应用列表-------------------
      private Element createApplications()
 {
  Element applications = null;
  try
  {
   applications = new Element("applications");
   
   MBeanServer mBeanServer = Registry.getServer();
         ObjectName queryHosts = new ObjectName("*:j2eeType=WebModule,*");
         Set hostsON = mBeanServer.queryNames(queryHosts, null);

   Iterator iterator = hostsON.iterator();
   while(iterator.hasNext())
   {
    ObjectName contextON = (ObjectName)iterator.next();
          String webModuleName = contextON.getKeyProperty("name");                     
    String hostName = null;
          String contextName = null;
          if(webModuleName.startsWith("//"))
               webModuleName = webModuleName.substring(2);
         
          int slash = webModuleName.indexOf("/");
          if(slash != -1)
          {
              hostName = webModuleName.substring(0, slash);
              contextName = webModuleName.substring(slash);
          }
    else continue;
 
          if("/".equals(contextName)) continue;
         
          Element oneApp = new Element("application_information");
          try
          {       
              ObjectName queryManager = new ObjectName(contextON.getDomain() + ":type=Manager,path=" + contextName + ",host=" + hostName + ",*");
              Set managersON = mBeanServer.queryNames(queryManager, null);
              ObjectName managerON = null;
              for(Iterator iterator2 = managersON.iterator(); iterator2.hasNext();)
                 managerON = (ObjectName)iterator2.next();
 
              Element wmn = new Element("web_module_name");
              wmn.setText(contextName.substring(1));
         
              Element as = new Element("active_sessions");
           as.setText(mBeanServer.getAttribute(managerON, "activeSessions").toString());
         
           Element sc = new Element("session_count");
           sc.setText(mBeanServer.getAttribute(managerON, "sessionCounter").toString());
         
           Element mas = new Element("max_active_sessions");
           mas.setText(mBeanServer.getAttribute(managerON, "maxActive").toString()); 
           oneApp.addContent(wmn);
           oneApp.addContent(as);
           oneApp.addContent(sc);
           oneApp.addContent(mas);
           applications.addContent(oneApp);
          }
          catch(Exception e)
          {
           System.out.println("Error in TomcatMonitor.createApplications()-2");
          }//end_try
   }//end_while
  }
        catch(Exception e)
        {
         System.out.println("Error in TomcatMonitor.createApplications()-1");
        }//end_try
        return applications;
 }

posted on 2006-12-04 11:18 afunms 阅读(388) 评论(3)  编辑  收藏

Feedback

# re: tomcat监视 2008-04-21 15:29 chenhao

没想到我要解决的问题,你两年前都已经研究的这么透彻了,惭愧啊。还有,原来你一直这么有目标阿,终于知道afunms大概的意思了。刚才在google上搜相关资料,看到afunms就是一惊,难道真的那么巧,进来一看,果然是你,在那边生活的还好吗?  回复  更多评论   

# re: tomcat监视 2008-04-21 15:37 afu

@chenhao
呵呵,能告诉我你是哪位吗?
  回复  更多评论   

# re: tomcat监视 2008-04-21 15:48 chenhao

nch的classmate,cqep的参与者,@dhcc  回复  更多评论   



只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜