Pacemaker 0.6

view contrib/showscores.sh @ 12495:e4cbf2a152e7

Medium: PE: Prefer the current location if it is one of a group of nodes with the same (highest) score
author Andrew Beekhof <abeekhof@suse.de>
date Thu Jul 03 12:19:55 2008 +0200 (2 days ago)
parents 331cc60ebd40
children
line source
1#!/bin/bash
2
3# May 2008, Dominik Klein
4# Display scores of Linux-HA resources
5
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
10
11if [ "$1" = "--help" -o "$1" = "-h" ]
12then
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
20fi
21
22tmpfile=/tmp/dkshowscorestmpfiledk
23tmpfile2=/tmp/dkshowscorestmpfile2dk
24tmpfile3=/tmp/dkshowscorestmpfile3dk
25
26if [ `crmadmin -D | cut -d' ' -f4` != `uname -n|tr "[:upper:]" "[:lower:]"` ]
27 then echo "Warning: Script is not running on DC. This will be slow."
28fi
29
30sortby=1
31if [ "$1" = "node" ]
32then
33 sortby=3
34fi
35
36export default_stickiness=`cibadmin -Q -o crm_config 2>/dev/null|grep "default[_-]resource[_-]stickiness"|grep -o -E 'value ?= ?"[^ ]*"'|cut -d '"' -f 2|grep -v "^$"`
37export default_failurestickiness=`cibadmin -Q -o crm_config 2>/dev/null|grep "resource[_-]failure[_-]stickiness"|grep -o -E 'value ?= ?"[^ ]*"'|cut -d '"' -f 2|grep -v "^$"`
38
39if [ -n "$1" -a "$1" != "node" ]
40then
41 resource=$1
42fi
43if [ -n "$2" ]
44then
45 nodename=$2
46fi
47
482>&1 ptest -LVs | grep -E "$resource" | grep -E "$nodename" | sed 's/dump_node_scores\:\ //' > $tmpfile
49
50parseline() {
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}
56
57get_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
69
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}
77
78get_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}
83
84unset group_resources
85# display group scores
86grep group_color $tmpfile | while read line
87do
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
95done >> $tmpfile2
96
97# display allocation scores
98grep -v master_color $tmpfile | grep -v clone_color | grep -v group_color | while read line
99do
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
111done >> $tmpfile2
112
113# display promotion scores
114grep master_color $tmpfile | while read line
115do
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
131done | sort | uniq >> $tmpfile2
132
133
134if [ "$3" = "singlescore" ]
135then
136 sed 's/ */ /g' $tmpfile2 | cut -d ' ' -f 2 | tail -n 1
137else
138 # Heading
139 printf "%-20s%-10s%-16s%-11s%-9s%-16s\n" "Resource" "Score" "Node" "Stickiness" "#Fail" "Fail-Stickiness"
140 sort -k $sortby $tmpfile2
141fi
142
143rm $tmpfile $tmpfile2 $tmpfile3