打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
监控openfire数据

策划和开发需求openfire数据

(1)使用jvm暴露接口进行监控:
jvm接口介绍:http://blog.csdn.net/linghunhong/article/details/6438409

在ServerStarter.java中start方法最后添加mbean注册:

  1. <span style="white-space:pre">    </span>/** 
  2.             * 注册jmx 
  3.             *  
  4.             */  
  5.            MBeanServer ms =  ManagementFactory.getPlatformMBeanServer();  
  6.         ObjectName ofJmxName = new ObjectName("******:type=***");  
  7.            Class jmxClass = loader.loadClass(  
  8.                    "org.jmx.你的mbean实现");  
  9.            ms.registerMBean(jmxClass.newInstance(),ofJmxName);  
  10.            //注册结束  

你的mbean注册中可以实现对已有统计的接口,openfire统计相关都在StatisticsManager.java中

然后可以使用jdk提供的jconsole.exe监控查看

(2)数据库连接监控:

安装Load Statistic插件

(3)数据包聊天、登陆用户监控:

安装Monitoring Service插件

(4)

要求:统计消息转发的最长时长、最短时长、平均时长
统计IQ最长时长、最短时长、平均时长

方案:

1、利用openfire提供的PacketInterceptor,在interceptPacket方法中实现对IQ和Message的日志打印(具体打印内容自定义)。可以每个一段时间对日志内容进行分析

2、利用Monitoring Service提供的接口进行仿照开发

制作插件,主体部分逻辑如下:

  1. import java.util.concurrent.ConcurrentHashMap;  
  2. import java.util.concurrent.atomic.AtomicInteger;  
  3. import java.util.concurrent.atomic.AtomicLong;  
  4.   
  5. import org.jivesoftware.openfire.interceptor.InterceptorManager;  
  6. import org.jivesoftware.openfire.interceptor.PacketInterceptor;  
  7. import org.jivesoftware.openfire.session.Session;  
  8. import org.jivesoftware.openfire.stats.Statistic;  
  9. import org.jivesoftware.openfire.stats.StatisticsManager;  
  10. import org.jivesoftware.openfire.stats.i18nStatistic;  
  11. import org.picocontainer.Startable;  
  12. import org.xmpp.packet.IQ;  
  13. import org.xmpp.packet.Message;  
  14. import org.xmpp.packet.Packet;  
  15.   
  16. /** 
  17.  * Creates and manages Enteprise-specific statistics, specifically: <ul> 
  18.  *      message 转发最长时间、最短时间、平均时间、所有时间、数目 
  19.  *       
  20.  * </ul> 
  21.  * 
  22.  * @author  
  23.  */  
  24. public class StatisticsModule implements Startable {  
  25.     //message 统计相关key  
  26.     public static final String MESSAGE_COUNT_KEY = "m_count";  
  27.     public static final String MESSAGE_LONGEST_TIME_KEY = "m_longest_time";  
  28.     public static final String MESSAGE_SHORTEST_TIME_KEY = "m_shortest_time";  
  29.     public static final String MESSAGE_ALL_TIME_KEY = "m_all_time";  
  30.     public static final String MESSAGE_AVG_TIME_KEY = "m_avg_time";  
  31.      
  32.     //message统计存储  
  33.     private ConcurrentHashMap<String,AtomicLong> m_timeHash = new ConcurrentHashMap<String,AtomicLong>() ;  
  34.     private AtomicInteger message_Count = new AtomicInteger();  
  35.     private AtomicLong messgae_longestTime = new AtomicLong();  
  36.     private AtomicLong message_shortestTime = new AtomicLong(100000l);  
  37.     private AtomicLong message_allTime = new AtomicLong();  
  38.       
  39.       
  40.       
  41.     private StatisticsManager statisticsManager;  
  42.     private PacketInterceptor packetInterceptor;  
  43.       
  44.       
  45.       
  46. //    private long   
  47.     public void start() {  
  48.         // Retrieve instance of StatisticsManager  
  49.         statisticsManager = StatisticsManager.getInstance();  
  50.   
  51.         // Register a packet listener so that we can track packet traffic.  
  52.         packetInterceptor = new PacketInterceptor() {  
  53.             public void interceptPacket(Packet packet, Session session, boolean incoming,  
  54.                                         boolean processed)  
  55.             {  
  56.                 if(null==packet.getID()){  
  57.                     //没有id的不能统计  
  58.                     return;  
  59.                 }  
  60.                 // Only track processed packets so that we don't count them twice.  
  61.                 if (incoming&&!processed) {  
  62.                     if (packet instanceof Message) {  
  63.                         m_timeHash.put(packet.getID(),new AtomicLong(System.currentTimeMillis()));  
  64.                     }else if(packet instanceof IQ){  
  65.                         iq_timeHash.put(packet.getID(), new AtomicLong(System.currentTimeMillis()));  
  66.                     }  
  67.                       
  68.                 }else if(incoming&&processed){  
  69.                     if (packet instanceof Message) {  
  70.                         AtomicLong time = m_timeHash.get(packet.getID());  
  71.                         if(time!=null){  
  72.                             //end-start  
  73.                             //获取longest时间和shortest时间,比较,如果需要的话保存  
  74.                             //获取all,进行加法操作  
  75.                             //获取count进行自增1操作  
  76.                             //删除这个map  
  77.                             long t = System.currentTimeMillis()-time.longValue();  
  78.                             if(messgae_longestTime.longValue()<t){  
  79.                                 messgae_longestTime.set(t);  
  80.                             }  
  81.                             if(message_shortestTime.longValue()>t){  
  82.                                 message_shortestTime.set(t);  
  83.                             }  
  84.                             message_allTime.getAndAdd(t);  
  85.                             message_Count.incrementAndGet();  
  86.                             m_timeHash.remove(packet.getID());  
  87.                         }  
  88.                     }  
  89.                 }  
  90.             }  
  91.         };  
  92.         InterceptorManager.getInstance().addInterceptor(packetInterceptor);  
  93.   
  94.         // Register all statistics.  
  95.         addPacketNumberStatistic();  
  96.         addPacketAllTimeStatistic();  
  97.         addPacketLongestTimeStatistic();  
  98.         addPacketShortestTimeStatistic();  
  99.         addPacketAvgTimeStatistic();  
  100.           
  101.         
  102.     }  
  103.   
  104.     /** 
  105.      * Remove all registered statistics. 
  106.      */  
  107.     public void stop() {  
  108.   
  109.   
  110.         // Remove Statistic  
  111.         statisticsManager.removeStatistic(MESSAGE_COUNT_KEY);  
  112.         statisticsManager.removeStatistic(MESSAGE_LONGEST_TIME_KEY);  
  113.         statisticsManager.removeStatistic(MESSAGE_SHORTEST_TIME_KEY);  
  114.         statisticsManager.removeStatistic(MESSAGE_ALL_TIME_KEY);  
  115.         statisticsManager.removeStatistic(MESSAGE_AVG_TIME_KEY);  
  116.         
  117.   
  118.         statisticsManager = null;  
  119.   
  120.         // Remove the packet listener.  
  121.         InterceptorManager.getInstance().removeInterceptor(packetInterceptor);  
  122.         packetInterceptor = null;  
  123.         message_Count = null;  
  124.         messgae_longestTime = null;  
  125.         message_shortestTime = null;  
  126.         message_allTime = null;  
  127.         m_timeHash = null;  
  128.           
  129.         
  130.     }  
  131.   
  132.      
  133.     /** 
  134.      * Tracks the total number of message 
  135.      */  
  136.     private void addPacketAvgTimeStatistic() {  
  137.         // Register a statistic.  
  138.         Statistic packetTrafficStatistic = new i18nStatistic(MESSAGE_AVG_TIME_KEY, null, Statistic.Type.count) {  
  139.             public double sample() {  
  140.                 if(message_Count.longValue()==0){  
  141.                     return 0;  
  142.                 }  
  143.                 return message_allTime.longValue()/message_Count.longValue();  
  144.             }  
  145.   
  146.             public boolean isPartialSample() {  
  147.                 return true;  
  148.             }  
  149.         };  
  150.         statisticsManager.addStatistic(MESSAGE_AVG_TIME_KEY, packetTrafficStatistic);  
  151.     }  
  152.   
  153.     /** 
  154.      * Tracks the total number of message 
  155.      */  
  156.     private void addPacketNumberStatistic() {  
  157.         // Register a statistic.  
  158.         Statistic packetTrafficStatistic = new i18nStatistic(MESSAGE_COUNT_KEY, null, Statistic.Type.count) {  
  159.             public double sample() {  
  160.                 return message_Count.get();  
  161.             }  
  162.   
  163.             public boolean isPartialSample() {  
  164.                 return true;  
  165.             }  
  166.         };  
  167.         statisticsManager.addStatistic(MESSAGE_COUNT_KEY, packetTrafficStatistic);  
  168.     }  
  169.     /** 
  170.      * Tracks the total time of message 
  171.      */  
  172.     private void addPacketAllTimeStatistic() {  
  173.         // Register a statistic.  
  174.         Statistic packetTrafficStatistic = new i18nStatistic(MESSAGE_ALL_TIME_KEY, null, Statistic.Type.count) {  
  175.             public double sample() {  
  176.                 return message_allTime.get();  
  177.             }  
  178.   
  179.             public boolean isPartialSample() {  
  180.                 return true;  
  181.             }  
  182.         };  
  183.         statisticsManager.addStatistic(MESSAGE_ALL_TIME_KEY, packetTrafficStatistic);  
  184.     }  
  185.     /** 
  186.      * Tracks the longestTime of message 
  187.      */  
  188.     private void addPacketLongestTimeStatistic() {  
  189.         // Register a statistic.  
  190.         Statistic packetTrafficStatistic = new i18nStatistic(MESSAGE_LONGEST_TIME_KEY, null, Statistic.Type.count) {  
  191.             public double sample() {  
  192.                 return messgae_longestTime.get();  
  193.             }  
  194.   
  195.             public boolean isPartialSample() {  
  196.                 return true;  
  197.             }  
  198.         };  
  199.         statisticsManager.addStatistic(MESSAGE_LONGEST_TIME_KEY, packetTrafficStatistic);  
  200.     }  
  201.       
  202.     /** 
  203.      * Tracks the shortestTime of message 
  204.      */  
  205.     private void addPacketShortestTimeStatistic() {  
  206.         // Register a statistic.  
  207.         Statistic packetTrafficStatistic = new i18nStatistic(MESSAGE_SHORTEST_TIME_KEY, null, Statistic.Type.count) {  
  208.             public double sample() {  
  209.                 return message_shortestTime.get();  
  210.             }  
  211.   
  212.             public boolean isPartialSample() {  
  213.                 return true;  
  214.             }  
  215.         };  
  216.         statisticsManager.addStatistic(MESSAGE_SHORTEST_TIME_KEY, packetTrafficStatistic);  
  217.     }  
  218.       
  219.       
  220. }  

这样,以上信息就能在jmx接口中暴露出来了


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
源码详解openfire保存消息记录_修改服务端方式
XMPP协议学习笔记五(Openfire消息处理流程)
通过openfire发送文字
openfire3.6.3插件开发方法(经小组测试成功)
Java线程新特征之同步
netty的timeout
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服