From 819e2a6fe923eb715023de0c9bf77f563e02b1cf Mon Sep 17 00:00:00 2001 From: Dave Fennell Date: Wed, 2 Jan 2013 13:58:27 +0000 Subject: [PATCH 1/3] Added plugin for packetship media streaming server. --- plugins/streaming/packetship_ | 122 ++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 plugins/streaming/packetship_ diff --git a/plugins/streaming/packetship_ b/plugins/streaming/packetship_ new file mode 100755 index 00000000..b2b645b0 --- /dev/null +++ b/plugins/streaming/packetship_ @@ -0,0 +1,122 @@ +#!/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}) + +# Disk stats are from '' to '' +disk_stats=$(echo "$xml" | sed "0,//d" | sed -e "/<\/ps:disk>/,\$d" | grep $mode) +network_stats=$(echo "$xml" | sed "0,//d" | sed -e "/<\/ps:network>/,\$d" | grep $mode) + +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 +} + +# echo $stats + +# Config mode. +if [ "$1" = "config" ]; then + echo 'graph_args --lower-limit 0' + echo 'graph_category streaming' + echo 'graph_info '${mode}' statistics for packetship server' + echo 'graph_scale no' + echo 'graph_title Packetship '${mode} + + if [ "$mode" = "streams" ]; then + echo 'graph_vlabel streams' + else + echo 'graph_vlabel bandwidth (Mbit/sec)' + fi + + echo "disk_value.label Disk current" + echo "disk_value.info Disk current" ${mode} + echo "disk_value.type GAUGE" + + echo "disk_max.label Disk max" + echo "disk_max.info Disk max" ${mode} + echo "disk_max.type GAUGE" + + echo "network_value.label Network current" + echo "network_value.info Network current" ${mode} + echo "network_value.type GAUGE" + + echo "network_max.label Network max" + echo "network_max.info Network max" ${mode} + echo "network_max.type GAUGE" + + # If dirty config capability is enabled then fall through + # to output the data with the config information. + if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then + exit 0 + fi +fi + +while read_dom; do + # Ignore empty tags (First loop) + if [ "$TAG_NAME" = "" ]; then + continue + fi + + eval $ATTRIBUTES + + echo "disk_value.value " $used + echo "disk_max.value " $max +done <<< "$disk_stats" + +while read_dom; do + # Ignore empty tags (First loop) + if [ "$TAG_NAME" = "" ]; then + continue + fi + + eval $ATTRIBUTES + + echo "network_value.value " $used + echo "network_max.value " $max +done <<< "$network_stats" From 9bfb1101b5076a31c7e8f806cf06626be183fbd4 Mon Sep 17 00:00:00 2001 From: Dave Fennell Date: Wed, 2 Jan 2013 14:17:00 +0000 Subject: [PATCH 2/3] Slight fix to output format of packetship_ plugin. --- plugins/streaming/packetship_ | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/streaming/packetship_ b/plugins/streaming/packetship_ index b2b645b0..c527f392 100755 --- a/plugins/streaming/packetship_ +++ b/plugins/streaming/packetship_ @@ -105,8 +105,8 @@ while read_dom; do eval $ATTRIBUTES - echo "disk_value.value " $used - echo "disk_max.value " $max + echo "disk_value.value" $used + echo "disk_max.value" $max done <<< "$disk_stats" while read_dom; do @@ -117,6 +117,6 @@ while read_dom; do eval $ATTRIBUTES - echo "network_value.value " $used - echo "network_max.value " $max + echo "network_value.value" $used + echo "network_max.value" $max done <<< "$network_stats" From 2912117ad4835febaf101aefcbd01e704159ec72 Mon Sep 17 00:00:00 2001 From: Dave Fennell Date: Thu, 3 Jan 2013 17:36:27 +0000 Subject: [PATCH 3/3] Updated packetship plugin to support multiple pumps. --- plugins/streaming/packetship_ | 107 +++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/plugins/streaming/packetship_ b/plugins/streaming/packetship_ index c527f392..a9ec0964 100755 --- a/plugins/streaming/packetship_ +++ b/plugins/streaming/packetship_ @@ -38,10 +38,7 @@ fi # Fetch the XML formatted stats from packetship. xml=$(wget -q -O - http://${hostname}/${url}) -# Disk stats are from '' to '' -disk_stats=$(echo "$xml" | sed "0,//d" | sed -e "/<\/ps:disk>/,\$d" | grep $mode) -network_stats=$(echo "$xml" | sed "0,//d" | sed -e "/<\/ps:network>/,\$d" | grep $mode) - +# Function to do simple string parsing of XML data. read_dom () { local IFS=\> read -d \< ENTITY CONTENT @@ -58,7 +55,24 @@ read_dom () { return 0 } -# echo $stats +# 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) - eval $ATTRIBUTES + # Output disk values for this pump. + while read_dom; do + # Ignore empty tags (First loop) + if [ "$TAG_NAME" = "" ]; then + continue + fi - echo "network_value.value" $used - echo "network_max.value" $max -done <<< "$network_stats" + 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