labunix's blog

labunixのラボUnix

debian busterでgnuplotをASCII出力で使ってみる。

■debian busterでgnuplotをASCII出力で使ってみる。

$ lsb_release -d
Description:	Debian GNU/Linux 10 (buster)

 debian busterにsysstatを導入する。
 https://labunix.hateblo.jp/entry/20200721/1595266993

■feedgnuplotを探してインストール。

$ apt-file search bin/gnuplot
gnuplot-nox: /usr/bin/gnuplot-nox         
gnuplot-qt: /usr/bin/gnuplot-qt
gnuplot-x11: /usr/bin/gnuplot-x11

$ apt-cache show gnuplot | ./myscripts/lsec Description-en:
Description-en: Command-line driven interactive plotting program.
 Gnuplot is a portable command-line driven interactive data and function
 plotting utility that supports lots of output formats, including drivers
 for many printers, (La)TeX, (x)fig, Postscript, and so on. The X11-output
 is packaged in gnuplot-x11.
 .
 Data files and self-defined functions can be manipulated by the internal
 C-like language. Can perform smoothing, spline-fitting, or nonlinear fits,
 and can work with complex numbers.
 .
 This metapackage is to install a full-featured gnuplot (-qt, -x11 or -nox).

$ apt-cache search ^gnuplot
gnuplot-data - コマンドライン駆動の対話的な作図プログラム (データファイル)
gnuplot-doc - コマンドライン駆動の対話的作図プログラム - ドキュメンテーションパッケージ
gnuplot - Command-line driven interactive plotting program.
gnuplot-nox - Command-line driven interactive plotting program. No-X package
gnuplot-qt - Command-line driven interactive plotting program. QT-package
gnuplot-x11 - Command-line driven interactive plotting program. X-package
elpa-gnuplot-mode - Gnuplot mode for Emacs
gnuplot-mode - Transition Package, gnuplot-mode to elpa-gnuplot-mode
libpdl-graphics-gnuplot-perl - gnuplot-based plotting backend for PDL
python-gnuplotlib - Gnuplot-based plotter for numpy
python3-gnuplotlib - Gnuplot-based plotter for numpy

$ sudo apt-get install -y gnuplot gnuplot-doc

$ dpkg -L gnuplot-doc | awk '/pdf/{print "cp "$1" ."}'
cp /usr/share/doc/gnuplot/gnuplot.pdf .
cp /usr/share/doc/gnuplot/tutorial.pdf .

$ dpkg -L gnuplot-doc | awk '/pdf/{print "cp "$1" ."}' | sh

■1日前のデータを元にグラフを描いてみる。
 ネットワークは100超えるので一旦スルー。
 というかほとんど定形なのでスクリプトにした方が良い。今回はそれもスルー。

$ mytitle="CPU idle";env LANG=C sar -u -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search=idle '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                        (NR>5&&$1 !~ /Average/&& $2 ~ /all/){print $1","$target}' | \
  gnuplot -e '
    set datafile separator ","; 
    set title "'"${mytitle}"'"; 
    set xdata time; 
    set timefmt "%H:%M:%S"; 
    set format x "%H:%M"; 
    set yrange [0:100]; 
    set xrange ["00:00":"23:59"]; 
    set terminal dumb ; 
    plot "'"-"'" u 1:2 w l title ""; 
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle


                                                                               
                                    CPU idle                                   
                                                                               
  100 +--------------------------------------------------------------------+   
      |********************************************************************|   
      |         *  *    *       * * ** **               ** *  ***  ******  |   
      |                          ***   *                   *  * ***      **|   
   80 |-+                          *                                     +-|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 
                                                                               

$ mytitle="CPU 100-(idle)";env LANG=C sar -u -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search=idle '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                        (NR>5&&$1 !~ /Average/&& $2 ~ /all/){print $1","100-$target}' | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle


                                                                               
                                 CPU 100-(idle)                                
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
      |                                                                    |   
      |                                                                    |   
   80 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |-+                          *                                     +-|   
      |                          ***   *                   *  * ***      **|   
      |         *  *    *       * * ** **               ** *  ***  ******  |   
      |********************************************************************|   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 


$ mytitle="memused";env LANG=C sar -r -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search=memused '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                           (NR>5&&$1 !~ /Average/){print $1","$target}' | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset dat; \
  unset mytitleafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle



                                                                               
                                     memused                                   
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
      |                                                                    |   
      |                                                                    |   
   80 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |********************************************************************|   
      |                                                                    |   
      |                                                                    |   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 


$ mytitle="100-(memused)";env LANG=C sar -r -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search=memused '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                           (NR>5&&$1 !~ /Average/){print $1","100-$target}' | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle


                                                                               
                                  100-(memused)                                
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
      |                                                                    |   
      |                                                                    |   
   80 |********************************************************************|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 

$ mytitle="swpused";env LANG=C sar -S -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
  awk -v search="^.swpused" '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                             (NR>5&&$1 !~ /Average/){print $1","$target}' | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;  
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle


                                                                               
                                     swpused                                   
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
      |                                                                    |   
      |                                                                    |   
   80 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 


$ mytitle="tps";env LANG=C sar -b -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search="^tps" '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                           (NR>5&&$1 !~ /Average/){OFS=",";print $1,$target,$(target+1),$(target+2)}'  | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";                                                                                         
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle

                                                                               
                                       tps                                     
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +   * +    +     +     +     +    +     |   
      |                                *                                   |   
      |                                *                   *               |   
   80 |-+                        **    *                   *             +-|   
      |                          **    *                ** *               |   
      |                          **    *                ** *  *            |   
   60 |-+                        **  * *                ** *  * *        +-|   
      |                          **  * *                ** *  * *          |   
      |                         * *  * *                ** *  * *          |   
      |                         * *  * **               ** *  * *          |   
   40 |-+                       * *  * **               ****  * *        +-|   
      |                         * *  * **              * ***  * *          |   
      |                         * * * ***              * *** *** *         |   
   20 |-+                       * * * ***              * *** *** * *     *-|   
      |                         * *** ****             * *** ***  ****** **|   
      |                        *  *** ****             * *** * *   *  * * *|   
      |     +     +    +     + *  *+* ****    +     + ** ** ** *+    +  *  |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 
                                                                               

$ mytitle="rtps";env LANG=C sar -b -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search="^tps" '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                           (NR>5&&$1 !~ /Average/){OFS=",";print $1,$(target+1)}'  | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle

                                                                               
                                      rtps                                     
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +   * +    +     +     +     +    +     |   
      |                                *                                   |   
      |                                *                   *               |   
   80 |-+                        *     *                   *             +-|   
      |                          **    *                ** *               |   
      |                          **    *                ** *  *            |   
   60 |-+                        **  * *                ** *  *          +-|   
      |                          **  * *                ** *  * *          |   
      |                         * *  * *                ** *  * *          |   
      |                         * *  * **               ** *  * *          |   
   40 |-+                       * *  * **               ****  * *        +-|   
      |                         * *  * **              * ***  * *          |   
      |                         * * * ***              * *** ** *          |   
   20 |-+                       * * * ***              * *** *** * *     +-|   
      |                         * * * ****             * *** *** * **      |   
      |                        *  * * ****             * *** ***  ** *** * |   
      |     +     +    +     + *  *+* ****    +     + ** ** ** *+    +  ***|   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00 


$ mytitle="wtps";env LANG=C sar -b -f /var/log/sysstat/sa$(date '+%d' --date "yesterday") | \
    awk -v search="^tps" '(NR==5){for(a=2;a<=NF;a++){if($a ~ search){target=a}}} \
                           (NR>5&&$1 !~ /Average/){OFS=",";print $1,$(target+2)}'  | \
  gnuplot -e '
    set datafile separator ",";
    set title "'"${mytitle}"'";
    set xdata time;
    set timefmt "%H:%M:%S";
    set format x "%H:%M";
    set yrange [0:100];
    set xrange ["00:00":"23:59"];
    set terminal dumb ;
    plot "'"-"'" u 1:2 w l title "";
    unset datafile separator;unset xdata;unset timefmt;unset format x;unset yrange ;unset xrange; unset terminal;unset title'; \
  unset mytitle

                                                                               
                                      wtps                                     
                                                                               
  100 +--------------------------------------------------------------------+   
      |     +     +    +     +     +     +    +     +     +     +    +     |   
      |                                                                    |   
      |                                                                    |   
   80 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   60 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
      |                                                                    |   
   40 |-+                                                                +-|   
      |                                                                    |   
      |                                                                    |   
   20 |-+                                                                +-|   
      |                            *                                       |   
      |                            *                            *        **|   
      |     +     +    +     +    *+*    +    +     +     +   * *********  |   
    0 +--------------------------------------------------------------------+   
    00:00 02:00 04:0006:00 08:00 10:00 12:0014:00 16:00 18:00 20:0022:00 00:00