Last active
May 18, 2024 03:12
-
-
Save MorbZ/e5d05856a6bdbcf4ca52c4cae21f2228 to your computer and use it in GitHub Desktop.
Munin plugin for Plex: Shows playing streams and transcoding sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# If the server needs authentication add file /etc/munin/plugin-conf.d/plex: | |
# [plex] | |
# env.plex_token yourplextoken | |
import urllib2, sys, os | |
import xml.etree.ElementTree as ET | |
# Show Config | |
if len(sys.argv) > 1 and sys.argv[1] == 'config': | |
print 'graph_title Plex Streams' | |
print 'graph_vlabel Number of streams' | |
print 'graph_category plex' | |
print 'graph_scale no' | |
print 'playing.label Playing' | |
print 'playing.draw AREASTACK' | |
print 'transcoding.label Transcoding' | |
print 'transcoding.draw LINE2' | |
sys.exit(0) | |
# Show values | |
# Make URL | |
url = 'http://localhost:32400/status/sessions/'; | |
token = os.getenv('plex_token'); | |
if token is not None: | |
url += '?X-Plex-Token=' + token | |
# Get playing streams | |
file = urllib2.urlopen(url) | |
root = ET.ElementTree(file=file).getroot() | |
playingNum = 0 | |
for video in root.iter('Video'): | |
for player in video.iter('Player'): | |
if player.get('state') == 'playing': | |
playingNum += 1 | |
print 'playing.value', playingNum | |
# Get transcoding sessions | |
procs = os.popen('pgrep -l "Plex Transcoder"').read() | |
lines = len(procs.split('\n')) - 1 | |
print 'transcoding.value', lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following code prints the three values (including the transcopy.value) but only for one single server. However, it has been updated for Python3!