cheap script to pass data through gnuplot

im putting this script up not because it does something useful, but because i needed somewhere to store it. if it actually helps you then i apologize.

#!/bin/bash
# script for gnuplot to combine multiple pieces of data into on graph
# in png format 

case $1 in
   'load_avg')
                if [ $# -lt 3 ]; then
                        echo "usage: $0 <load_avg|combined_load_ave|idle_context> <PNG OUTPUT FILENAME> <graph_data1 graph_data2 graph_data3...>" 1>&2
         exit 1
      fi

      TMP_FILE="/tmp/graph_script.tmp.$$"
      BASE_NAME="$2"

                while [ ! -z "$3" ]; do
                        PREPEND_NAME="`basename $3 | cut -d_ -f1`"
         FILENAME="${PREPEND_NAME}_$BASE_NAME"

                        echo "#!/usr/bin/gnuplot
set terminal png
set output \"$FILENAME\"
set key top left
set key box
set grid x y
set autoscale y
set xrange [0:24]
set xlabel \"hour of the day\" 2.0,-1.
set ylabel \"one minute average number of processes on the run queue\"
set title \"one minute load average\"
set xtics rotate (\"00:00\" 0, \"1:00\" 1,\"2:00\" 2, \"3:00\" 3, \"4:00\" 4, \"5:00\" 5, \"6:00\" 6, \"7:00\" 7, \"8:00\" 8, \"9:00\" 9, \"10:00\" 10, \"11:00\" 11, \"12:00\" 12, \"13:00\" 13, \"14:00\" 14, \"15:00\" 15, \"16:00\" 16, \"17:00\" 17, \"18:00\" 18, \"19:00\" 19, \"20:00\" 20, \"21:00\" 21, \"22:00\" 22, \"23:00\" 23, \"00:00\" 24)
set mxtics 1
set mytics 2
set ytics 0,.5
plot \"$3\" using 1:2 title \"`basename $3`\" smooth bezier" >$TMP_FILE

                        chmod 755 $TMP_FILE
                        $TMP_FILE
                        rm -f $TMP_FILE

                shift
                done
      ;;

   'combined_load_avg')
                if [ $# -lt 3 ]; then
                        echo "usage: $0 <load_avg|combined_load_ave|idle_context> <PNG OUTPUT FILENAME> <graph_data1 graph_data2 graph_data3...>" 1>&2
         exit 1
      fi

      TMP_FILE="/tmp/graph_script.tmp.$$"
      FILENAME="$2"

      echo "#!/usr/bin/gnuplot
set terminal png
set output \"$FILENAME\"
set key top left
set key box
set grid x y
set autoscale y
set xrange [0:24]
set xlabel \"hour of the day\" 2.0,-1.
set ylabel \"amount of process\"
set title \"process activity\"
set xtics rotate (\"00:00\" 0, \"1:00\" 1,\"2:00\" 2, \"3:00\" 3, \"4:00\" 4, \"5:00\" 5, \"6:00\" 6, \"7:00\" 7, \"8:00\" 8, \"9:00\" 9, \"10:00\" 10, \"11:00\" 11, \"12:00\" 12, \"13:00\" 13, \"14:00\" 14, \"15:00\" 15, \"16:00\" 16, \"17:00\" 17, \"18:00\" 18, \"19:00\" 19, \"20:00\" 20, \"21:00\" 21, \"22:00\" 22, \"23:00\" 23, \"00:00\" 24)
set mxtics 1
set mytics 2
set ytics 0,.5" >> $TMP_FILE

      if [ $# -gt 2 ]; then
         printf "plot \"$3\" using 1:2 title \"`basename $3`\" smooth bezier " >>$TMP_FILE
         shift

         while [ ! -z "$3" ]; do
            printf ", \"$3\" using 1:2 title \"`basename $3`\" smooth bezier " >>$TMP_FILE
            shift
         done
      fi

      chmod 755 $TMP_FILE
      $TMP_FILE
      rm -f $TMP_FILE
      ;;

   'idle_context')
                if [ $# -lt 3 ]; then
                        echo "usage: $0 <load_avg|combined_load_ave|idle_context> <PNG OUTPUT FILENAME> <graph_data1 graph_data2 graph_data3...>" 1>&2
         exit 1
      fi

      TMP_FILE="/tmp/graph_script.tmp.$$"
      BASE_NAME="$2"

                while [ ! -z "$3" ]; do
                        PREPEND_NAME="`basename $3 | cut -d_ -f1`"
                        FILENAME="${PREPEND_NAME}_$BASE_NAME"

                        echo "#!/usr/bin/gnuplot
reset
set terminal png
set output \"$FILENAME\"
set size 1.0,2
set origin 0.0, 0.0
set multiplot
set size 1,1
set origin 0.0,1.0
set grid
unset key
set samples 250
#idle
set title \"Percentage of CPU idle over a 24 hour period\"
set xlabel \"Time / Hours in 24 hr format\" 2.0,-1
set ylabel \"Percent of CPU idle\"
set xtics rotate (\"00:00\" 0, \"1:00\" 1,\"2:00\" 2, \"3:00\" 3, \"4:00\" 4, \"5:00\" 5, \"6:00\" 6, \"7:00\" 7, \"8:00\" 8, \"9:00\" 9, \"10:00\" 10, \"11:00\" 11, \"12:00\" 12, \"13:00\" 13, \"14:00\" 14, \"15:00\" 15, \"16:00\" 16, \"17:00\" 17, \"18:00\" 18, \"19:00\" 19, \"20:00\" 20, \"21:00\" 21, \"22:00\" 22, \"23:00\" 23, \"00:00\" 24)
set mytics 2
set mxtics 2
set xrange [0:24]
set yrange [0:100]
set autoscale y
plot \"$3\" using 2 with lines
#switches
set size 1,1
set origin 0.0,0.0
set title \"Amount of Context Switches over a 24 hour period\"
set ylabel \"Context Switches\"
set xrange [0:24]
set yrange [0:55000]
set autoscale y
plot \"$3\" using 3 with lines
unset multiplot
reset" >$TMP_FILE

              chmod 755 $TMP_FILE
              $TMP_FILE
              rm -f $TMP_FILE

                        shift
      done
      ;;

    *) echo "to use load average display :"
       echo "usage: $0 <load_avg|combined_load_ave|idle_context> <PNG OUTPUT FILENAME> <graph_data1 graph_data2 graph_data3...>"
esac
# EOF
«
»

    Leave a Reply

    Your email address will not be published. Required fields are marked *