From: Richard W.M. Jones Date: Sun, 4 Nov 2018 17:37:00 +0000 (+0000) Subject: Add RAID viewer. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=c8eecc14765a5457f775b7575cf16d088d90b67e;p=libguestfs-talks.git Add RAID viewer. --- diff --git a/2019-fosdem/nbdview/README b/2019-fosdem/nbdview/README index ad14699..ed6bc8e 100644 --- a/2019-fosdem/nbdview/README +++ b/2019-fosdem/nbdview/README @@ -1,3 +1,6 @@ +nbdview +------- + nbdview is a small Tcl/Tk program that lets you visualize reads and writes happening to an nbdkit server in real time. @@ -6,7 +9,7 @@ filter. For example, using the memory plugin (but any plugin may be used): size=$((64 * 1024 * 1024)) - delay=20ms + delay=40ms nbdkit --filter=log --filter=delay \ memory \ size=$size \ @@ -29,3 +32,27 @@ most 64MB. Then you can write to the NBD server using ordinary tools such as qemu, qemu-io, guestfish, etc. and observe the reads and writes to the disk. + +nbdraid +------- + +As above but allowing you to display operations to multiple (RAID) +devices. + +Start N copies of nbdkit like this: + + size=$((64 * 1024 * 1024)) + delay=40ms + rm /tmp/error$i + rm /tmp/sock$i + nbdkit -U /tmp/sock$i \ + --filter=error --filter=log --filter=delay \ + memory \ + size=$size \ + logfile=/tmp/log$i \ + rdelay=$delay wdelay=$delay \ + error-rate=1 error-file=/tmp/error$i & + +Then start nbdraid.tcl: + + ./nbdraid $N $size /tmp/log%d /tmp/error%d diff --git a/2019-fosdem/nbdview/nbdraid.tcl b/2019-fosdem/nbdview/nbdraid.tcl new file mode 100755 index 0000000..a6dada1 --- /dev/null +++ b/2019-fosdem/nbdview/nbdraid.tcl @@ -0,0 +1,118 @@ +#!/usr/bin/env wish +# Visualize RAID activity - read the README file first! +# Copyright (C) 2018 Red Hat Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Red Hat nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +package require Tk + +source "nbdcanvas.tcl" + +set blocksize 4096 +set width 128 +set scale 2 + +# This list is used to store all the RAID handles. +set handles {} + +# This function polls the log file of each handle (every 100 ms). +proc poll {} { + global handles + + foreach h $handles { + nbdpoll $h + } + after 100 poll +} + +# Parse command line. +if { $argc != 4 } { + puts "usage: nbdview N size logfile-pattern errorfile-pattern" + exit 1 +} +set N [lindex $argv 0] +set size [lindex $argv 1] +set logpattern [lindex $argv 2] +set errorpattern [lindex $argv 3] + +# Menubar. +option add *tearOff 0 +menu .menubar +. configure -menu .menubar +menu .menubar.file +.menubar add cascade -menu .menubar.file -label File +.menubar.file add command -label "Quit" -command { exit } + +# Frame. +frame .f +pack .f -anchor center -expand 1 -fill both -ipadx 10 -ipady 10 + +# Canvases. +for { set i 1 } { $i <= $N } { incr i } { + set logfile($i) [format $logpattern $i] + set errorfile($i) [format $errorpattern $i] + + # VBox to store the canvas and controls. + set box ".f.h$i" + frame $box + pack $box -side left -expand 1 -fill both + + # Create the error checkbox. + set errorbutton "$box.e" + set errorvar($i) off + checkbutton $errorbutton -text "Error" -variable errorvar($i) \ + -command "set_errorfile $i" + proc set_errorfile { i } { + global errorvar errorfile + if { $errorvar($i) } { + # Touch the error inject file. + close [open $errorfile($i) "w"] + } else { + # Delete it. + file delete $errorfile($i) + } + } + pack $errorbutton -side top -anchor nw -expand 0 -fill none + + # Create the i'th canvas. + set canvas "$box.c" + set h [nbdcanvas $canvas $logfile($i) $size $blocksize $width $scale] + $canvas configure -borderwidth 4 -relief groove + pack $canvas -side top -expand 0 -fill none + + lappend handles $h +} + +# Set up the window. +wm title . "nbdraid" +wm resizable . false false + +# Start polling the log file. +after 100 poll