bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
11.88k stars 1.49k forks source link

Counting HLS readers in Prometheus metrics #962

Open tompointexe opened 2 years ago

tompointexe commented 2 years ago

Describe the feature

Counting HLS readers in Prometheus metrics, i think the title explains itself 😅 Thanks !

aler9 commented 2 years ago

Hello, this can't be done as in HLS there isn't the concept of "reader": streams are served as files with an HTTP server, and anyone can pull them.

Anyway, an alternative could be reporting the number of served files per second, or the bandwidth, hence i'm leaving this open in order to find and implement an alternative metric.

dlozoya commented 1 year ago

Currently, I am using http connections to the HLS port. I think it can be reliable but I don't know if 100%. I run this script every minute and save result in database

viewers=$(ss -tn | grep ':8888' | wc -l)

aler9 commented 1 year ago

@dlozoya that works only if clients reuse the same HTTP connection for pulling multiple segments and keeps it open. It's an optional feature of HTTP.

Anyway, another way of implementing this could be forcing clients to store an identifier somewhere (cookies or query parameters) and making it mandatory to pull segments. But this is completely out of the HLS specification, so there may be compatibility issues.