Created
September 10, 2023 11:05
-
-
Save leighb2282/6066c3ad603c2f17e848440b42411f45 to your computer and use it in GitHub Desktop.
bash script used for additional granular monitoring of live ingest servers.
This file contains hidden or 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
| #!/bin/bash | |
| # status-lingest.sh Version 0.40 | |
| # Script to poll for Lingest status | |
| # Previous Update: Set up functions to retrieve each regions data separately, this allows for each region to be polled individually via cron which means faster cycle times | |
| # Latest Update: Record data to file instead of just reporting it to stdout. | |
| # Next update: Add current date (from the lingest) into dataset, potentially add bgbroadcastd checks too. | |
| # Leigh Burton | |
| # Last updated: Mon 16 Jun 2014 12:03:43 PDT | |
| # Usage Function | |
| usage() | |
| { | |
| echo "Available Switches:" | |
| echo "-u US Lingest Checks" | |
| echo "-e EU Lingest Checks" | |
| echo "-i IN Lingest Checks" | |
| echo "-a AP Lingest Checks" | |
| } | |
| if [ "$#" == "0" ]; then | |
| usage | |
| exit 1 | |
| fi | |
| # Setting data Location | |
| hname=$(echo $HOSTNAME) | |
| opssrv="" | |
| if [ "$hname" == $opssrv ]; then | |
| dataloc="/var/www/data/lingest" # sreops data location | |
| elif [ "$hname" == "Chimera" ]; then | |
| dataloc="/home/lburton/Documents/monitoring/data/lingest" # Chimera data location | |
| else | |
| echo "Not sreops or Chimera, exiting" # Only sreops or Chimera can be valid polling nodes | |
| exit 1 | |
| fi | |
| echo $hname [$dataloc] | |
| echo "" | |
| # Pull different regions active lingests | |
| usactive=$(curl -ks "############/api/r/v2/list_nodegroups.php?format=json&nodegroup=#########" | sed 's/description/"\n"/g' | awk -F'[:|,]' '{print $2 $4}' | sed 's/"//g;s/location//g' | awk '{print $3}' | sort -u | grep "sjc\|iad\|ord\|dfw\|mia") | |
| apactive=$(curl -ks "############/api/r/v2/list_nodegroups.php?format=json&nodegroup=#########" | sed 's/description/"\n"/g' | awk -F'[:|,]' '{print $2 $4}' | sed 's/"//g;s/location//g' | awk '{print $3}' | sort -u | grep "hkg\|nrt\|sin") | |
| euactive=$(curl -ks "############/api/r/v2/list_nodegroups.php?format=json&nodegroup=#########" | sed 's/description/"\n"/g' | awk -F'[:|,]' '{print $2 $4}' | sed 's/"//g;s/location//g' | awk '{print $3}' | sort -u | grep "lhr\|fra\|cdg") | |
| inactive=$(curl -ks "############/api/r/v2/list_nodegroups.php?format=json&nodegroup=#########" | sed 's/description/"\n"/g' | awk -F'[:|,]' '{print $2 $4}' | sed 's/"//g;s/location//g' | awk '{print $3}' | sort -u | grep "maa\|hyd\|blr\|bom\|del") | |
| # Print Schema for easy reading while in development | |
| echo "Schema: Name|#Streams|#Killed|#Pulls|%EGcpu|%EGmem|%LOcpu|%LOmem|%BGBDcpu|%BGBDmem" | |
| ##################### | |
| # US Lingest Checks # | |
| ##################### | |
| uschk() | |
| { | |
| for server in $usactive | |
| do | |
| # Grab LO & EG pid $server | |
| lopid=$(ssh -qCo ConnectTimeout=2 lburton@$server "cat /var/run/WowzaMediaServer-LiveOrigin.pid") | |
| egpid=$(ssh -qCo ConnectTimeout=2 lburton@$server "cat /var/run/WowzaMediaServer.pid") | |
| bgbdpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps auxwww | grep bg[b]roadcastd" | awk '{print $2}') | |
| # Grab CPU & Memory for each of those pids | |
| lostat=$(ssh -qCo ConnectTimeout=2 lburton@$server "ps -p $lopid -o %cpu,%mem | tail -n 1") | |
| egstat=$(ssh -qCo ConnectTimeout=2 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| bgbdstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| # Grab EG stream info (Schema: |Name|#Streams|#Killed|#Pulls| ) | |
| egdet=$(curl -ks $server:21935/egstatus.xml| awk -F'[:|,]' '{print $3, $16, $18, $20}' | grep lingest) | |
| # Combine info into a single variable (Schema: |Name|#Streams|#Killed|#Pulls|%EGcpu|%EGmem|%LOcpu|%LOmem|%BGBDcpu|%BGBDmem ) | |
| lindet=$(echo $egdet $egstat $lostat $bgbdstat) | |
| # Output information | |
| echo $lindet >> $dataloc/ustemp | |
| done | |
| cat $dataloc/ustemp | |
| mv $dataloc/ustemp $dataloc/usdata | |
| ls -l $dataloc | |
| } | |
| ##################### | |
| # EU Lingest Checks # | |
| ##################### | |
| euchk() | |
| { | |
| for server in $euactive | |
| do | |
| # Grab LO & EG pid | |
| lopid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer-LiveOrigin.pid") | |
| egpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer.pid") | |
| bgbdpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps auxwww | grep bg[b]roadcastd" | awk '{print $2}') | |
| #Grab CPU & Memory for each of those pids | |
| lostat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $lopid -o %cpu,%mem | tail -n 1") | |
| egstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| bgbdstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| # Grab EG stream info (Schema: |Name|#Streams|#Killed|#Pulls| ) | |
| egdet=$(curl -ks $server:21935/egstatus.xml| awk -F'[:|,]' '{print $3, $16, $18, $20}' | grep lingest) | |
| # Combine info into a single variable (Schema: |Name|#Streams|#Killed|#Pulls|%EGcpu|%EGmem|%LOcpu|%LOmem|%BGBDcpu|%BGBDmem ) | |
| lindet=$(echo $egdet $egstat $lostat $bgbdstat) | |
| # Output information | |
| echo $lindet >> $dataloc/eutemp | |
| done | |
| cat $dataloc/eutemp | |
| mv $dataloc/eutemp $dataloc/eudata | |
| ls -l $dataloc | |
| } | |
| ##################### | |
| # IN Lingest Checks # | |
| ##################### | |
| inchk() | |
| { | |
| # Uncommend below for testing | |
| for server in $inactive | |
| do | |
| # Grab LO & EG pid | |
| lopid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer-LiveOrigin.pid") | |
| egpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer.pid") | |
| bgbdpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps auxwww | grep bg[b]roadcastd" | awk '{print $2}') | |
| #Grab CPU & Memory for each of those pids | |
| lostat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $lopid -o %cpu,%mem | tail -n 1") | |
| egstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| bgbdstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| # Grab EG stream info (Schema: |Name|#Streams|#Killed|#Pulls| ) | |
| egdet=$(curl -ks $server:21935/egstatus.xml| awk -F'[:|,]' '{print $3, $16, $18, $20}' | grep lingest) | |
| # Combine info into a single variable (Schema: |Name|#Streams|#Killed|#Pulls|%EGcpu|%EGmem|%LOcpu|%LOmem|%BGBDcpu|%BGBDmem ) | |
| lindet=$(echo $egdet $egstat $lostat $bgbdstat) | |
| # Output information | |
| echo $lindet >> $dataloc/intemp | |
| done | |
| cat $dataloc/intemp | |
| mv $dataloc/intemp $dataloc/indata | |
| ls -l $dataloc | |
| } | |
| ##################### | |
| # AP Lingest Checks # | |
| ##################### | |
| apchk() | |
| { | |
| for server in $apactive | |
| do | |
| # Grab LO & EG pid | |
| lopid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer-LiveOrigin.pid") | |
| egpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "cat /var/run/WowzaMediaServer.pid") | |
| bgbdpid=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps auxwww | grep bg[b]roadcastd" | awk '{print $2}') | |
| #Grab CPU & Memory for each of those pids | |
| lostat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $lopid -o %cpu,%mem | tail -n 1") | |
| egstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| bgbdstat=$(ssh -qCo ConnectTimeout=5 lburton@$server "ps -p $egpid -o %cpu,%mem | tail -n 1") | |
| # Grab EG stream info (Schema: |Name|#Streams|#Killed|#Pulls| ) | |
| egdet=$(curl -ks $server:21935/egstatus.xml| awk -F'[:|,]' '{print $3, $16, $18, $20}' | grep lingest) | |
| # Combine info into a single variable (Schema: |Name|#Streams|#Killed|#Pulls|%EGcpu|%EGmem|%LOcpu|%LOmem|%BGBDcpu|%BGBDmem ) | |
| lindet=$(echo $egdet $egstat $lostat $bgbdstat) | |
| # Output information | |
| echo $lindet >> $dataloc/aptemp | |
| done | |
| cat $dataloc/aptemp | |
| mv $dataloc/aptemp $dataloc/apdata | |
| ls -l $dataloc | |
| } | |
| while getopts "u e i a" o; do | |
| case "${o}" in | |
| u) | |
| uschk | |
| exit 0 | |
| ;; | |
| e) | |
| euchk | |
| exit 0 | |
| ;; | |
| i) | |
| inchk | |
| exit 0 | |
| ;; | |
| a) | |
| apchk | |
| exit 0 | |
| ;; | |
| \?) | |
| echo "Invalid option: -$o" >&2 | |
| usage | |
| exit 1 | |
| esac | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment