zorchenhimer / MovieNight

Single instance video streaming server with integrated chat.

Home Page:https://discord.gg/F2VSgjJ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minimal statistics dashboard

zorglube opened this issue · comments

I just open this issue to ask if it is possible to work on a very minimal statistics dashboard.
I'm thinking about something like :

  • list / number of current viewer
  • IPs of the viewer
  • nickname of the viewer if it is also in the chat

Some work in progress is visible here.

commented

These are already commands in chat. I'm not really sure we'd really need a specific dashboard for them.

  • /stats will give a some info about the server (server uptime, stream, uptime, current users, max users).
  • /users will list out the currently connected users.
  • /iplist (as admin) will dump the names and IPs of the currently connected users to the server's console. Idea being the admin has access to the console.

Yup I saw that, but :

  • /stats show only chat statistics ;
  • /users show only chat current users ;
  • /iplist since my MN instance is behind en Nginx, it show me only my Nginx IP ;

The statistics I'm interested in are the video-steam's stats. Maybe I missed something ?

commented

Stats about the video streams aren't currently recorded at all, so adding a dashboard for it might not be trivial.

As for the IPs being wrong behind nginx, you need to set the X-Forwarded-For proxy header for the websocket (Note: banning users also requires this. Otherwise you'd be banning everybody lol):

location /ws {
        proxy_pass http://movienight;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

I wasn't thinking about recording stream stats.
Adding the stream stats into the /stats message can be a nice minimal achievement.

Thank for the tips, I'll check my Nginx conf ;-)

commented

In order to display stats, I need to actually get them from somewhere. This is what "recording stats" does. It figures out the stats and saves them somewhere so the command doesn't hang.

Just to be sure I don't miss anything, if you don't mind can you have a small look on this Nginx setup

	set 						$upstream [MovieNight-IP];
	# Movie Night
	location / {
		proxy_pass			http://$upstream;
		proxy_http_version 		1.1;
		
		proxy_set_header		Host $host;
		proxy_set_header		X-Real-IP $remote_addr;
		proxy_set_header		Upgrade $http_upgrade;
		proxy_set_header		Connection "Upgrade";
		proxy_set_header		X-Forwarded-For $proxy_add_x_forwarded_for;
		
		proxy_redirect			off;
		proxy_next_upstream	error timeout invalid_header http_500 http_404;
		proxy_connect_timeout	2;
		proxy_intercept_errors	on;
	}

	# Movie Night Chat Websoket forward 
	location /ws {
		proxy_pass			http://$upstream;
		proxy_http_version		1.1;
		proxy_set_header		Host $host;
		proxy_set_header		Upgrade $http_upgrade;
		proxy_set_header		Connection "Upgrade";
		proxy_set_header		X-Forwarded-For $proxy_add_x_forwarded_for;
	}

In order to display stats, I need to actually get them from somewhere. This is what "recording stats" does. It figures out the stats and saves them somewhere so the command doesn't hang.

Yes yes definitely, by recording I understood get/grab & write the stats somewhere on a disk.

commented

Just to be sure I don't miss anything, if you don't mind can you have a small look on this Nginx setup

It looks like you're doing a bunch of extra stuff for location / that shouldn't really be needed. Additionally, I don't think proxy_next_upstream will actually do anything if you didn't define a block of upstream servers. The relevant bit of my config:

upstream movienight {
        server 127.0.0.1:8089;
}

server {
        location / {
                proxy_pass http://movienight;
        }

        # ... 
}

If I wanted to grab video stats I would need to set the X-Forwarded-For header, but iirc that isn't even looked at on the video end right now.

The proxy_next_upstream is here to provide an default response when MovieNight is off, actually today it's like that

server {
	set 						$upstream [MovieNight-IP];

	# Movie Night
	location / {
		proxy_pass				http://$upstream;
		[...]
		proxy_next_upstream		error timeout invalid_header http_500 http_404;
		proxy_connect_timeout	2;
		proxy_intercept_errors	on;
	}

	# Movie Night Chat Websoket forward 
	location /ws {
		[...]
	}

	error_page 500 502 503 504 /error.html;
	location /error.html {
		return 					200 "<!DOCTYPE html><html><head><title>Movie Night</title></head><body style=\"background-color:black;\"><h1 style=\"color:grey;\">Server is down</h1></body></html>";
	}
}
commented

Ah, that's fair. I just capture the 502 error and use a custom error page for that. Same thing, different execution, I suppose.

Probably Way toooo much options in Nginx ^_^

But... About the stream stats. Let say I'll work on that. It imply I'll have to dig into Joy4 rmtp server to get some kind of viewer += 1 each time a new client is connecting.

and have the viewer value stored into :

type streamStats struct {
	messageIn   int
	messageOut  int
	maxUsers    int
	start       time.Time
	mutex       sync.Mutex
	viewers     int
	maxViewers  int
	streamStart time.Time
	streamLive  bool // True if live
}
commented

Shouldn't be necessary to dive into that library for that. Iirc, there's a map of channels around somewhere that does packet coping from the server to each client. Have a look at the http handler for the /live endpoint.

Thank !

By the way, I just red that the X-Forwarded-For header is now standardized as Forwarded header.