Building Live HLS stats for Varnish

Alejandro Ferrari
3 min readFeb 20, 2017

--

Just a short intro

As Streaming Media consultant, I work with customers around the world with many crazy ideas :) and great challenges.

The platform of one of my customers grow quickly and we saw that all (almost what we test) media servers in the market don’t cover all our needs for Edge distribution layer.

For this reason we choose Varnish, with your VCL language and many VMODs was a great option to build a new Edge layer.

Here some Pros and Cons that I found with this election:

Pros:

  1. OpenSource (no license fee by default)
  2. Bullet proof technology, used by many biggest streaming platform as Dailymotion or inclusive recommended by Adobe
  3. Highly scalable and customizable.

Cons:

  1. Not much documentation about HLS implementations, code snippets or examples.
  2. And the reason of this article, NO stats system for Live HLS concurrent users (except for premium subscription users)

Now is time to back to technical part!

This be the current Stack

Tools involved into Stats Flow

And the result look like this

Grafana real dashboard

I’ll show all the configurations created to build this dashboard

First we need to select a way to identify each user as unique, to made this we choose use custom Cookie.

Videos.js / Clappr.io

The player need to send the cookie created into each request, if are using a player based on hls.js library we need to add this configuration:

Varnish Cache

We cache the .ts and the .m3u8 from the Origin Server, but we need something additional to manage at this point, we mention that we use a cookie to identify each unique user, for this reason Varnish is in charge to manage this business logic, they check if cookie exist in the request and in case no cookie was sent, they create a new, or update the older if exist.

When request arrives:

Before response:

OK, until now, we made all settings to identify the user… the next steps be capture this data and send to a DB for persist.

Logging

To create a custom log file with the information needed to calculate the amount of user, we use varnishncsa

FluentD

Is the responsible to capture this logs and send to StatsD compatible server

Telegraf

As mentioned previously this is the StatsD compatible server, they be in charge to summarize the amount of users watching our streams.

InfluxDB

Here is very simple just store the metrics.

Grafana

Just the amazing tool that allow create amazing Dashboards just in seconds, with high quality.

This is the simple query needed to get the information from InfluxDB

Grafana Dashboard with configurations

Hope this help to others to build something similar, in case you need I’m available to be hired as consultant, for this project or any related with Live/Vod Streaming platforms.

Any advice or feedback is welcome, feel free to write into the comments!

Enjoy!

Alejandro

--

--

Alejandro Ferrari

Streaming Professional Consulting Services / Wowza - Flussonic - Icecast / Akamai - CloudFlare - CloudFront