slitaz-forge rev 367

tank/makegraphs: create boot.html
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 16 09:35:21 2013 +0200 (2013-05-16)
parents e6e4be1b2591
children b19fb9901643
files mirror/info/bin/makegraphs tank/web/lib/makegraphs
line diff
     1.1 --- a/mirror/info/bin/makegraphs	Thu May 09 18:16:08 2013 +0200
     1.2 +++ b/mirror/info/bin/makegraphs	Thu May 16 09:35:21 2013 +0200
     1.3 @@ -15,6 +15,8 @@
     1.4  [ -d $rrdlog ] || mkdir -p $rrdlog
     1.5  [ -d $rrdgraph ] || mkdir -p $rrdgraph
     1.6  
     1.7 +RRDTOOLYEAR=$(rrdtool --help | sed '/Copyright/!d;s/.*-\([0-9]*\) .*/\1/')
     1.8 +
     1.9  updatecpudata() {
    1.10  	[ -e "$rrdlog/cpu.rrd" ] || rrdtool create $rrdlog/cpu.rrd --step=300 \
    1.11  			DS:user:COUNTER:600:0:500000000 \
    1.12 @@ -148,10 +150,11 @@
    1.13  	period=$1
    1.14  	extra="--logarithmic --lower-limit 1"
    1.15  	[ "$period" == "day" ] && maxdisk="$(getmax disk)" && extra=""
    1.16 -	info=""
    1.17 +	info="$(fdisk -l 2> /dev/null | sed '/dev/!d;s|.*: \(.*\), .*|\1|;q')"
    1.18 +	[ -n "$info" ] && info="[ $info ]"
    1.19  	[ -r $2 ] &&
    1.20  	info="[ $(fdisk -l 2> /dev/null | grep "^Disk $2:" | \
    1.21 -		  sed "s|Disk $2: \(.*\), .*|\1|") ]"
    1.22 +		  sed "s|Disk $2: \(.*\), .*|\1|") ]" ||
    1.23  	if [ -e /sys/block/${2#/dev/}/device/iodone_cnt ]; then
    1.24  #		--right-axis-label "I/O state %"
    1.25  	rrdtool graph "$rrdgraph/disk-$period.png" --start -1$period \
    1.26 @@ -182,8 +185,10 @@
    1.27  		"CDEF:writepct=100,write,$maxdisk,/,*" \
    1.28  		'AREA:readpct#0000FF:sectors written from disk' \
    1.29  		'STACK:writepct#00FF00:sectors read to disk' \
    1.30 -		'LINE1:ino#FF00FF:% inodes used' \
    1.31 -		'LINE1:blk#FF0000:% blocks used\j'
    1.32 +		'LINE1:ino#FF00FF:inodes used' \
    1.33 +		'GPRINT:ino:MAX:%1.0lf%%' \
    1.34 +		'LINE1:blk#FF0000:blocks used' \
    1.35 +		'GPRINT:blk:MAX:%1.0lf%%\j'
    1.36  	fi
    1.37  }
    1.38  
    1.39 @@ -234,10 +239,26 @@
    1.40  		DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE \
    1.41  		DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE \
    1.42  		DEF:tcp=$rrdlog/proto-$interface.rrd:tcp:AVERAGE \
    1.43 +		DEF:rsync=$rrdlog/proto-$interface.rrd:rsync:AVERAGE \
    1.44  		'AREA:incoming#00FF00:incoming traffic' \
    1.45 -		'GPRINT:outgoing:MAX:max output%8.3lf %sBps' \
    1.46 +		'AREA:rsync#FF00FF:updates' \
    1.47  		'LINE1:outgoing#0000FF:outgoing traffic' \
    1.48 -		'LINE1:tcp#000000:connections\j'
    1.49 +		'GPRINT:outgoing:MAX:max %5.3lf %sBps' \
    1.50 +		'LINE1:tcp#000000:connections' \
    1.51 +		'GPRINT:tcp:MAX:max %2.0lf\j'
    1.52 +	rrdtool graph "$rrdgraph/proto-$interface-$period.png" --start -1$period \
    1.53 +		$rrdgraphargs -t "traffic on $interface graph per $period" \
    1.54 +		--logarithmic -A -v "Bytes/second" --units=si \
    1.55 +		DEF:rsync=$rrdlog/proto-$interface.rrd:rsync:AVERAGE \
    1.56 +		DEF:www=$rrdlog/proto-$interface.rrd:www:AVERAGE \
    1.57 +		DEF:ssh=$rrdlog/proto-$interface.rrd:ssh:AVERAGE \
    1.58 +		DEF:tcp=$rrdlog/proto-$interface.rrd:tcp:AVERAGE \
    1.59 +		DEF:udp=$rrdlog/proto-$interface.rrd:udp:AVERAGE \
    1.60 +		'AREA:tcp#00FF00:tcp connections' \
    1.61 +		'AREA:rsync#0000FF:rsync' \
    1.62 +		'LINE1:www#FF0000:www' \
    1.63 +		'LINE1:ssh#FF00FF:ssh' \
    1.64 +		'LINE1:udp#000000:udp connections\j'
    1.65  }
    1.66  
    1.67  netframes() {
    1.68 @@ -357,6 +378,8 @@
    1.69  cat > $rrdgraph/boot.html <<EOT
    1.70  <html>
    1.71  <body>
    1.72 +$(stat -c %y /var/log/dmesg.log | sed 's/\.0*//')
    1.73 +<span style="color: blue"><i>$(cat /proc/cmdline)</i></span>
    1.74  <pre>
    1.75  $(cat /var/log/dmesg.log /var/log/boot.log | \
    1.76  sed	-e 's/</\&lt;/g;s/>/\&gt;/g' -e 's/.*\]R//' -e 's/.*\[?8h//' \
     2.1 --- a/tank/web/lib/makegraphs	Thu May 09 18:16:08 2013 +0200
     2.2 +++ b/tank/web/lib/makegraphs	Thu May 16 09:35:21 2013 +0200
     2.3 @@ -48,17 +48,20 @@
     2.4  		DEF:system=$rrdlog/cpu.rrd:system:AVERAGE \
     2.5  		DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE \
     2.6  		DEF:nice=$rrdlog/cpu.rrd:nice:AVERAGE \
     2.7 +		DEF:iowait=$rrdlog/cpu.rrd:iowait:AVERAGE \
     2.8  		DEF:celsius=$rrdlog/cpu.rrd:celsius:AVERAGE \
     2.9 -		'CDEF:total=user,system,idle,nice,+,+,+' \
    2.10 +		'CDEF:total=user,system,idle,nice,iowait,+,+,+,+' \
    2.11  		'CDEF:userpct=100,user,total,/,*' \
    2.12  		'CDEF:systempct=100,system,total,/,*' \
    2.13  		'CDEF:idlepct=100,idle,total,/,*' \
    2.14  		'CDEF:nicepct=100,nice,total,/,*' \
    2.15 +		'CDEF:iopct=100,iowait,total,/,*' \
    2.16  		'CDEF:temp=celsius,1000,/' \
    2.17 -		'AREA:userpct#0000FF:user cpu usage' \
    2.18 -		'STACK:nicepct#C0C0FF:nice cpu usage' \
    2.19 -		'STACK:systempct#FF0000:system cpu usage' \
    2.20 -		'STACK:idlepct#00FF00:idle cpu usage' \
    2.21 +		'AREA:userpct#0000FF:user cpu' \
    2.22 +		'STACK:nicepct#C0C0FF:nice cpu' \
    2.23 +		'STACK:systempct#FF0000:system cpu' \
    2.24 +		'STACK:iopct#FFFF00:I/O wait' \
    2.25 +		'STACK:idlepct#00FF00:idle cpu' \
    2.26  		'LINE1:temp#000000:temperature\g' \
    2.27  		'GPRINT:temp:MAX:max %2.0lfC\j'
    2.28  }
    2.29 @@ -105,7 +108,8 @@
    2.30  		'STACK:bufferpct#FF00FF:buffered memory' \
    2.31  		'STACK:cachepct#FFFF00:cached memory' \
    2.32  		'STACK:freepct#00FF00:free memory' \
    2.33 -		'LINE2:swusedpct#FF0000:used swap\j'
    2.34 +		'LINE2:swusedpct#FF0000:used swap\g' \
    2.35 +		'GPRINT:swusedpct:MAX:%1.0lf%%\j'
    2.36  }
    2.37  
    2.38  updatememdata () {
    2.39 @@ -164,25 +168,16 @@
    2.40  	rate=$(echo | awk "BEGIN { printf \"%.0e\\n\",$err/$done }")
    2.41  	[ $err -eq 0 ] &&  rate="0"
    2.42  #		--right-axis-label "I/O state %"
    2.43 -	# BUG workaround: swap readsect and writesect :-/
    2.44  	rrdtool graph "$rrdgraph/disk-$period.png" --start -1$period \
    2.45  		$rrdgraphargs -t "disk access per $period $info" \
    2.46  		--logarithmic --lower-limit 1 -v "Sectors/second" --units=si \
    2.47  		DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE \
    2.48  		DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE \
    2.49 -		DEF:req=$rrdlog/iodisk.rrd:req:AVERAGE \
    2.50 -		DEF:done=$rrdlog/iodisk.rrd:done:AVERAGE \
    2.51 -		DEF:err=$rrdlog/iodisk.rrd:err:AVERAGE \
    2.52  		"CDEF:readpct=100,read,$maxdisk,/,*" \
    2.53  		"CDEF:writepct=100,write,$maxdisk,/,*" \
    2.54 -		"CDEF:errpct=100,err,req,/,*" \
    2.55 -		"CDEF:donepct=100,done,req,/,*" \
    2.56 -		"CDEF:errrate=err,done,/" \
    2.57  		'AREA:readpct#0000FF:sectors written from disk' \
    2.58  		"COMMENT:I/O error rate $rate" \
    2.59 -		'STACK:writepct#00FF00:sectors read to disk' \
    2.60 -		'LINE2:donepct#FFFF00:% I/O complete' \
    2.61 -		'LINE2:errpct#FF0000:% I/O error\j'
    2.62 +		'STACK:writepct#00FF00:sectors read to disk\j'
    2.63  	else
    2.64  	rrdtool graph "$rrdgraph/disk-$period.png" --start -1$period \
    2.65  		$rrdgraphargs -t "disk access per $period $info" \
    2.66 @@ -191,8 +186,8 @@
    2.67  		DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE \
    2.68  		"CDEF:readpct=100,read,$maxdisk,/,*" \
    2.69  		"CDEF:writepct=100,write,$maxdisk,/,*" \
    2.70 -		'AREA:readpct#0000FF:sectors written from disk' \
    2.71 -		'STACK:writepct#00FF00:sectors read to disk'
    2.72 +		'AREA:readpct#0000FF:sectors read from disk' \
    2.73 +		'STACK:writepct#00FF00:sectors written to disk'
    2.74  	fi
    2.75  }
    2.76  
    2.77 @@ -327,3 +322,25 @@
    2.78  updateifgraph $iface week
    2.79  updateifgraph $iface month
    2.80  updateifgraph $iface year
    2.81 +
    2.82 +[ ! -s $rrdgraph/boot.html -o /var/log/boot.log -nt $rrdgraph/boot.html ] &&
    2.83 +cat > $rrdgraph/boot.html <<EOT
    2.84 +<html>
    2.85 +<body>
    2.86 +$(stat -c %y /var/log/dmesg.log | sed 's/\.0*//')
    2.87 +<span style="color: blue"><i>$(cat /proc/cmdline)</i></span>
    2.88 +<pre>
    2.89 +$(cat /var/log/dmesg.log /var/log/boot.log | \
    2.90 +sed	-e 's/</\&lt;/g;s/>/\&gt;/g' -e 's/.*\]R//' -e 's/.*\[?8h//' \
    2.91 +	-e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' -e 's|.\[[0-9][0-9Gm;]*||g' \
    2.92 +	-e ':a;s/^\(.\{1,68\}\)\(\[ [A-Za-z]* \]\)/\1 \2/;ta' \
    2.93 +	-e 's#\[ OK \]#[ <span style="color: green">OK</span> ]#' \
    2.94 +	-e 's#\[ Failed \]#[ <span style="color: red">Failed</span> ]#' \
    2.95 +	-e 's|No such .*|<span style="color: red">&</span>|' \
    2.96 +	-e 's|ERROR .*|<span style="color: red">&</span>|' \
    2.97 +	-e 's|command line: \(.*\)|command line: <span style="color: blue">\1</span>|' \
    2.98 +)
    2.99 +</pre>
   2.100 +</body>
   2.101 +</html>
   2.102 +EOT