なんちゃってビジュアルリアルタイム監視
単に、gnuplot のグラフをターミナルで動的に閲覧するだけの古いやり方。
- gnuplot
- topless
今回は sar 1で例を書く。
- sar
バックグラウンドジョブ
cron なんかで、数値のログを取るジョブを走らせる。
sar が単純なので。
$ pwd
/PATH/TO/FOO
$ LANG=C sar 1 > sar.txt &
グラフ作成スクリプト
gnuplot でターミナルにグラフ出力する。
$ti とかは、必要あれば正しい日時に2。
tail -200 sar.txt | while read -a ARR ; do
ti="2018-01-01 ${ARR[0]}"
d=$(( $(date +%s -d"$ti" ) - 946652400)) #
echo $d ${ARR[2]}
done > /tmp/tmp.txt
gnuplot <<'EOF'
#!/usr/bin/env gnuplot
set terminal dumb
set title 'CPU'
set xdata time
set timefmt "%s"
set format x "%M:%S"
plot '/tmp/tmp.txt' u ($1):($2) notitle w l
EOF
rm /tmp/tmp.txt
これを実行すれば、
$ bash ./graph.sh
gnuplot> #!/usr/bin/env gnuplot
gnuplot> set terminal dumb
Terminal type set to 'dumb'
Options are 'feed 79 24'
gnuplot> set title 'CPU'
gnuplot> set xdata time
gnuplot> set timefmt "%s"
gnuplot> set format x "%M:%S"
gnuplot> plot 'tmp.txt' u ($1):($2) notitle w l
CPU
2.5 ++-+--+--+-+--+--+--+--+--+-+--+--+--+--+--+-+--+--+--+--+--+-+--+-++
+ + + + + + + * + +
| * |
| * |
2 ++ * * ++
| * * |
| * * |
| * * |
1.5 ++ * * * ++
| * * * * |
| * * * * * |
1 ++ * * ** * ** * * ++
| * * ** * ** * * |
| * * ** * * * ** * * |
| * * ** ** * * * ** * * |
0.5 ++ * * ** ** * ** * ** * * ++
| * * ** ** * ** * ** * * |
| * * ** ** * ** * ** * * |
+ * + + + **+ ** **+**** *+** * * +
0 ++-+-*********************************************************+--+-++
44:30 45:00 45:30 46:00 46:30 47:00 47:30 48:00 48:30
gnuplot>
ビジュアルリアルタイム監視
あとは topless で監視するだけ。
$ topless -s 10 'bash ./graph.sh | grep "^ "'
Author And Source
この問題について(なんちゃってビジュアルリアルタイム監視), 我々は、より多くの情報をここで見つけました https://qiita.com/bunzaemon/items/54656031e1e116d346a5著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .