How to: Guide to Setting Up PlexWatchWeb in a Jail -- Robust User Monitoring for Plex
see: https://forums.plex.tv/index.php/topic/ ... d-stopped/
PlexWatch is a handy application that fills a gap for Plex users in terms of user and content monitoring, which informs demand management. Ideally this functionality built in natively, but thankfully someone on the dev team has written it and made it available as a bolt-on over on the Plex forums. It's a recurring script that's written in Perl and can be managed through CLI, but there is also a web-based front-end that really makes this a joy to use and significantly easier to manage.
I think it makes a lot of sense if you have a lot of activity within your home that you would like to keep tabs on, and particularly if you have multiple external users that connect to your Plex server remotely. This allows you to see what IPs/users are connecting and when so that you can alter your network and hardware needs accordingly. It provides some nice data and even organizes it into some decent graphs.
Check Google Images for screenies.
What does it do?
(straight from the developer):
- notify when a user starts watching a video
notify when a user stops watching a video
notify when a user pauses watching a video
notify when a user resumes watching a video
notify on recently added content to a PMS server
notifies via email, prowl, pushover, growl, twitter, boxcar, pushbullet, GNTP and/or a log file
enable/disable notifications per provider & per notification type (start, stop, paush, resume, recently added)
backed by a SQLite DB (for state and history)
CLI to query watched videos, videos being watched and stats on time watched per user
Limit output per user or exclude users
...more to come
- https://pushover.net
https://prowlapp.com
http://growl.info/ (via Growlnotify @ http://growl.info/do...eneraldownloads)
https://twitter.com/ (create a new app @ https://dev.twitter.com/apps)
https://boxcar.io/ (boxcar v1 & boxcar_v2)
SNARL/GROWL: GNTP notifications supported. Anything that uses GNTP should work
https://www.pushbullet.com
With the features accounted for, let's start with a disclaimer: Although I have been running NAS4Free (and before that, FreeNAS 0.7x) for several years, I am still a novice FreeBSD / UNIX user. However, I have successfully built my server box's functionality through a number of extensions that I could never have fathomed when I began Nas4Free. That is solely through the use of how-to guides like this one. For newbs like me, it really helps to have exact instructions that are specific to our platform. I have benefited in this way from the good folks on our forums and so I would like to finally make a contribution myself. If you folks have problems recreating what worked for me on my box, hopefully some wiser souls will be along to help.
Also, please no making fun of my code/commands. I know there are more efficient ways of doing things, stacking commands, etc, but I am taking baby steps here. It's A-B-C's for me. Ok, [/disclaimer]
These two links were helpful in my own efforts to get a working installation going:
https://forums.freenas.org/index.php?threads/plexwatch-installation.19126/
https://github.com/ljunkie/plexWatch/blob/master/README.md
On to the Guide!
I have plexWatch set up in its own jail and have the Plex Logs directory mounted in fstab. You don't really need access to the PMS log directory unless you want to log IP addresses, which I do. You could feasibly set this up within your Plex jail, but I chose to keep things separate so that in case something borks in one it doesn't affect the other.
1) Start with a working jail
I am still on TheBrig because that was the thing to be on when I set my Nas4Free up, but any working jail should work. Note that my jail is based on FreeBSD 9.3 and the new package manager, pkg_tools. What this means when it comes time to add packages to the jail is that my command looks like "pkg install" instead of the old "pkg_add". If you need to upgrade an older jail to the new package manager (as I did and was confused for a while on how to do it), see this thread and then come back:
https://www.xigmanas.com/forums/viewtopic.php?f=79&t=7843
2) enter jail cli
newbs: SSH in, then
Code: Select all
jlsCode: Select all
jexec x cshTHE BACK END:
3) Install packages:
Code: Select all
pkg install p5-libwww p5-XML-Simple p5-Time-Duration p5-Time-modules p5-DBD-SQLite p5-JSON nano wget Code: Select all
mkdir -p /opt/plexWatch/Code: Select all
cd /opt/plexWatch/Code: Select all
wget --no-check-certificate -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl
Code: Select all
wget --no-check-certificate -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/config.pl-distCode: Select all
chmod 777 /opt/plexWatch && chmod 755 /opt/plexWatch/plexWatch.plCode: Select all
cp /opt/plexWatch/config.pl-dist /opt/plexWatch/config.plCode: Select all
nano /opt/plexWatch/plexWatch.pl#!/usr/bin/perl
to
Code: Select all
#!/usr/local/bin/perlOnce you have saved the corrected this and saved, edit:
Code: Select all
nano /opt/plexWatch/config.plThe main things to edit at this point are:
$server = 'localhost'; ## IP of your PMS - or localhost
$port = 32400; ## port of your PMS
You could also fill in the lines:
$myPlex_user = '';
$myPlex_pass = '';
You should fill in those lines if you require clients to authenticate on the local network (this is a PMS setting).
7) Test the script and see that it works
Go into your plex server and load up a video. Play, then run the script manually:
Code: Select all
/opt/plexWatch/plexWatch.plCode: Select all
/opt/plexWatch/plexWatch.plYou should note the creation of a SQLite database file in the same path called plexWatch.db.
You can check to see if your activity was logged if you like.
Code: Select all
/opt/plexWatch/plexWatch.pl --watched8) Set up cronjob
Now we want this script to run on an endless loop so that we don't miss any activity and also so that we don't have to sit in front of a command window constantly executing /opt/plexWatch/plexWatch.pl. That would be a horrible life and the yield would probably not be worth the effort.
Code: Select all
nano /etc/crontabCode: Select all
#Plexwatch all the dam time
* * * * * root /opt/plexWatch/plexWatch.plBonus Round
You need to be able to send traffic over https in order to enable push notifications, so let's set that up. First, enable your chosen service in
Code: Select all
nano /opt/plexWatch/config.plNow we need to get https working so that our push notes make it to remote servers.
Do:
Code: Select all
cpanLet this run its course. To my mind, you should now be able to
Code: Select all
install LWP::Protocol::httpsI then ran
Code: Select all
install Crypt:SSLeayCode: Select all
install IO::Socket::SSLCode: Select all
install LWP::Protocol::httpsBonus Round 2
If you like to log IP addresses (I do -- call me old-fashioned), you need to add an additional package:
Code: Select all
pkg install p5-File-ReadBackwardsYou also have to enable debug logging in PMS, map your PMS Log folder (fstab) to your plexWatch jail and edit your config.pl again:
Code: Select all
nano /opt/plexWatch/config.pl$log_client_ip = 1;
$debug_logging = 1;
Your $server_log directory is in whatever jail you installed PMS to, in /usr/local/plexdata/Plex Media Server/Logs/Plex Media Server.log by default. Again, you need access from this jail, if separate, to these folders in your PMS jail (if applicable) by properly configuring fstab (there is a handy form in the webgui for this in The Brig).
It should look something like this:
Code: Select all
/mnt/plex_jail/usr/local/plexdata/ /mnt/plexWatch_jail/mnt/plexlogs/ nullfs ro 0 0;Whew! That's all for the back end. If you only want CLI management and push notifications, you're done. You can see all the flags and options you can call over on the github page.
THE FRONT END
It sure is a lot nicer to have a web interface though. Easy on the eyes, easy to manage, access from mobile devices and so on.
1) Add packages:
Code: Select all
pkg install apache24 mod_php5 php5-sqlite3 php5-curl php5-json php5-extensions2) Adjust your Apache conf to enable handling of php pages on your webserver.
Start by editing your httpd.conf:
Code: Select all
nano /usr/local/etc/apache24/httpd.confCode: Select all
DirectoryIndex index.html index.phpCode: Select all
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phpsStart by initializing php.ini from the default production values supplied with the package:
Code: Select all
cp /usr/local/etc/php.ini-production /usr/local/etc/php.iniCode: Select all
nano /usr/local/etc/php.iniCode: Select all
";date.timezone="Remove the ";" and change it to your actual time zone (a list of supported TZs is here:https://php.net/manual/en/timezones.php), in my case:
Code: Select all
date.timezone = Europe/London4) Download plexWatchWeb to your webroot, unpack and fix its permissions:
Code: Select all
cd /usr/local/www/apache24/data
wget --no-check-certificate https://github.com/ecleese/plexWatchWeb/archive/master.zip
unzip master.zip && rm master.zip
mv plexWatchWeb-master plexWatch
chown -R www:www plexWatchCode: Select all
echo 'apache24_enable="YES"' >> /etc/rc.confCode: Select all
service apache24 restartCode: Select all
service apache24 onestartNavigate to http://<ip_of_your_jail>/plexWatch and we should now be live!!! You have a bit of initial set up to do. Remember, your plexWatchWeb files live in /usr/local/www/apache24/data so if you need to edit anything, that's where to go. I had to 'factory reset' once by deleting /config/config.php.
On setup you have to point to your plexWatch.db file at /opt/plexWatch/plexWatch.db
If you have problems here, make sure your permissions allow public users to at least read from it (eg, chmod 755). This should already be set from earlier, but heck, check again. I never had this problem, but I noticed out in the forums that some people were 777 the whole directory. If you have problems with the WebGui end, that's where I'd start.
Sorry it was long-winded, but I wanted to be detailed for the beginner as I have been there myself (and am still not far from there now). Let me know if you succeed or fail below, as well as any improvements I can make to the guide, and most of all, enjoy!