4
# SysInfo OCF Resource Agent
5
# It records (in the CIB) various attributes of a node
7
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Br�e
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of version 2 of the GNU General Public License as
12
# published by the Free Software Foundation.
14
# This program is distributed in the hope that it would be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
# Further, this software is distributed without any warranty that it is
19
# free of the rightful claim of any third person regarding infringement
20
# or the like. Any license provided herein, whether implied or
21
# otherwise, applies only to this software file. Patent licenses, if
22
# any, provided herein do not apply to combinations of this program with
23
# other software, or any other product whatsoever.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write the Free Software Foundation,
27
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
29
#######################################################################
32
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
33
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
35
#######################################################################
40
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
41
<resource-agent name="SysInfo">
42
<version>1.0</version>
45
This is a SysInfo Resource Agent.
46
It records (in the CIB) various attributes of a node
49
os: Linux-2.4.26-gentoo-r14
51
cpu_info: Intel(R) Celeron(R) CPU 2.40GHz
62
cpu_info: Intel Core Duo
74
cpu_speed (Linux): bogomips
75
cpu_speed (Darwin): Ghz
78
<shortdesc lang="en">Records various node attributes in the CIB</shortdesc>
82
<parameter name="pidfile" unique="0">
83
<longdesc lang="en">PID file</longdesc>
84
<shortdesc lang="en">PID file</shortdesc>
85
<content type="string" default="$OCF_RESKEY_pidfile" />
88
<parameter name="delay" unique="0">
89
<longdesc lang="en">Interval to allow values to stabilize</longdesc>
90
<shortdesc lang="en">Dampening Delay</shortdesc>
91
<content type="string" default="0s" />
96
<action name="start" timeout="20s" />
97
<action name="stop" timeout="20s" />
98
<action name="monitor" timeout="20s" interval="60s"/>
99
<action name="meta-data" timeout="5" />
100
<action name="validate-all" timeout="20s" />
106
#######################################################################
111
echo -e "$name:\t$value"
112
${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n $name -v "$value"
117
UpdateStat arch "`uname -m`"
118
UpdateStat os "`uname -s`-`uname -r`"
122
mem=`top -l 1 | grep Mem: | awk '{print $10}'`
123
mem_used=`top -l 1 | grep Mem: | awk '{print $8}'`
124
mem=`SysInfo_mem_units $mem`
125
mem_used=`SysInfo_mem_units $mem_used`
126
mem_total=`expr $mem_used + $mem`
127
cpu_type=`system_profiler SPHardwareDataType | grep "CPU Type:"`
128
cpu_type=${cpu_type/*: /}
129
cpu_speed=`system_profiler SPHardwareDataType | grep "CPU Speed:" | awk '{print $3}'`
130
cpu_cores=`system_profiler SPHardwareDataType | grep "Number Of"`
131
cpu_cores=${cpu_cores/*: /}
134
if [ -f /proc/cpuinfo ]; then
135
cpu_type=`grep "model name" /proc/cpuinfo | head -n 1`
136
cpu_type=${cpu_type/*: /}
137
cpu_speed=`grep "bogomips" /proc/cpuinfo | head -n 1`
138
cpu_speed=${cpu_speed/*: /}
139
cpu_cores=`grep "^processor" /proc/cpuinfo | wc -l`
142
if [ -f /proc/meminfo ]; then
143
# meminfo results are in kB
144
mem=`grep "SwapFree" /proc/meminfo | awk '{print $2"k"}'`
145
if [ ! -z $mem ]; then
146
UpdateStat free_swap `SysInfo_mem_units $mem`
148
mem=`grep "Inactive" /proc/meminfo | awk '{print $2"k"}'`
149
mem_total=`grep "MemTotal" /proc/meminfo | awk '{print $2"k"}'`
151
mem=`top -n 1 | grep Mem: | awk '{print $7}'`
157
if [ x != x"$cpu_type" ]; then
158
UpdateStat cpu_info "$cpu_type"
161
if [ x != x"$cpu_speed" ]; then
162
UpdateStat cpu_speed "$cpu_speed"
165
if [ x != x"$cpu_cores" ]; then
166
UpdateStat cpu_cores "$cpu_cores"
170
load15=`echo ${loads} | awk '{print $10}'`
171
UpdateStat cpu_load $load15
173
if [ ! -z "$mem" ]; then
174
# Massage the memory values
175
UpdateStat ram_total `SysInfo_mem_units $mem_total`
176
UpdateStat ram_free `SysInfo_mem_units $mem`
180
# o df: -h flag not available on Solaris 8. (OK on 9, 10, ...) #FIXME#
181
# o tail: explicit "-n" not available in Solaris; instead simplify
182
# 'tail -n <c>' to the equivalent 'tail -<c>'.
183
disk=`df -h / | tail -1 | awk '{print $4}'`
184
if [ x != x"$disk" ]; then
185
UpdateStat root_free `SysInfo_hdd_units $disk`
189
SysInfo_mem_units() {
196
memlen=`expr ${#mem} - 1`
197
memlen_alt=`expr ${#mem} - 2`
198
if [ ${mem:$memlen:1} = "G" ]; then
199
mem="${mem:0:$memlen}"
200
if [ $mem != ${mem/./} ]; then
201
mem_before=${mem/.*/}
203
mem=$[mem_before*1024]
204
if [ ${#mem_after} = 0 ]; then
206
elif [ ${#mem_after} = 1 ]; then
207
mem=$[mem+100*$mem_after]
208
elif [ ${#mem_after} = 2 ]; then
209
mem=$[mem+10*$mem_after]
210
elif [ ${#mem_after} = 3 ]; then
211
mem=$[mem+$mem_after]
213
mem_after=${mem_after:0:3}
214
mem=$[mem+$mem_after]
217
elif [ ${mem:$memlen:1} = "M" ]; then
219
mem="${mem:0:$memlen}"
220
elif [ ${mem:$memlen:1} = "k" ]; then
221
mem="${mem:0:$memlen}"
223
mem=`expr $mem / 1024`
224
elif [ ${mem:$memlen_alt:2} = "kB" ]; then
225
mem="${mem:0:$memlen_alt}"
227
mem=`expr $mem / 1024`
228
elif [ ${mem:$memlen_alt:2} = "Mb" ]; then
229
mem="${mem:0:$memlen_alt}"
231
elif [ ${mem:$memlen_alt:2} = "MB" ]; then
232
mem="${mem:0:$memlen_alt}"
236
# Round to the next multiple of 50
237
memlen=`expr ${#mem} - 2`
238
mem_round="${mem:$memlen:2}"
239
if [ x$mem_round = x ]; then
241
elif [ $mem_round = "00" ]; then
244
mem_round=`echo $mem_round | sed 's/^0//'`
245
if [ $mem_round -lt "50" ]; then
247
mem=$[mem-$mem_round]
251
mem=$[mem-$mem_round]
257
SysInfo_hdd_units() {
259
disklen=`expr ${#disk} - 1`
260
disklen_alt=`expr ${#disk} - 2`
261
if [ ${disk:$disklen:1} = "G" ]; then
262
disk="${disk:0:$disklen}"
263
elif [ ${disk:$disklen:1} = "M" ]; then
264
disk="${disk:0:$disklen}"
266
disk=`expr $disk / 1024`
267
elif [ ${disk:$disklen:1} = "k" ]; then
268
disk="${disk:0:$disklen}"
270
disk=`expr $disk / 1048576`
271
elif [ ${disk:$disklen_alt:2} = "kB" ]; then
272
disk="${disk:0:$disklen_alt}"
274
disk=`expr $disk / 1048576`
275
elif [ ${disk:$disklen_alt:2} = "Mb" ]; then
276
disk="${disk:0:$disklen_alt}"
278
disk=`expr $disk / 1024`
279
elif [ ${disk:$disklen_alt:2} = "MB" ]; then
280
disk="${disk:0:$disklen_alt}"
282
disk=`expr $disk / 1024`
289
usage: $0 {start|stop|monitor|validate-all|meta-data}
291
Expects to have a fully populated OCF RA-compliant environment set.
296
echo $OCF_RESKEY_clone > $OCF_RESKEY_pidfile
302
rm $OCF_RESKEY_pidfile
307
if [ -f $OCF_RESKEY_pidfile ]; then
308
clone=`cat $OCF_RESKEY_pidfile`
311
if [ x$clone = x ]; then
312
rm $OCF_RESKEY_pidfile
313
exit $OCF_NOT_RUNNING
315
elif [ $clone = $OCF_RESKEY_clone ]; then
319
elif [ x$OCF_RESKEY_CRM_meta_globally_unique = xtrue
320
-o x$OCF_RESKEY_CRM_meta_globally_unique = xTrue
321
-o x$OCF_RESKEY_CRM_meta_globally_unique = xyes
322
-o x$OCF_RESKEY_CRM_meta_globally_unique = xYes
327
exit $OCF_NOT_RUNNING
334
if [ $# -ne 1 ]; then
339
: ${OCF_RESKEY_pidfile:="$HA_RSCTMP/SysInfo-${OCF_RESOURCE_INSTANCE}"}
340
: ${OCF_RESKEY_clone:="0"}
341
if [ x != x${OCF_RESKEY_delay} ]; then
342
OCF_RESKEY_delay="-d ${OCF_RESKEY_delay}"
345
case $__OCF_ACTION in
353
monitor) SysInfo_monitor
355
validate-all) SysInfo_validate
357
usage|help) SysInfo_usage
361
exit $OCF_ERR_UNIMPLEMENTED