visualize_stats.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. #
  3. # This script polls gnunet-stats repeatedly to create statistics plots.
  4. # Use 'collect' to collect statistics and 'plot' to plot whats been
  5. # collected. All plots will be written to $STATDIR as separate .png files.
  6. #
  7. # WARNING: calling 'collect' will delete all files in $STATDIR.
  8. #
  9. # Requires: gnuplot
  10. #
  11. # Note: gnuplot syntax has changed across versions. This
  12. # script perhaps will not produce color images with older gnuplots.
  13. # The script should work atleast with gnuplot 3.8k patchlevel 1.
  14. #
  15. SLEEP=120
  16. GNUNET=$HOME/
  17. STATDIR=$GNUNET/stats
  18. IMAGEVIEWER='display'
  19. TMP=/tmp/.gnuplot_error
  20. ##########################################################################
  21. mkdir -p $STATDIR
  22. case "$1" in
  23. collect)
  24. rm -f $STATDIR/*
  25. STARTTIME=`date +%s`
  26. IFS=":"
  27. while true; do
  28. NOW=`date +%s`
  29. RELAT=$[$NOW-$STARTTIME]
  30. gnunet-statistics | while read KEY VALUE; do
  31. KEY=`echo $KEY | tr / .`
  32. # Collect stats of previous round
  33. if [ -e "$STATDIR/$KEY.dat" ]; then
  34. PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"`
  35. else
  36. PREV=$VALUE
  37. fi
  38. # Write new stats
  39. echo $RELAT $VALUE >>"$STATDIR/$KEY.dat"
  40. echo $RELAT $PREV $VALUE >>"$STATDIR/$KEY.diff"
  41. done
  42. sleep $SLEEP
  43. done
  44. ;;
  45. plot)
  46. # Plot incremental
  47. ls -1 $STATDIR/*.dat | while read FILENAME; do
  48. BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
  49. echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - incr';plot '$FILENAME' using (\$1/60):(\$2) title '' with lines;" | nice gnuplot 2> $TMP
  50. EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
  51. if test $EC -ge 1
  52. then
  53. rm "$FILENAME.png"
  54. fi
  55. done
  56. # Plot diff
  57. ls -1 $STATDIR/*.diff | while read FILENAME; do
  58. BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
  59. echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - diff';plot '$FILENAME' using (\$1/60):(\$3-\$2) title '' with lines;" | nice gnuplot 2> $TMP
  60. EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
  61. if test $EC -ge 1
  62. then
  63. rm "$FILENAME.png"
  64. fi
  65. done
  66. ;;
  67. view)
  68. $IMAGEVIEWER $STATDIR/*.png
  69. ;;
  70. *)
  71. echo $"Usage: $0 {collect|plot|view}"
  72. exit 1
  73. esac