社区
消息协作
帖子详情
大家对系统统计在线人数有什么好的方案?
renxuanyao
2010-05-27 09:18:20
如题。
...全文
202
19
打赏
收藏
大家对系统统计在线人数有什么好的方案?
如题。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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来实现3.监听器Listener实现
统计
人数
功能(1)先创建监听器包listener在新建OnlineListener类(2)创建监听器servlet的接口4.Redis实现
统计
人数
功能 需求:平均访问时常,平均同时
在线
人数
,最高同时
在线
人数
(1)先设计数据表:开始访问页面时间,离开页面时间表:(id,place,ip,user_id,user_na......
redis
统计
数量_Redis实现实时
统计
在线
用户
人数
的几种
方案
一个业务系统网站每天
人数
的访问量是多少,
在线
人数
是多少? 这种业务我们在开发中就要预留,也是在我们的设计范围内的咯!因为一个正在运营的网站,每天都会用到
统计
。那
在线
人数
是如何
统计
的呢,这里有几种
方案
,代码用laravel框架。可以作为开发中参考。1 用表
统计
方式用数据表
统计
在线
人数
,这种方式只能用在并发量不大的情况下。首先我们先新建表:user_loginuser_login表模拟用户登录,不存在...
如何
统计
网站的
在线
人数
呢?
如何
统计
网站的
在线
人数
呢? 首先很简单的思想就是,如果只针对会员用户进行
统计
,在登录登出时加判断,然后维护一个表(或者其他存储方式)来存储
在线
会员即可。 但是有个问题就是,对于正常退出的会员当然可以使用这种方式,那如果该会员是关闭了网页或者停电或者其他因素,那如何得知这些情况呢? 1. 维护
在线
用户表 假设使用数据库来完成这个功能,想要达到最快的速度,就直接使用MYSQL内存表来保存在
REDIS实践之
在线
人数
统计
几种
方案
分析
在线
人数
统计
业务是我们开发web肯定要设计的业务逻辑,本文就会给出几种设计
方案
,来分析下各个
方案
的优缺点: 使用有序集合 这种
方案
能够同时储存
在线
的用户 和 用户上线时间,能够执行非常多的聚合计算,但是所消耗的内存也是非常可观的。 使用集合 这种
方案
能储存
在线
的用户,也能够执行一定的聚合计算,相对有序集合,所消耗的内存要小些,但是随着用户量的增多,消耗内存空间也处于增加状态
实时用户
在线
人数
统计
(一):表
统计
在项目中有时候需要
统计
实时
在线
人数
,在我过往的项目中,主要实施过以下几种
方案
,现在一一来说明下: 1)表
统计
:用数据表
统计
在线
人数
,缺点是当并发量大的时候可能造成性能瓶颈,如无特别大的并发的时候完全可以胜任 2)Redis有序集合:因为在内存中,所以效率很高,可以
统计
某个时间段内的
在线
人数
,还可以做各种聚合操作。但是如果
在线
人数
比较多的情况下,会比较占用内存。 3)Redis HyperLo...
消息协作
536
社区成员
39,097
社区内容
发帖
与我相关
我的任务
消息协作
企业开发 Exchange Server
复制链接
扫一扫
分享
社区描述
企业开发 Exchange Server
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章