Monitoring
How many users are connected?
There are three basic ways to determine how many users are connected.
Do it yourself
The most obvious way to track users is from within your application server. This is simple to implement (it's basically a matter of properly processing joins/leaves or connects/disconnects) and quite flexible. Unfortunately, some application architectures render this approach impractical.
RestQ
If you are running MorbidQ, you can use the RestQ callback system to notify your application server (or some other interested party) of connect, disconnect, subscribe, unsubscribe, and send events. This approach provides the benefits of highly-detailed information, easily-customizable deployment, and, if desired, complete control over all queue events. RestQ was invented to simplify integration with web frameworks, but can be deployed in any environment.
For more information, see MorbidQ's RestQ documentation.
0.7 monitor feed
Orbited 0.7 ships with a variety of servers for testing and whatnot. One of these is the monitor feed. It provides the listener with basic information about the daemon, including how many users are connected.
To run it on port 8005, add this line to the [listen] section of your config:
monitor://:8005
So now you're running it. To actually access it, add this line to the [access] section of your config:
* -> localhost:8005
Now start Orbited and go to localhost:8000/system/monitor. The code there simply connects to localhost:8005 and updates some values in a table.
It will probably be more useful for you to plug in directly to the feed. To do this, simply connect to localhost:8005 (or wherever you choose to run the monitor feed) and listen. You can connect using Orbited, telnet, or a regular socket. You will immediately start receiving JSON frames separated by "~".
The first frame will look like this:
['INIT': data]
"data" is a dictionary providing initial values for the following keys: user, pid, cpu, mem, connections. After that, you will receive a frame every second with an update:
['UPDATE': data]
"data" is a dictionary with an entry for every item that has changed in the past second. Note that if no changes have occurred, the feed will generate no update.
Here are sample files to get you started:
test.html:
<html>
<head>
<script src="/static/Orbited.js"></script>
<script>
onload = function() {
c = new Orbited.TCPSocket();
c.onread = console.log;
c.open("localhost", 8005);
};
</script>
</head>
<body>
</body>
</html>
orbited.cfg:
[listen] http://:8000 monitor://:8005 [static] test = test.html [access] * -> localhost:8005 # daemon monitoring feed
Grab both files, run Orbited from the same directory, and navigate in Firefox to localhost:8000/test. Watch the Firebug console to see what kind of updates you get when you make new connections and such.
The code is located here. Feel free to modify it to fit your needs.