Please find attached a patch to the pacemaker SysInfo RA.

This patch adds 2 new features:

- Allow a list of filesystems/devices to be queried for free space
('disks' param)

For e.g. disk="/dev/sda1 /tmp /home/user", these will be reported as
$disk_free with some munging of slashes:
dev_sda1_free=...
tmp_free=...
home_user_free=...

- Allow the specification of the unit to report disk-free attributes in
('disk_unit' param) - accepts B,K,M,G,T,P (defaults to G as before).

Note: The root_free attribute is still created as before, even if no
'disks' are specified, and will continue to default to G unless
'disk_unit is specified.

Please let me know if you find any bugs, errors or omissions with this
patch.

Thanks,

Matthew


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
--- SysInfo	2010-11-19 15:15:57.000000000 +0000
+++ SysInfo.new	2010-11-19 15:23:28.000000000 +0000
@@ -69,9 +69,9 @@
 Units:
    free_swap: Mb
    ram_*:     Mb
-   root_free: Gb
    cpu_speed (Linux): bogomips
    cpu_speed (Darwin): Ghz
+   *_free:    GB (or user-defined: disk_unit)
 
 </longdesc>
 <shortdesc lang="en">SysInfo resource agent</shortdesc>
@@ -90,6 +90,26 @@
 <content type="string" default="0s" />
 </parameter>
 
+<parameter name="disks" unique="1">
+<longdesc lang="en">
+Filesystems or Paths to be queried for free disk space as a SPACE separated list - e.g "/dev/sda1 /tmp".
+Results will be written to an attribute with leading slashes removed, and other slashes replaced with underscore, and the word 'free' appended - e.g /dev/sda1 -> dev_sda1_free
+Note: The root filesystem '/' is always queried to an attribute named 'root_free'
+</longdesc>
+<shortdesc lang="en">List of Filesytems/Paths to query for free disk space</shortdesc>
+content type="string" />
+</parameter>
+
+<parameter name="disk_unit" unique="1">
+<longdesc lang="en">
+Unit to report disk free space in.
+Can be one of: B, K, M, G, T, P (case-insensitive)
+</longdesc>
+<shortdesc lang="en">Unit to report disk free space in</shortdesc>
+content type="string" default="G"/>
+</parameter>
+
+
 </parameters>
 <actions>
 <action name="start"   timeout="90" />
@@ -176,13 +196,16 @@
     fi
 
     # Portability notes:
-    #   o df:   -h flag not available on Solaris 8.  (OK on 9, 10, ...) #FIXME#
     #   o tail: explicit "-n" not available in Solaris; instead simplify
     #	  'tail -n <c>' to the equivalent 'tail -<c>'.
-    disk=`df -h / | tail -1 | awk '{print $4}'`
-    if [ x != x"$disk" ]; then
-        UpdateStat root_free `SysInfo_hdd_units $disk`
-    fi
+    for disk in "/" ${OCF_RESKEY_disks}; do
+	unset disk_free disk_label
+	disk_free=`df -k ${disk} | tail -1 | awk '{print $4}'`
+	if [ x != x"$disk_free" ]; then
+	    disk_label=`echo $disk | sed -e 's#^/$#root#;s#^/*##;s#/#_#g'`
+	    UpdateStat ${disk_label}_free `SysInfo_hdd_units $disk_free`
+	fi
+    done
 }
 
 SysInfo_mem_units() {
@@ -251,33 +274,37 @@
 }
 
 SysInfo_hdd_units() {
-    disk=$1
-    disklen=`expr ${#disk} - 1`
-    disklen_alt=`expr ${#disk} - 2`
-    if [ ${disk:$disklen:1} = "G" ]; then
-	disk="${disk:0:$disklen}"
-    elif [ ${disk:$disklen:1} = "M" ]; then
-	disk="${disk:0:$disklen}"
-	disk=${disk/.*/}
-	disk=`expr $disk / 1024`
-    elif [ ${disk:$disklen:1} = "k" ]; then
-	disk="${disk:0:$disklen}"
-	disk=${disk/.*/}
-	disk=`expr $disk / 1048576`
-    elif [ ${disk:$disklen_alt:2} = "kB" ]; then
-	disk="${disk:0:$disklen_alt}"
-	disk=${disk/.*/}
-	disk=`expr $disk / 1048576`
-    elif [ ${disk:$disklen_alt:2} = "Mb" ]; then
-	disk="${disk:0:$disklen_alt}"
-	disk=${disk/.*/}
-	disk=`expr $disk / 1024`
-    elif [ ${disk:$disklen_alt:2} = "MB" ]; then
-	disk="${disk:0:$disklen_alt}"
-	disk=${disk/.*/}
-	disk=`expr $disk / 1024`
+    disk_size=$1
+    disk_unit=${OCF_RESKEY_disk_unit}
+    if [ -z $disk_unit ]; then
+	disk_unit="G"
     fi
-    echo $disk    
+    
+    case $disk_unit in
+	[Pp])
+            disk_size=$((disk_size/1024/1024/1024/1024))
+	    ;;
+	[Tt])
+            disk_size=$((disk_size/1024/1024/1024))
+	    ;;
+	[Gg])
+            disk_size=$((disk_size/1024/1024))
+            ;;
+        [Mm])
+            disk_size=$((disk_size/1024))
+            ;;
+        [Kk])
+	    #Already in KB
+            ;;
+        [Bb])
+            disk_size=$((disk_size*1024))
+            ;;
+           *)
+	    ocf_log err "disk_unit set to invalid unit"
+	    exit $OCF_ERR_ARGS
+    esac
+
+    echo $disk_size
 }
 
 SysInfo_usage() {

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to