Git Product home page Git Product logo

nginx-hls-viewers's Introduction

nginx-hls-viewers

A python script for monitoring live viewer count from an nginx HLS stream with the nginx-rtmp-module enabled.

Other solutions for this exist but rely on too many dependencies, or require piping the stream through some means other than nginx itself. Which makes setup cumbersome and time-consuming.

This is a single python script with no dependencies. Simply download and run with python interpreter.

It works by monitoring the nginx access log and using the IP address of the client and the time at which they were last seen to tell if they are still watching.

The script then writes to a file for you to do what you wish with, for example, to configure nginx to serve the file over HTTP.

Setup

Download with curl and run as a normal python script.

curl https://raw.githubusercontent.com/ketnipz/nginx-hls-viewers/main/main.py > main.py
sudo python3 main.py -I /var/log/nginx/hls_access.log

By default, the output file is located at /tmp/hls.count. This file contains nothing but the current view count.

cat /tmp/hls.count
0

You may also configure a systemd service to keep this python script running, click here for an example .service file.

To see an example nginx configuration file, click here.

Usage

usage: main.py [-h] [-I IN_FILE_NAME] [-O OUT_FILE_NAME] [-w WAIT]

optional arguments:
  -h, --help            show this help message and exit
  -I IN_FILE_NAME, --in IN_FILE_NAME
                        Path to the nginx logging file
  -O OUT_FILE_NAME, --out OUT_FILE_NAME
                        Path to live viewer count file
  -w WAIT, --wait WAIT  Time in minutes to wait before assuming a client
                        is not longer watching

nginx-hls-viewers's People

Contributors

ben-pearce avatar

Stargazers

ustoopia avatar Darto KLoning avatar panoskpt avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

ustoopia

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.