How to gather user streaming statistics

The Wowza media server logs anonymous statistics in the access or stats logs. To correlate stream events in the logs with users, first you have to (1) identify the user, then (2) add a user identifier (UID) to the stream name with a querystring, and you have to (3) add x-sname-query to the Fields list of the access and/or stats Appender in /conf/ Here are some options and details:

  1. Identify the user:
    1. If you're sing a player system like JW Player or Flowplayer running in CMS or other web system where a UID is stored in a cookie in the HTML, you can add javascript to retrieve UID cookie in your play page, then add the UID to file Flashvar (JW Player) or the clip (Flowplayer)
    2. For custom Flash clients running in CMS or other web system where a UID is stored in a cookie in the HTML container, you can use ExternalInterface to retrieve the UID and avoid making the user login again.
      import flash.external.ExternalInterface;
      var uid:String = "";
      if (ExternalInterface.available && /http*:/ ) == 0) {
      	uid ="getUID()");
      Where getUID is a javascript function in the HTML container.
    3. If there isn't a UID cookie, here are two options for user authentication (These require a Flash client):
      How to do user authentication for Flash RTMP client using JDBC connection to MySQL database
      How to do file-based RTMP authentication with URL query strings (OnConnectAuthenticate2)
    4. For non-Flash clients, you would add UID to playback URLs in your server page (asp, php, etc.)
  2. Add the UID to stream name:
    1. In a player system like JW Player or Flowplayer (as noted above) you might be able to add to player setup in the HTML
    2. In Flash actionscript, append the uid to stream name in the command:"mp4:sample.mp4?uid=123");
    3. Flash HTTP (San Jose)
    4. For Cupertino
    5. RTSP
  3. To add x-sname-query field to log4j Appender, open /conf/ in a text editor, find the serverAccess Fields list and add ", x-sname-query" to the end of the list:
    log4j.appender.serverAccess.layout.Fields=x-severity,x-category,x-event;date,time,c-client-id,c-ip,c-port,cs-bytes,sc-bytes,x-duration,x-sname,x-stream-id,x-spos,sc-stream-bytes,cs-stream-bytes,x-file-size,x-file-length,x-ctx,x-comment, x-sname-query
    You must restart Wowza after changes to file.

    To test, play a stream in the Wowza SimpleVideoStreaming example player:

    Server: rtmp://[wowza-address]:1935/vod
    Stream: mp4:sample.mp4?uid=123

    Now open the current access log, look for the stream events associated with that play and look in the x-sname-query field for "uid=123".

    If you would just like the uid, you can play "mp4:sample.mp4?123"
Now you can see what, when and how much each user streamed.
Note: Adding a querystring to the stream name in Silverlight smooth streaming Manifest url has been a problem in testing with the Wowza Smooth streaming examples.

Originally Published: 06-24-2011.

If you're having problems or want to discuss this article, post in our forum.