diff --git a/extra/showscores.sh b/extra/showscores.sh index 19c02049eb..e28a29a2a3 100644 --- a/extra/showscores.sh +++ b/extra/showscores.sh @@ -1,143 +1,151 @@ #!/bin/bash - -# May 2008, Dominik Klein -# Display scores of Linux-HA resources - -# Known issues: -# * cannot get resource[_failure]_stickiness values for master/slave and clone resources -# if those values are configured as meta attributes of the master/slave or clone resource -# instead of as meta attributes of the encapsulated primitive +# +# Copyright (C) 2008-2009 Dominik Klein +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +# Display scores of Pacemaker resources if [ "$1" = "--help" -o "$1" = "-h" ] then + echo "showscores.sh - basically parsing ptest -Ls." echo "Usage: " echo "$0 (to display score information for all resources on all nodes sorted by resource name)" echo "$0 node (to display score information for all resources on all nodes sorted by nodename)" echo "$0 (to display score information for a specific resource on all nodes)" echo "$0 (to display score information for a specific resource on a specific node)" echo "$0 singlescore (to display just the score number (not additional info) for a specific resource on a specific node)" exit 0 fi tmpfile=/tmp/dkshowscorestmpfiledk tmpfile2=/tmp/dkshowscorestmpfile2dk -tmpfile3=/tmp/dkshowscorestmpfile3dk -if [ `crmadmin -D | cut -d' ' -f4` != `uname -n|tr "[:upper:]" "[:lower:]"` ] - then echo "Warning: Script is not running on DC. This will be slow." +#doesnt work in ais clusters +if ! ps -ef|grep -q -w aisexec; then + if [ `crmadmin -D | cut -d' ' -f4` != `uname -n|tr "[:upper:]" "[:lower:]"` ] + then echo "Warning: Script is not running on DC. This will be slow." + fi fi sortby=1 if [ "$1" = "node" ] then sortby=3 fi -export default_stickiness=`cibadmin -Q -o crm_config 2>/dev/null|grep "default[_-]resource[_-]stickiness"|grep -o -E 'value ?= ?"[^ ]*"'|cut -d '"' -f 2|grep -v "^$"` -export default_failurestickiness=`cibadmin -Q -o crm_config 2>/dev/null|grep "resource[_-]failure[_-]stickiness"|grep -o -E 'value ?= ?"[^ ]*"'|cut -d '"' -f 2|grep -v "^$"` +export default_stickiness=`crm_attribute -G -n default-resource-stickiness -Q 2>/dev/null` +export default_migrationthreshold=`crm_attribute -G -n migration-threshold -t rsc_defaults -Q 2>/dev/null` if [ -n "$1" -a "$1" != "node" ] then resource=$1 fi if [ -n "$2" ] then nodename=$2 fi -2>&1 ptest -LVs | grep -E "$resource" | grep -E "$nodename" | sed 's/dump_node_scores\:\ //' > $tmpfile +2>&1 ptest -Ls | grep -E "$resource" | grep -E "$nodename" > $tmpfile -parseline() { - line="$1" - node=`echo $line|cut -d " " -f 9|sed 's/://'` - res=`echo $line|cut -d " " -f 5` - score=`echo $line|cut -d " " -f 10|sed 's/1000000/INFINITY/'` +parseline() { + if ! echo $*|grep -q "promotion score"; then + shift; + fi + res=$1; shift; shift; shift; shift; + node=$(echo $1|sed 's/:$//'); shift; + score=$1; } get_stickiness() { res="$1" # get meta attribute resource_stickiness - if ! stickiness=`crm_resource -g resource_stickiness -r $res --meta 2>/dev/null` + if ! stickiness=`crm_resource -g resource-stickiness -r $res --meta -Q 2>/dev/null` then - # if that doesnt exist, get syntax like /dev/null | grep -E "/dev/null` + if ! migrationthreshold=`crm_resource -g migration-threshold -r $res --meta -Q 2>/dev/null` then # if that doesnt exist, use the default value - failurestickiness="$default_failurestickiness" + migrationthreshold="$default_migrationthreshold" fi } -get_failcount() { - res="$1" - node="$2" - failcount=`crm_failcount -G -r $res -U $node 2>/dev/null|grep -o -E 'value ?= ?INFINITY|value ?= ?[0-9]*'|cut -d '=' -f 2|grep -v "^$"` +get_failcount() { #usage $0 res node + failcount=`crm_failcount -G -r $1 -U $2 -Q 2>/dev/null|grep -o "^[0-9]*$"` } -unset group_resources -# display group scores -grep group_color $tmpfile | while read line -do - unset node res score stickiness failcount failurestickiness - parseline "$line" - get_stickiness $res - get_failcount $res $node - printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness - export group_resources="$res $group_resources" - echo $group_resources > $tmpfile3 -done >> $tmpfile2 +#determine the longest resource name to adjust width of the first column +max_res_id_len=0 +for res_id in $(tail -n +2 $tmpfile | sed 's/^[a-zA-Z_-]*\:\ //' | cut -d " " -f 1 | sort | uniq); do + res_id_len=$(echo $res_id|wc -c) + [ $res_id_len -gt $max_res_id_len ] && export max_res_id_len=$res_id_len; +done +# we'll later add "_(master)" to master scores, so add 9 chars to max_res_id_len +max_res_id_len=$(($max_res_id_len+9)) + +#same for nodenames +max_node_id_len=0 +for node_id in $(sed 's/^[a-zA-Z_-]*\:\ //' $tmpfile | cut -d " " -f 5 | grep -v "^$" | sort | uniq | sed 's/\://'); do + node_id_len=$(echo $node_id|wc -c) + [ $node_id_len -gt $max_node_id_len ] && export max_node_id_len=$node_id_len; +done # display allocation scores -grep -v master_color $tmpfile | grep -v clone_color | grep -v group_color | while read line +grep native_color $tmpfile | while read line do - unset node res score stickiness failcount failurestickiness - parseline "$line" - #skip group resources - if grep -q -w $res $tmpfile3 - then - #echo skipping $res as it is part of a group and their score is shown in the group_color lines - continue - fi + unset node res score stickiness failcount migrationthreshold + parseline $line get_stickiness $res get_failcount $res $node - printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness + printf "%-${max_res_id_len}s%-10s%-${max_node_id_len}s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $migrationthreshold done >> $tmpfile2 # display promotion scores -grep master_color $tmpfile | while read line +grep "promotion score" $tmpfile | while read line do - unset node res score stickiness failcount failurestickiness - parseline "$line" - inflines=`grep master_color $tmpfile | grep $res | grep 1000000 | wc -l` + unset node res score stickiness failcount migrationthreshold + parseline $line + # Skip if node=none. Sometimes happens for clones but is internally mapped to another clone instance, so this is skipped + [ "$node" = "none" ] && continue + inflines=`grep "promotion score" $tmpfile | grep $res | grep 1000000 | wc -l` if [ $inflines -eq 1 ] then # [10:24] the non INFINITY values are the true ones # [10:25] except for when the actually resulting score is [-]INFINITY # [10:25] yeah - actualline=`grep master_color $tmpfile | grep $res | grep -v 1000000` - parseline "$actualline" + actualline=`grep "promotion score" $tmpfile | grep $res | grep -v 1000000` + parseline $actualline fi get_stickiness $res get_failcount $res $node res=$res"_(master)" - printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness + printf "%-${max_res_id_len}s%-10s%-${max_node_id_len}s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $migrationthreshold done | sort | uniq >> $tmpfile2 - if [ "$3" = "singlescore" ] then sed 's/ */ /g' $tmpfile2 | cut -d ' ' -f 2 | tail -n 1 else # Heading - printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" "Resource" "Score" "Node" "Stickiness" "#Fail" "Fail-Stickiness" + printf "%-${max_res_id_len}s%-10s%-${max_node_id_len}s%-11s%-9s%-16s\n" "Resource" "Score" "Node" "Stickiness" "#Fail" "Migration-Threshold" sort -k $sortby $tmpfile2 fi -rm -f $tmpfile $tmpfile2 $tmpfile3 +rm -f $tmpfile $tmpfile2