社区
消息协作
帖子详情
大家对系统统计在线人数有什么好的方案?
renxuanyao
2010-05-27 09:18:20
如题。
...全文
217
19
打赏
收藏
大家对系统统计在线人数有什么好的方案?
如题。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
19 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
renxuanyao
2010-06-15
打赏
举报
回复
非常感谢,虽然不能是及时的但已经很不错了,程序中有个小BUG(dominoVersion.indexOf("6.5")<0 )这不能退出吧,要不只有6.5的才可以了,
killer_wo
2010-06-15
打赏
举报
回复
先说一下,以下不是我写的。
思路:通过取得xml,然后解析xml,找到自己需要的,然后组合,输出。
以下是输出整个目前的session当中的相关数,与实时性有一定关系。
如果只需要输出人员,则需要完成之后,统计i。
import lotus.domino.*;
import lotus.domino.Document;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
public class JavaAgent extends AgentBase {
private static final String CONSOLE_COMMAND ="Show Inetusers -xml >HttpUsers.xml";
private static final String OUTPUT_FILE_NAME = "HttpUsers.xml";
public void NotesMain() {
try {
Session session = getSession();
//取Domino服务器版本,版本低于6.5则退出
String dominoVersion = session.getNotesVersion();
System.out.println(dominoVersion);
System.out.println(dominoVersion.indexOf("6.5"));
if (dominoVersion.indexOf("6.5") < 0) {
return;
}
AgentContext agentContext = session.getAgentContext();
Document curdoc=agentContext.getDocumentContext();
Database curDB = agentContext.getCurrentDatabase();
String server = curDB.getServer();
// (Your code goes here)
//接收控制台返回的字符串
String returnString = session.sendConsoleCommand(server, CONSOLE_COMMAND);
if (returnString.equals("") || returnString.indexOf("<") < 0 ||
returnString.indexOf(">") < 0) {
return;
}
//输出的文件存在则先删除
File file = new File(OUTPUT_FILE_NAME);
if (file.exists()) {
file.delete();
}
//将控制台返回的字符串写到文件中
FileOutputStream fos = new FileOutputStream(file);
fos.write(returnString.getBytes());
fos.flush();
fos.close();
//分析XML文件
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.
newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
org.w3c.dom.Document document = builder.parse(file);
Element rootElement = document.getDocumentElement();
NodeList userDataList = rootElement.getElementsByTagName("userdata");
if (userDataList == null || userDataList.getLength() == 0) {
return;
}
Node userDataNode = null;
Node userNameNode = null;
for (int i = 0; i < userDataList.getLength(); i++) {
userDataNode = userDataList.item(i);
String netaddress = getNodeProperty(userDataNode, "netaddress");
String login = getNodeProperty(userDataNode, "login");
login = stringToDateTimeString(login);
String expires = getNodeProperty(userDataNode, "expires");
expires = stringToDateTimeString(expires);
userNameNode = userDataNode.getChildNodes().item(1);
if (userNameNode == null) {
continue;
}
if (!userNameNode.hasChildNodes()) {
continue;
}
String userName = getNodeValue(userNameNode);
String printString = "用户名=" + userName + ", 地址=" + netaddress +
", 登陆时间=" + login + ", 过期时间=" + expires;
System.out.println(printString);
curdoc.appendItemValue("OnlineAll",printString);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public String getNodeValue(Node node) {
Node firstNode = node.getFirstChild();
if (firstNode == null) {
return "";
}
return firstNode.getNodeValue();
}
public String getNodeProperty(Node node, String propertyName) {
NamedNodeMap namedNodeMap = node.getAttributes();
if (namedNodeMap == null || namedNodeMap.getLength() == 0) {
return "";
}
for (int i = 0; i < namedNodeMap.getLength(); i++) {
Node childNode = namedNodeMap.item(i);
if (childNode.getNodeName().equals(propertyName)) {
return childNode.getNodeValue();
}
}
return "";
}
public String stringToDateTimeString(String string) {
int pos = string.indexOf("T");
String single = string.substring(0, 4);
single += "年";
single += string.substring(4, 6);
single += "月";
single += string.substring(6, 8);
single += " ";
String sHour = string.substring(pos + 1, pos + 3);
String sMinute = string.substring(pos + 3, pos + 5);
String sSecond = string.substring(pos + 5, pos + 7);
single += sHour + ":" + sMinute + ":" + sSecond;
int hour = Integer.parseInt(sHour);
if (hour < 12) {
single += " 早上";
}
else {
single += " 下午";
}
return single;
}
}
chenzb
2010-06-13
打赏
举报
回复
你问的是http应用?
c api应该可以啊,过滤每个http验证、失效等。。。。。
如果浏览器客户和服务器不是双向通讯的话,肯定不可能准确的
renxuanyao
2010-06-11
打赏
举报
回复
换个问法就是怎么把当前在线的人员信息输出到一个文件中
renxuanyao
2010-06-10
打赏
举报
回复
没有高手吗。
renxuanyao
2010-06-08
打赏
举报
回复
没有人知道吗,tell http show users怎么读到XML文件中呢?
renxuanyao
2010-06-07
打赏
举报
回复
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
xuminwlt
2010-06-07
打赏
举报
回复
这个时效性很明显达不到系统的要求,如果涉及到在线通讯方面的开发,或者流程操作
,难道必须得Sametime整合?
renxuanyao
2010-06-04
打赏
举报
回复
请教啊,tell http show users怎么读到XML文件中呢?
CrazyNotes
2010-06-03
打赏
举报
回复
在线人数只能用tell http show users,没有其他方法
至于浏览器非正常退出的问题,那是要代码来实现logout,并不在tell http show users考虑的范畴
only4u
2010-06-03
打赏
举报
回复
[Quote=引用 6 楼 crazynotes 的回复:]
就是把tell http show users输出到一个xml文件中再处理
[/Quote]
这个方法肯定不行,如果没有按logout,直接关浏览器,session不会立即销毁,完毕
renxuanyao
2010-06-03
打赏
举报
回复
tell http show users怎么读到XML文件中呢?
renxuanyao
2010-06-02
打赏
举报
回复
恩,不错的方法,但要是客户端直接关闭IE也会显示在那,就是说要到服务器SESSION时间到了才能恢复正确。
CrazyNotes
2010-06-02
打赏
举报
回复
就是把tell http show users输出到一个xml文件中再处理
xyk_1986
2010-06-01
打赏
举报
回复
三楼滴大虾能不能把代码贴出来或者说下思路也可以。。感激不尽。。
renxuanyao
2010-05-31
打赏
举报
回复
能不能分享一下
CrazyNotes
2010-05-31
打赏
举报
回复
可以实时统计啊,我有成功应用哈哈
renxuanyao
2010-05-30
打赏
举报
回复
当然有一定的要求
Domino0627
2010-05-30
打赏
举报
回复
看对时效性是否有要求。
Java如何实现
统计
在线
人数
的功能?
监听器Listener实现
统计
人数
功能(1)先创建监听器包listener在新建OnlineListener类(2)创建监听器servlet的接口4.Redis实现
统计
人数
功能 需求:平均访问时常,平均同时
在线
人数
,最高同时
在线
人数
(1)先设计数据表:...
如何
统计
网站的
在线
人数
呢?
如何
统计
网站的
在线
人数
呢? 首先很简单的思想就是,如果只针对会员用户进行
统计
,在登录登出时加判断,然后维护一个表(或者其他存储方式)来存储
在线
会员即可。 但是有个问题就是,对于正常退出的会员当然可以...
redis
统计
数量_Redis实现实时
统计
在线
用户
人数
的几种
方案
那
在线
人数
是如何
统计
的呢,这里有几种
方案
,代码用laravel框架。可以作为开发中参考。1 用表
统计
方式用数据表
统计
在线
人数
,这种方式只能用在并发量不大的情况下。首先我们先新建表:user_loginuser_login表模拟...
几种优雅实现
在线
人数
统计
的
方案
欢迎加入小哈的星球,你将获得:专属的项目实战 / Java 学习路线 /一对一提问 / 学习打卡 / 每月赠书新项目:仿小红书(微服务架构)正在更新中... 。全栈前后端分离博客项目 2.0 版本完结啦,演示链接:...
在线
人数
统计
的几种优雅实现
方案
在线
人数
统计
这个功能相信大家一眼就明白是啥,这个功能不难做,实现的方式也很多,这里说一下我常使用的方式:使用Redis的有序集合(zset)实现。zaddzrem。
消息协作
536
社区成员
39,094
社区内容
发帖
与我相关
我的任务
消息协作
企业开发 Exchange Server
复制链接
扫一扫
分享
社区描述
企业开发 Exchange Server
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章