contrib/showscores.sh

12 months ago

author
hg@oss-1.clusterlabs.org
date
Wed Mar 25 08:22:05 2009 -0400
branch
stable-0.6
changeset 12584
06f6bfb052ee
parent 12144
331cc60ebd40
permissions
-rw-r--r--

Hg: Hack so that new clones check out the stable-1.0 branch instead of the unused 'default' branch

     1 #!/bin/bash
     3 # May 2008, Dominik Klein
     4 # Display scores of Linux-HA resources
     6 # Known issues:
     7 # * cannot get resource[_failure]_stickiness values for master/slave and clone resources
     8 #   if those values are configured as meta attributes of the master/slave or clone resource
     9 #   instead of as meta attributes of the encapsulated primitive
    11 if [ "$1" = "--help" -o "$1" = "-h" ]
    12 then
    13 	echo "Usage: "
    14 	echo "$0 (to display score information for all resources on all nodes sorted by resource name)"
    15 	echo "$0 node (to display score information for all resources on all nodes sorted by nodename)"
    16 	echo "$0 <resource-id> (to display score information for a specific resource on all nodes)"
    17 	echo "$0 <resource-id> <nodename> (to display score information for a specific resource on a specific node)"
    18 	echo "$0 <resource-id> <nodename> singlescore (to display just the score number (not additional info) for a specific resource on a specific node)"
    19 	exit 0
    20 fi
    22 tmpfile=/tmp/dkshowscorestmpfiledk
    23 tmpfile2=/tmp/dkshowscorestmpfile2dk
    24 tmpfile3=/tmp/dkshowscorestmpfile3dk
    26 if [ `crmadmin -D | cut -d' ' -f4` != `uname -n|tr "[:upper:]" "[:lower:]"` ] 
    27   then echo "Warning: Script is not running on DC. This will be slow."
    28 fi
    30 sortby=1
    31 if [ "$1" = "node" ] 
    32 then
    33 	sortby=3
    34 fi
    36 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 "^$"`
    37 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 "^$"`
    39 if [ -n "$1" -a "$1" != "node" ]
    40 then
    41       resource=$1
    42 fi
    43 if [ -n "$2" ]
    44 then
    45       nodename=$2
    46 fi
    48 2>&1 ptest -LVs | grep -E "$resource" | grep -E "$nodename" | sed 's/dump_node_scores\:\ //' > $tmpfile
    50 parseline() {
    51 	line="$1"
    52         node=`echo $line|cut -d " " -f 9|sed 's/://'`
    53         res=`echo $line|cut -d " " -f 5`
    54         score=`echo $line|cut -d " " -f 10|sed 's/1000000/INFINITY/'`
    55 }
    57 get_stickiness() {
    58 	res="$1"
    59 	# get meta attribute resource_stickiness
    60 	if ! stickiness=`crm_resource -g resource_stickiness -r $res --meta 2>/dev/null`
    61 	then
    62 		# if that doesnt exist, get syntax like <primitive resource-stickiness="100"
    63 		if ! stickiness=`crm_resource -x -r $res 2>/dev/null | grep -E "<master|<primitive|<clone" | grep -o "resource[_-]stickiness=\"[0-9]*\"" | cut -d '"' -f 2 | grep -v "^$"`
    64 		then 
    65 			# if no resource-specific stickiness is confiugured, use the default value
    66 			stickiness="$default_stickiness"
    67 		fi	
    68 	fi
    70 	# get meta attribute resource_failure_stickiness
    71 	if ! failurestickiness=`crm_resource -g resource_failure_stickiness -r $res --meta 2>/dev/null`
    72 	then
    73 		# if that doesnt exist, use the default value
    74 		failurestickiness="$default_failurestickiness"
    75 	fi	
    76 }
    78 get_failcount() {
    79 	res="$1"
    80 	node="$2"
    81         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 "^$"`
    82 }
    84 unset group_resources
    85 # display group scores
    86 grep group_color $tmpfile | while read line
    87 do
    88         unset node res score stickiness failcount failurestickiness
    89         parseline "$line"
    90         get_stickiness $res
    91         get_failcount $res $node
    92         printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness
    93 	export group_resources="$res $group_resources"
    94 	echo $group_resources > $tmpfile3
    95 done >> $tmpfile2
    97 # display allocation scores
    98 grep -v master_color $tmpfile | grep -v clone_color | grep -v group_color | while read line
    99 do
   100 	unset node res score stickiness failcount failurestickiness
   101 	parseline "$line"
   102 	#skip group resources
   103 	if grep -q -w $res $tmpfile3
   104 	then
   105 		#echo skipping $res as it is part of a group and their score is shown in the group_color lines
   106 		continue
   107 	fi
   108 	get_stickiness $res
   109 	get_failcount $res $node
   110 	printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness
   111 done >> $tmpfile2
   113 # display promotion scores
   114 grep master_color $tmpfile | while read line
   115 do
   116 	unset node res score stickiness failcount failurestickiness
   117 	parseline "$line"
   118 	inflines=`grep master_color $tmpfile | grep $res | grep 1000000 | wc -l`
   119 	if [ $inflines -eq 1 ]
   120 	then
   121 		# [10:24] <beekhof> the non INFINITY values are the true ones
   122 		# [10:25] <kleind> except for when the actually resulting score is [-]INFINITY
   123 		# [10:25] <beekhof> yeah
   124 		actualline=`grep master_color $tmpfile | grep $res | grep -v 1000000`
   125 		parseline "$actualline"
   126 	fi
   127 	get_stickiness $res
   128 	get_failcount $res $node
   129 	res=$res"_(master)"
   130 	printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" $res $score $node $stickiness $failcount $failurestickiness
   131 done | sort | uniq >> $tmpfile2
   134 if [ "$3" = "singlescore" ]
   135 then
   136 	sed 's/  */ /g' $tmpfile2 | cut -d ' ' -f 2 | tail -n 1
   137 else
   138 	# Heading
   139 	printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" "Resource" "Score" "Node" "Stickiness" "#Fail" "Fail-Stickiness"
   140 	sort -k $sortby $tmpfile2
   141 fi
   143 rm $tmpfile $tmpfile2 $tmpfile3

mercurial