-
-
Save phipac/cc2517796634554641ade9ef55def48b 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 python3 | |
# Updated for Python3 by phipac 20210131 | |
# If the server needs authentication add file /etc/munin/plugin-conf.d/plex: | |
# [plex] | |
# env.plex_token yourplextoken | |
import urllib.request, urllib.error, urllib.parse, 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('transcopy.label Transcopy') | |
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 = urllib.request.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 sessiong for playback and copy | |
file = urllib.request.urlopen(url) | |
root = ET.ElementTree(file=file).getroot() | |
# Get transcoding sessions | |
transcodeNum = 0 | |
transcopyNum = 0 | |
for video in root.iter('MediaContainer'): | |
for TranscodeSession in video.iter('TranscodeSession'): | |
if TranscodeSession.get('videoDecision') == 'transcode': | |
transcodeNum += 1 | |
if TranscodeSession.get('videoDecision') == 'copy': | |
transcopyNum += 1 | |
print('transcoding.value', transcodeNum) | |
print('transcopy.value', transcopyNum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment