Merge ~rodsmith/plainbox-provider-checkbox:fix-disk-cpu-load into plainbox-provider-checkbox:master

Proposed by Rod Smith
Status: Merged
Approved by: Jeff Lane 
Approved revision: 507507ebc8bdbfd1ec4c1a62b5e393cb3f08e072
Merged at revision: 15ec3e8bf85e0aac21729f41a5fa4c993c06270a
Proposed branch: ~rodsmith/plainbox-provider-checkbox:fix-disk-cpu-load
Merge into: plainbox-provider-checkbox:master
Diff against target: 68 lines (+19/-2)
1 file modified
bin/disk_cpu_load (+19/-2)
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Review via email: mp+314029@code.launchpad.net

Description of the change

This MR fixes bug #1641684, at least minimally. (More extensive verbose-mode messages might conceivably be desired in some cases, but I thought it best to start with the basics.) Specifically, there are two chances:

* The cpu_load variable is now calculated via the "bc" command rather
  than with bash's built-in arithmetic. The script failure was caused
  by the ultra-low CPU load of disk on the P8 server, which produced
  a fractional (0.01) CPU load; but bash's integer arithmetic caused
  this to produce an error, so the "set -e" in the script caused a
  failure. Using "bc" to do the calculation works around this problem.
* A new "--verbose" option, if used, produces messages to be displayed
  reporting when key actions are started and on the values of some
  intermediate variables.

To post a comment you must log in.
Revision history for this message
Jeff Lane  (bladernr) wrote :

Cool. Thanks for addressing that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/disk_cpu_load b/bin/disk_cpu_load
2index 5e0d0eb..93b1569 100755
3--- a/bin/disk_cpu_load
4+++ b/bin/disk_cpu_load
5@@ -24,13 +24,14 @@
6 #
7 # Usage:
8 # disk_cpu_load [ --max-load <load> ] [ --xfer <mebibytes> ]
9-# [ <device-filename> ]
10+# [ --verbose ] [ <device-filename> ]
11 #
12 # Parameters:
13 # --max-load <load> -- The maximum acceptable CPU load, as a percentage.
14 # Defaults to 30.
15 # --xfer <mebibytes> -- The amount of data to read from the disk, in
16 # mebibytes. Defaults to 4096 (4 GiB).
17+# --verbose -- If present, produce more verbose output
18 # <device-filename> -- This is the WHOLE-DISK device filename (with or
19 # without "/dev/"), e.g. "sda" or "/dev/sda". The
20 # script finds a filesystem on that device, mounts
21@@ -44,6 +45,7 @@ set -e
22 get_params() {
23 disk_device="/dev/sda"
24 short_device="sda"
25+ verbose=0
26 max_load=30
27 xfer=4096
28 while [ $# -gt 0 ] ; do
29@@ -54,6 +56,8 @@ get_params() {
30 --xfer) xfer="$2"
31 shift
32 ;;
33+ --verbose) verbose=1
34+ ;;
35 *) disk_device="/dev/$1"
36 disk_device=`echo $disk_device | sed "s/\/dev\/\/dev/\/dev/g"`
37 short_device=$(echo $disk_device | sed "s/\/dev//g")
38@@ -109,8 +113,15 @@ compute_cpu_load() {
39 let diff_total=${end_total}-${start_total}
40 let diff_used=$diff_total-$diff_idle
41
42+ if [ "$verbose" == "1" ] ; then
43+ echo "Start CPU time = $start_total"
44+ echo "End CPU time = $end_total"
45+ echo "CPU time used = $diff_used"
46+ echo "Total elapsed time = $diff_total"
47+ fi
48+
49 if [ "$diff_total" != "0" ] ; then
50- let cpu_load=($diff_used*100)/$diff_total
51+ cpu_load=$(echo "($diff_used*100)/$diff_total" | bc)
52 else
53 cpu_load=0
54 fi
55@@ -127,7 +138,13 @@ echo "Testing CPU load when reading $xfer MiB from $disk_device"
56 echo "Maximum acceptable CPU load is $max_load"
57 blockdev --flushbufs $disk_device
58 start_load="$(grep "cpu " /proc/stat | tr -s " " | cut -d " " -f 2-)"
59+if [ "$verbose" == "1" ] ; then
60+ echo "Beginning disk read...."
61+fi
62 dd if="$disk_device" of=/dev/null bs=1048576 count="$xfer" &> /dev/null
63+if [ "$verbose" == "1" ] ; then
64+ echo "Disk read complete!"
65+fi
66 end_load="$(grep "cpu " /proc/stat | tr -s " " | cut -d " " -f 2-)"
67 compute_cpu_load "$start_load" "$end_load"
68 echo "Detected disk read CPU load is $cpu_load"

Subscribers

People subscribed via source and target branches