Giter VIP home page Giter VIP logo

audience-meter's Introduction

Audience Meter: Lightweight daemon to mesure audience of a live event

Audience Meter is a simple daemon written in Node.js to mesure the number of users currently online. This can be used to mesure the audience of live events.

Features

  • Namespaces to track an unlimited number of events
  • Cross browser push notification thru EventSource polyfill using xhr-streaming-CORS for recent browsers and flash/URLStream for older browser
  • Monitoring interface on a dedicated port
  • Spreads the load on multiple CPUs and/or multiple servers

How to use

Start by running the daemon on a server, root privilege is required to let the daemon listen on ports 80:

$ sudo node audience-meter.js

Here are available parameters:

Usage: audience-meter.js [options]

Options:

  -h, --help                           output usage information
  -V, --version                        output the version number
  -d, --debug                          Log everything
  -w, --workers <num>                  Number of worker processes to spawn (default to the number of CPUs)
  -m, --cluster-addr <ip:port>         Use a given multicast IP:PORT to sync several instances of audience-meter
                                       (disabled by default, prefered address is 239.255.13.37:314)
  --max-conn-duration <seconds>        The maximum number of seconds a connection can stay established
                                       (default 3600, 0 to disable)
  --enable-uuid                        Enable connection UUID to prevent several connections with same
                                       (EXPERIMENTAL, known to leak memory)
  --cluster-notify-interval <seconds>  Interval between notifications for a node's notification (default 2 seconds
  --cluster-node-timeout <seconds>     Delay after which node's namespace info will be forgotten if no notification
                                       is recieved by a node (default 5 seconds)
  --notify-delta-ratio <ratio>         Minimum delta of number of members to reach before to notify listeners based
                                       on a fraction of the current number of members (default 0.1)
  --notify-min-delay <seconds>         Minimum delay between notifications (default 2)
  --notify-max-delay <seconds>         Maximum delay to wait before not sending notification because of min-delta not
                                       reached (default 25)
  --increment-delay <seconds>          Number of seconds to wait before to increment the counter in order to mitigate
                                       de/connection floods
  --namespace-clean-delay <seconds>    Minimum delay to wait before to clean an empty namespace (default 60)
  --demo-port <port>                   Public port on which to bind the demo server (default 8080, 0 to disable)
  --stats-port <port>                  Local port on which to bind the global stats server (default 1442, 0 to disable)
  --notification-port <port>           Local port on which to bind the global notification server (default 2442, 0 to disable)

In the webpage of the event, add the following javascript to join an event.:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="/client/jquery.audience.js"></script>
<script>
$.audience('http://YOUR-SERVER.COM/' + namespace)
</script>

Note that you can only join a single event at a time in a single page.

You may want to report the current number of online users on the event. By default, joining an event listen for it. To get event members count when it changes, listen for incoming messages like this:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="/client/jquery.audience.js"></script>
<script>
$.audience('http://{hostname}/{namespace}').progress(function(total)
{
    document.getElementById("total").innerHTML = total;
});
</script>

Connected users <span id="total">-</span>

Monitoring Interface

The daemon listen on the 1442 port on localhost in order to let another process to dump all namespace counters for monitoring or graphing purpose. One possible usage is to update RRD files to track the evolution of the audiance over time.

The server send all namespaces and their associated info separated formated as a JSON object. Each namespace is stored in a proprety, with an object containing info on the namespace. Namespace fields are:

  • created: the UNIX timestamp of the namespace creationg time
  • connections: the total number of connections to the namespace since its creation
  • members: the current number of participents in the namespace

Here is a usage example using netcat (indentation added for clarity):

$ nc localhost 1442
{
    "namespace1":
    {
        "created":1300804962,
        "connections":234,
        "members":123
    },
    "namespace2":
    {
        "created":1300804302,
        "connections":456,
        "members":345
    },
    "namespace3":
    {
        "created":1300824940,
        "connections":789,
        "members":678
    }
}

License

(The MIT License)

Copyright (c) 2011 Olivier Poitrey [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

audience-meter's People

Contributors

nyvath avatar pyke369 avatar tcristina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

audience-meter's Issues

audience-meter KO since socket.io v0.7

audience-meter KO since socket.io v0.7

Please see https://github.com/LearnBoost/Socket.IO/wiki/Migrating-0.6-to-0.7+

Should change audience-meter.js ->

Line 92 :

BEFORE: 
    client.send(info);
AFTER :
    client.json.send(info);

Not sure about this one - Line 138 :

BEFORE:
   listener.send(listener.bufferNotif);
AFTER:
    listener.json.send(listener.bufferNotif);

Line 206 :

BEFORE: 
    socket.on('connection', function(client)
AFTER : 
    socket.sockets.on('connection', function(client)

Should change demo.html lines 6 to 7 ->

BEFORE: 
    var socket = new io.Socket("{hostname}");
    socket.connect();
AFTER : 
    var socket = io.connect("http://{hostname}");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.