Linux command pipeline buffer
This is a problem of Wang Gong.
MySQL monitoring indicators. Use mysqladmin to get the information every second, format the information and output the file.
Commands for getting information and formatting
Mysqladmin-uroot-proot-S mysql.sock ext-i1 | awk'/ Queries/ {QPX QPP 4} / Threads_connected/ {tc=$4} / Threads_running/ {printf "% 5d% 5d% 5d\ n", Q, tc, $4}'
This command can be carried out alone.
But if you want to redirect to a file, this information is not real-time. It takes more than ten seconds to write to the file.
Mysqladmin-uroot-proot-S mysql.sock ext-i1 | awk'/ Queries/ {qptince4} / Threads_connected/ {tc=$4} / Threads_running/ {printf "% 5d% 5d% 5d\ n", Q, tc, $4}'> a.log
Why can real-time output be achieved by directly executing the command, but redirection is delayed output?
This problem should also exist in tail-f.
After searching the data, it was found that it was the problem of the buffer zone.
Related links:
Https://aicode.cc/wei-shen-me-ni-de-ming-ling-xing-cheng-xu-mei-you.html
So the rewriting command can realize the requirement of real-time output.
Mysqladmin-uroot-proot-S mysql.sock ext-i1 | stdbuf-oL awk'/ Queries/ {Threads_connected/ tc=$4} / Threads_running/ {printf "% 5d% 5d% 5d\ n", Q, tc, $4}'> / tmp/mysql.log