diff --git a/plugins/streaming/packetship_ b/plugins/streaming/packetship_ new file mode 100755 index 00000000..a9ec0964 --- /dev/null +++ b/plugins/streaming/packetship_ @@ -0,0 +1,159 @@ +#!/bin/bash +# +# Plugin to parse packetship (http://www.packetship.com/) streaming server statistics. +# +# Author: +# Dave Fennell +# +# Created: +# 2nd January 2013 +# +# License: +# GPLv2 +# +# Usage: +# Link in /etc/munin/plugins/ as packetship_streams or packetship_bandwidth (or both) +# + +# change those to reflect your bind configuration (use plugin configuration) +# hostname file +if [ "$hostname" = "" ]; then + hostname="localhost" +fi + +# url path +if [ "$url" = "" ]; then + url="packetship/status.php" +fi + +# Get the mode from the plugin symlink name. +mode=${0#*_} + +# Check for valid mode. +if [[ "$mode" != "streams" && "$mode" != "bandwidth" ]]; then + echo "Link name must be packetship_streams or packetship_bandwidth." + exit 1 +fi + +# Fetch the XML formatted stats from packetship. +xml=$(wget -q -O - http://${hostname}/${url}) + +# Function to do simple string parsing of XML data. +read_dom () { + local IFS=\> + read -d \< ENTITY CONTENT + TAG_NAME=${ENTITY%% *} + ATTRIBUTES=${ENTITY#* } + + # Remove / characters from ATTRIBUTES if present. + ATTRIBUTES=${ATTRIBUTES//\//} + + if [[ $ENTITY = "" ]]; then + return 1 + fi + + return 0 +} + +# Get the number of pumps from the xml feed. +pumps_line=$(echo "$xml" | grep "' to '' + disk_stats=$(echo "$pump_section" | sed "0,//d" | sed -e "/<\/ps:disk>/,\$d" | grep $mode) + network_stats=$(echo "$pump_section" | sed "0,//d" | sed -e "/<\/ps:network>/,\$d" | grep $mode) + + # Output disk values for this pump. + while read_dom; do + # Ignore empty tags (First loop) + if [ "$TAG_NAME" = "" ]; then + continue + fi + + eval $ATTRIBUTES + + echo "pump"${pump}"_disk_value.value" $used + echo "pump"${pump}"_disk_max.value" $max + done <<< "$disk_stats" + + # Output network values for this pump + while read_dom; do + # Ignore empty tags (First loop) + if [ "$TAG_NAME" = "" ]; then + continue + fi + + eval $ATTRIBUTES + + echo "pump"${pump}"_network_value.value" $used + echo "pump"${pump}"_network_max.value" $max + done <<< "$network_stats" +done