如何使用 Uptimed 监控 Linux 系统正常运行时间

前段时间,我们讨论了如何 使用 Tuptime 查找 Linux 系统正常运行时间 Linux 上的实用程序。 今天,我们将学习一个类似的实用程序,名为 正常运行. 它是一个命令行实用程序,用于记录和跟踪 Linux 系统的正常运行时间。 使用 Uptimed,我们可以轻松显示历史正常运行时间记录的摘要,例如您的 Linux 系统已启动多长时间、最高正常运行时间是多少、系统何时重新启动等。在这个简短的指南中,让我们看看如何监控使用 Uptimed 实用程序的 Linux 系统正常运行时间。

在 Linux 上安装 Uptimed

Uptimed 在流行的 Linux 操作系统的官方存储库中可用。

安装 Uptimed Arch Linux,只需运行:

$ sudo pacman -S uptimed

Debian, Ubuntu, Linux 薄荷糖

$ sudo apt-get install uptimed

请注意,在 Ubuntu 及其衍生产品上,确保启用 [universe] 存储库。

$ sudo add-apt-repository universe

Fedora

$ sudo dnf install uptimed

CentOS 7

Uptimed 在 CentOS 的默认软件库中不可用。 因此,您需要启用 EPEL 存储库才能安装它。

启用 EPEL 存储库:

$ sudo yum install epel-release

然后使用命令安装 Uptimed:

$ sudo yum install uptimed

在其他 Linux 系统上,从 发布页面 然后手动编译安装。

# wget https://github.com/rpodgorny/uptimed/archive/v0.4.2.zip -O uptimed.zip
# unzip uptimed.zip
# cd uptimed-0.4.2/
# ./configure
# make
# make install

安装 Uptimed 后,启用并启动 uptimed 服务:

# systemctl enable uptimed
# systemctl start uptimed

检查 uptimed 服务的状态:

# systemctl status uptimed
● uptimed.service - Uptime record tracking daemon
   Loaded: loaded (/usr/lib/systemd/system/uptimed.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-02-11 14:21:12 IST; 1s ago
     Docs: man:uptimed(8)
           man:uprecords(1)
 Main PID: 1435 (uptimed)
   Status: "Next milestone (five days) at Sun Feb 16 14:13:59 2020"
   CGroup: /system.slice/uptimed.service
           └─1435 /usr/sbin/uptimed -f

Feb 11 14:21:12 server.ostechnix.local systemd[1]: Starting Uptime record tracking daemon...
Feb 11 14:21:12 server.ostechnix.local systemd[1]: Started Uptime record tracking daemon.

使用 Uptimed 监控 Linux 系统正常运行时间

要在系统重新启动之间监控 Linux 系统的正常运行时间,只需运行:

# uprecords

样本输出:

     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
     1     0 days, 02:35:51 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:22:33 2020
     2     0 days, 00:07:27 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:13:59 2020
->   3     0 days, 00:02:11 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 17:02:29 2020
----------------------------+---------------------------------------------------
1up in     0 days, 00:05:17 | at                        Tue Feb 11 17:09:56 2020
no1 in     0 days, 02:33:41 | at                        Tue Feb 11 19:38:20 2020
    up     0 days, 02:45:29 | since                     Tue Feb 11 14:13:59 2020
  down     0 days, 00:05:12 | since                     Tue Feb 11 14:13:59 2020
   %up               96.953 | since                     Tue Feb 11 14:13:59 2020

此处,第一列中的箭头标记表示最近的正常运行时间。

按启动时间排序结果

要显示按引导时间排序的 Linux 系统正常运行时间,请使用 -b 旗帜:

# uprecords -b
     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
     1     0 days, 00:07:27 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:13:59 2020
     2     0 days, 02:35:51 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:22:33 2020
->   3     0 days, 00:30:14 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 17:02:29 2020

同样,要按启动时间反向排序(即仅显示最近的重新启动),请使用 -B 旗帜:

# uprecords -B
     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
->   1     0 days, 00:14:51 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 17:02:29 2020
     2     0 days, 02:35:51 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:22:33 2020
     3     0 days, 00:07:27 | Linux 3.10.0-1062.1.1.el  Tue Feb 11 14:13:59 2020

显示 X 次正常运行时间

当不带任何选项运行 uprecords 命令时,它将显示 前 10 名历史正常运行时间记录 默认情况下。 但是,您可以使用 -m 旗帜。 为了 example,以下命令将显示前 20 条记录:

# uprecords -m 20

不要截断输出

正如您在上面的输出中注意到的,Linux 内核版本信息在 系统 列已被截断(即 Linux 3.10.0-1062.1.1.el)。 如果您不想截断信息,请使用 -w (宽输出)标志。

# uprecords -w
     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
     1     0 days, 02:35:51 | Linux 3.10.0-1062.1.1.el7.x86_64  Tue Feb 11 14:22:33 2020
->   2     0 days, 00:16:35 | Linux 3.10.0-1062.1.1.el7.x86_64  Tue Feb 11 17:02:29 2020
     3     0 days, 00:07:27 | Linux 3.10.0-1062.1.1.el7.x86_64  Tue Feb 11 14:13:59 2020
----------------------------+---------------------------------------------------
no1 in     0 days, 02:19:17 | at                        Tue Feb 11 19:38:21 2020
    up     0 days, 02:59:53 | since                     Tue Feb 11 14:13:59 2020
  down     0 days, 00:05:12 | since                     Tue Feb 11 14:13:59 2020
   %up               97.190 | since                     Tue Feb 11 14:13:59 2020

显示停机时间

您还可以使用显示重新启动之间的停机时间而不是内核版本 -d 标志如下:

# uprecords -d
     #               Uptime |        Last downtime                       Boot up
----------------------------+---------------------------------------------------
     1     0 days, 02:35:51 |     0 days, 00:01:07      Tue Feb 11 14:22:33 2020
->   2     0 days, 00:13:02 |     0 days, 00:04:05      Tue Feb 11 17:02:29 2020
     3     0 days, 00:07:27 |     0 days, 00:00:00      Tue Feb 11 14:13:59 2020
----------------------------+---------------------------------------------------
no1 in     0 days, 02:22:50 | at                        Tue Feb 11 19:38:21 2020
    up     0 days, 02:56:20 | since                     Tue Feb 11 14:13:59 2020
  down     0 days, 00:05:12 | since                     Tue Feb 11 14:13:59 2020
   %up               97.136 | since                     Tue Feb 11 14:13:59 2020

Uprecords 有更多选择。 要显示带有描述的所有选项,请运行:

# uprecords -?
usage: uprecords [OPTION]...

  -?             this help
  -a             do not print ansi codes
  -b             sort by boottime
  -B             reverse sort by boottime
  -k             sort by sysinfo
  -K             reverse sort by sysinfo
  -d             print downtime seen before every uptimes instead of system
  -c             do not show current entry if not in top entries
  -f             run continously in a loop
  -s             do not print extra statistics
  -w             wide output (more than 80 cols per line)
  -i INTERVAL    use INTERVAL seconds for loop instead of 5, implies -f
  -m COUNT       show a maximum of top COUNT entries instead of 10
  -M             show next milestone
  -v             version information

有关更多详细信息,请参阅手册页。

$ man uprecords

资源:

感谢您的光临!

帮助我们帮助您:

祝你有美好的一天!!