How to Monitor Remote Linux Systems at a Glance

Make a fortune with your little hand, give it a thumbs up!

Glances is a free open source, modern, cross-platform, real-time top and htop-like system monitoring tool that offers advanced features compared to similar tools and can run in different modes: as a standalone mode, as a client client/server mode, and in Web server mode.

Considering the web server mode, you don’t necessarily need to log in to the remote server via SSH to run glances, you can run it in web server mode and access it via web browser to remotely monitor your Linux server as described below.

To run Glance in web server mode, you need to install it with the Python Bottle module, a fast, simple, and lightweight WSGI micro-web framework, using the appropriate command for your Linux distribution.

$ sudo apt install glances python-bottle         [On Debian, Ubuntu and Mint]
$ sudo yum install glances python-bottle         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$ sudo emerge -a sys-apps/glances python-bottle  [On Gentoo Linux]
$ sudo apk add glances python-bottle             [On Alpine Linux]
$ sudo pacman -S glances python-bottle           [On Arch Linux]
$ sudo zypper install glances python-bottle      [On OpenSUSE]    

Alternatively, install it using the PIP command shown.

$ sudo pip install bottle

After installing the above packages, start Glaces with the -w flag to run it in web server mode. By default it will listen on port 61208.

$ glances -w 
OR
$ glances -w &

If you are running firewalld service then you should open port 61208 to allow inbound traffic to that port.

$ sudo firewall-cmd --permanent --add-port=61208/tcp
$ sudo firewall-cmd --reload

For UFW firewall, run the following command.

$ sudo ufw allow 61208/tcp
$ sudo ufw reload

Afterwards, access the Glances UI from a web browser using the URL http://SERVER_IP:61208/.

If you use the systemd system and service manager, you can run Glas as a service in web server mode for efficient management, as described in the next section. I actually prefer this approach to run as a background process.

Running Glance as a service in web server mode

First create the service unit file under /usr/lib/systemd/system/glancesweb.service.

$ sudo vim /usr/lib/systemd/system/glancesweb.service

Then copy and paste the unit file configuration below into it.

[Unit]
Description = Glances in Web Server Mode
After = network.target

[Service]
ExecStart = /usr/bin/glances  -w  -t  5

[Install]
WantedBy = multi-user.target

The configuration above tells systemd that this is a unit-of-type service and that it should be loaded after network.target.

一旦系统位于网络目标中,systemd 将调用命令“/usr/bin/glances -w -t 5”作为服务。 -t 指定实时更新的时间间隔(以秒为单位)。

[install] 部分通知 systemd “multi-user.target” 需要此服务。因此,当您启用它时,会创建一个从

/etc/systemd/system/multi-user.target.wants/glancesweb.service 到

/usr/lib/systemd/system/glancesweb.service 的符号链接。禁用它将删除该符号链接。

接下来,启用新的 systemd 服务,启动并查看其状态,如下所示。

$ sudo systemctl enable glancesweb.service
$ sudo systemctl start glancesweb.service
$ sudo systemctl status glancesweb.service

最后,在您的 Web 浏览器中,使用 URL http://SERVER_IP:61208/ 在任何设备(智能手机、平板电脑或计算机)上通过 Glances UI 远程监控您的 Linux 服务器。

alt
alt

您可以更改页面的刷新率,只需在 URL 末尾添加以秒为单位的句点,这会将刷新率设置为 8 秒。

http://SERVERI_P:61208/8 

在 Web 服务器模式下运行 Glance 的一个缺点是,如果 Internet 连接较差,客户端很容易与服务器断开连接。

您可以从本指南[1]中了解如何创建新的 systemd 服务:如何在 Linux 中创建 Systemd 单元文件

Reference

[1]

Source: https://www.tecmint.com/glances-monitor-remote-linux-systems/

本文由 mdnice 多平台发布

Guess you like

Origin blog.csdn.net/swindler_ice/article/details/132072977