Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)






On OSX, to show CPU usage, script is like this.
#!/bin/bash
top -l 1 | head -n 4 | tail -n 1|awk '{printf "%3d%%\n", $3}'


to get Memory Usage, script is like this.
#!/bin/bash
vm_stat | awk 'BEGIN{FS="[:]+"}{if(NR<7&&NR>1)sum+=$2; if(NR==2||NR==4||NR==5)free+=$2} END{printf "%3d%%\n",100*((sum - free)/sum)}'


Name thsese scripts like getCpuUsage.sh/getMemUsage.sh and put them in folder where the $PATH is set. Change their mode to u+x.

To show them on tmux status line, .tmux.conf is like
set -g status-right '#[fg=blue,bold]#H#[default] #[fg=blue,bold][CPU=#(getCpuUsage.sh) MEM=#(getMemUsage.sh)]#[default]'


Comments

Popular posts from this blog

Calling OpenCV functions via Cython from Python 3.X.

Subclassing and Signal connect on a same widget crashes PySide application on exit.