在Linux中使用Bashtop和Bpytop监视系统资源

时间:2020-03-21 11:46:20  来源:igfitidea点击:

监视工具至关重要,每个系统管理员都知道。
借助资源监视应用程序,我们可以在任务运行时不断观察系统资源的运行状况。
今天,我们将讨论两个系统资源监视器,即Bashtop和Bpytop,以监视Linux和类似Unix的操作系统中的系统资源。
Bashtop和Bpytop资源监视器将向我们显示系统的使用情况以及处理器,内存,磁盘,网络和进程的统计信息。

这个二重监视工具的作者先开发了Bashtop,然后创建了Bashtop的Python端口,并将其命名为Bpytop。
他们没有太大的区别。
这两个实用程序具有相同的目的并具有相同的功能集。
唯一的区别是两者都是用不同的编程语言编写的。
Bashtop用Bash编写,Bpytop用Python编写。
Bashtop和Bpytop支持GNU/Linux,Mac OS和FreeBSD。

开发人员声称Bpytop比Bashtop快,并且Bpytop具有更多功能,建议我们使用Bpytop代替Bashtop。
但是,这是个人选择。
我们可以尝试两者并为我们选择合适的西装。

在Linux上安装Bashtop资源监视器

在Arch Linux上安装bashtop

即使Bashtop是新的,它在很短的时间内就变得非常流行,并成为流行Linux发行版的官方存储库。

在Arch Linux上,Bashtop包含在[Community]存储库中。
要在Arch Linux及其类似Manjaro Linux的变体上安装Bashtop,请运行:

$sudo pacman -S bashtop

它在AUR中也可用,因此我们可以使用任何AUR帮助程序(例如Yay)进行安装。

$yay -S bashtop-git

在Debian上安装bashtop

从Debian 11开始,Bashtop在正式的Debian存储库中可用。
要在Debian上安装Bashtop,请运行:

$sudo apt install bashtop

在Fedora上安装bashtop

$sudo dnf install bashtop

在CentOS 8/RHEL 8上安装bashtop

$sudo dnf config-manager --set-enabled PowerTools
$sudo dnf install epel-release
$sudo dnf install bashtop

在Ubuntu上安装bashtop

自Ubuntu 20.10起,Bashtop在官方Ubuntu存储库中可用。

要在Ubuntu和诸如Linux Mint之类的衍生产品上安装Bashtop,请运行:

$sudo apt install bashtop

从Snap Store安装bashtop

它也可以作为快照应用程序使用:

$sudo snap install bashtop

从PPA安装bashtop

还有一个官方的PPA。
添加Bashtop PPA并通过一步一步运行以下命令将其安装在Ubuntu上:

$sudo add-apt-repository ppa:bashtop-monitor/bashtop
$sudo apt update
$sudo apt install bashtop

从源代码安装Bashtop

我们也可以从源代码安装它。
只要确保我们已经安装了上述依赖项即可。

Git使用以下命令克隆Bashtop存储库:

$git clone https://github.com/aristocratos/bashtop.git

上面的命令将在当前目录中名为“ bashtop”的目录中克隆Bashtop github存储库的内容。
转到克隆的目录:

$cd bashtop

并运行以下命令从源代码安装Bashtop:

$sudo make install

要卸载它,只需从bashtop目录运行以下命令:

$sudo make uninstall

在Linux上安装Bpytop资源监视器

Bpytop是Bashtop的python端口。
作者声称Bpytop比Bashtop快得多并且具有更多功能。

Bpytop可作为快照应用程序使用。
要在支持snap的Linux发行版上安装Bpytop,请运行:

$sudo snap install bpytop

从源代码安装Bpytop

确保系统具有以下依赖性:

  • 具有24位truecolor支持的终端,
  • Python 3(v3.6或者更高版本),
  • psutil模块(v5.7.0或者更高版本)。

安装必备组件后,git使用以下命令克隆Bpytop存储库:

$git clone https://github.com/aristocratos/bpytop.git

上面的命令将在名为“ bpytop”的本地目录中克隆bpytop的内容。
将CD放入其中并按如下所示安装它:

$cd bpytop 
$sudo make install

要卸载Bpytop,只需从bpytop目录运行以下命令:

$sudo make uninstall

在Linux中使用Bashtop和Bpytop监视系统资源

就像我已经说过的那样,Bashtop和Bpytop具有相同的目的,例如:监视系统资源并显示CPU,内存,磁盘,进程和网络等的统计信息。

要开始监视Linux系统资源,请运行Bashtop或者Bpytop,如下所示:

$bashtop

或者,

$bpytop

从上面的输出中可以看到,Bashtop显示以下详细信息:

  • CPU使用率图表,
  • 处理器时钟速度,
  • 总CPU使用率,
  • 每个CPU内核的使用情况,
  • 总内存
  • 使用的内存,
  • 可用内存
  • 高速缓存存储器,
  • 可用的缓存,
  • 交换使用情况(已使用和免费),
  • 当前磁盘的读写速度。

Bashtop/Bpytop的默认刷新率是2500毫秒。
按(+,A,a)键添加100毫秒以更新计时器。
按(-,S,s)键从更新计时器中减去100ms。

选择并查看过程

使用上/下键浏览过程或者使用。
按Pg Up和Pg Down键可在进程列表中跳一页。
按(主页或者结束)键跳到进程列表中的第一页或者最后一页。

进程部分按列显示以下详细信息:

  • 进程ID(PID),
  • 进程名称
  • 争论,
  • 线程,
  • 该过程的所有者,
  • 该进程的内存使用情况详细信息,
  • 进程的CPU使用率。

我们可以使用(左或者右)箭头键在各列之间切换。

进程名称由PID按降序排列。
例如:最大的PID将显示在顶部。
我们可以使用(R,r)键在“流程”部分中反转排序顺序。

要显示所选过程的详细信息,请按ENTER。

要关闭选定的过程详细信息框,请按ENTER键。

筛选程序

要按特定字符串过滤进程,请按(F,f)键并输入字符串名称。
例如,如果我们键入“ ssh”,我们将看到所有以“ ssh”字母开头的进程。

要清除任何输入的过滤器,请按(C,c)键。

终止流程

我们可以通过按(T,t)键使用SIGTERM终止选定的过程。

杀死进程

要使用SIGKILL杀死选定的进程,请按(K,k)键。

这等效于“ kill -9 <pid>”命令。

中断程序

要使用SIGINT中断选定的过程,请按(I,i)键。

显示帮助

我们可以键入F1,H,h键以显示帮助部分。

我们可以通过按Esc,M,m键调出Bashtop/Bpytop主菜单。

退出Bashtop/Bpytop

要退出Bashtop/Bpytop,只需按(Ctrl-C,Q,q)键。

配置Bashtop/Bpytop

Bashtop和Bpytop配置文件分别存储在“ $HOME/.config/bashtop”和“ $HOME/.config/bpytop”文件夹中。

我们可以通过查看文件来查看Bashtop/Bpytop的当前配置选项。

Bashtop配置文件:

$cat ~/.config/bashtop/bashtop.cfg

Bpytop配置文件:

$cat ~/.config/bashtop/bpytop.cfg

输出示例:

#? Config file for bashtop v. 0.9.25
#* Color theme, looks for a .theme file in "$HOME/.config/bashtop/themes" and "$HOME/.config/bashtop/user_themes"
#* Should be prefixed with either "themes/" or "user_themes/" depending on location, "Default" for builtin default theme
color_theme="Default"
#* Update time in milliseconds, increases automatically if set below internal loops processing time, recommended 2000 ms or above for better sample times for graphs
update_ms="2300"
#* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu responsive"
#* "cpu lazy" updates sorting over time, "cpu responsive" updates sorting directly
proc_sorting="pid"
#* Reverse sorting order, "true" or "false"
proc_reversed="false"
#* Show processes as a tree
proc_tree="false"
#* Check cpu temperature, only works if "sensors", "vcgencmd" or "osx-cpu-temp" commands is available
check_temp="false"
#* Draw a clock at top of screen, formatting according to strftime, empty string to disable
draw_clock="%X"
#* Update main ui when menus are showing, set this to false if the menus is flickering too much for comfort
background_update="true"
#* Custom cpu model name, empty string to disable
custom_cpu_name=""
#* Enable error logging to "$HOME/.config/bashtop/error.log", "true" or "false"
error_logging="true"
#* Show color gradient in process list, "true" or "false"
proc_gradient="true"
#* If process cpu usage should be of the core it's running on or usage of the total available cpu power
proc_per_core="false"
#* Optional filter for shown disks, should be names of mountpoints, "root" replaces "/", separate multiple values with space
disks_filter=""
#* Enable check for new version from github.com/aristocratos/bashtop at start
update_check="true"
#* Enable graphs with double the horizontal resolution, increases cpu usage
hires_graphs="false"
#* Enable the use of psutil python3 module for data collection, default on OSX
use_psutil="true"

只需根据自己的喜好更改设置。

或者,我们可以通过按“ m”字母从Bashtop/Bpytop TUI中查看当前选项。