大家对系统统计在线人数有什么好的方案?

renxuanyao 2010-05-27 09:18:20
如题。
...全文
198 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
  • 打赏
  • 举报
回复
看对时效性是否有要求。

535

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 Exchange Server
社区管理员
  • 消息协作社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧