如何使用uptimed来监视Linux系统

大家好,我是良许。
作为一名合格的 linux 运维人员,监视系统的正常运行时间可以说是一门基本功了。今天这篇文章就为大家分享一个用于记录和跟踪系统的运行时间的实用命令行工具,它的名字叫做 uptimed。
之所以推荐 uptimed,主要是因为它能在记录和跟踪系统的运行时间之余,还能将这些历史记录以摘要的形式直截了当地展示给用户,比如你的系统已经运行多长时间了?最长的运行时间记录是多少?系统又是何时重启的?等等,而且它也比较容易上手。下面就简单来了解一下 uptimed 的安装和使用吧。
安装uptimed工具
目前主流的 linux 发行版的官方存软件库中已经提供了 uptimed 。
在 arch linux 上安装:
$ sudo pacman -s uptimed
在 debian,ubuntu,linux mint 上安装:
$ sudo apt-get install uptimed
在 ubuntu 及其衍生版本上安装前请确保添加了 universe 存储库,没有的话请运行以下命令添加:
$ sudo add-apt-repository universe
在 fedora 上安装:
$ sudo dnf install uptimed
在 centos 7 上安装:
因为 centos 7 的默认存储库中没有 uptimed,所以要先添加 epel 存储库:
$ sudo yum install epel-release
然后运行以下命令安装:
$ 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
安装完成后,启用并启动服务:
# systemctl enable uptimed
# systemctl start 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 1412 ist; 1s ago
docs: man:uptimed(8)
man:uprecords(1)
main pid: 1435 (uptimed)
status: “next milestone (five days) at sun feb 16 1459 2020”
cgroup: /system.slice/uptimed.service
└─1435 /usr/sbin/uptimed -f
feb 11 1412 server.ostechnix.local systemd[1]: starting uptime record tracking daemon.。.
feb 11 1412 server.ostechnix.local systemd[1]: started uptime record tracking daemon.
这样,前期的安装工作就算完成了。
使用uptimed工具
安装完成 uptimed 工具之后,运行 uprecords 命令就能显示系统运行时间的历史摘要了:
# uprecords
输出的摘要结果:
# uptime | system boot up
----------------------------+---------------------------------------------------
1 0 days, 0251 | linux 3.10.0-1062.1.1.el tue feb 11 1433 2020
2 0 days, 0027 | linux 3.10.0-1062.1.1.el tue feb 11 1459 2020
-》 3 0 days, 0011 | linux 3.10.0-1062.1.1.el tue feb 11 1729 2020
----------------------------+---------------------------------------------------
1up in 0 days, 0017 | at tue feb 11 1756 2020
no1 in 0 days, 0241 | at tue feb 11 1920 2020
up 0 days, 0229 | since tue feb 11 1459 2020
down 0 days, 0012 | since tue feb 11 1459 2020
%up 96.953 | since tue feb 11 1459 2020
这里的 -》 符号表示定位到了系统最近的一次启动时间。
使用 -b 按启动时间正序输出:
# uprecords -b
# uptime | system boot up
----------------------------+---------------------------------------------------
1 0 days, 0027 | linux 3.10.0-1062.1.1.el tue feb 11 1459 2020
2 0 days, 0251 | linux 3.10.0-1062.1.1.el tue feb 11 1433 2020
-》 3 0 days, 0014 | linux 3.10.0-1062.1.1.el tue feb 11 1729 2020
使用 -b 按启动时间倒序输出:
# uprecords -b
# uptime | system boot up
----------------------------+---------------------------------------------------
-》 1 0 days, 0051 | linux 3.10.0-1062.1.1.el tue feb 11 1729 2020
2 0 days, 0251 | linux 3.10.0-1062.1.1.el tue feb 11 1433 2020
3 0 days, 0027 | linux 3.10.0-1062.1.1.el tue feb 11 1459 2020
使用 -m 自定义输出记录数:
不加参数的话结果默认输出前 10 条记录,想要输出前 20 条记录,请运行:
# uprecords -m 20
使用 -w 输出完整信息:
上面的结果中关于 linux 的内核信息是被省略了部分内容的,想要输出完整的内核信息请用 -w 进行宽输出:
# uprecords -w
# uptime | system boot up
----------------------------+---------------------------------------------------
1 0 days, 0251 | linux 3.10.0-1062.1.1.el7.x86_64 tue feb 11 1433 2020
-》 2 0 days, 0035 | linux 3.10.0-1062.1.1.el7.x86_64 tue feb 11 1729 2020
3 0 days, 0027 | linux 3.10.0-1062.1.1.el7.x86_64 tue feb 11 1459 2020
----------------------------+---------------------------------------------------
no1 in 0 days, 0217 | at tue feb 11 1921 2020
up 0 days, 0253 | since tue feb 11 1459 2020
down 0 days, 0012 | since tue feb 11 1459 2020
%up 97.190 | since tue feb 11 1459 2020
使用 -d 显示关机时间:
-d 可以将上面的内核信息替换为关机时间信息:
# uprecords -d
# uptime | last downtime boot up
----------------------------+---------------------------------------------------
1 0 days, 0251 | 0 days, 0007 tue feb 11 1433 2020
-》 2 0 days, 0002 | 0 days, 0005 tue feb 11 1729 2020
3 0 days, 0027 | 0 days, 0000 tue feb 11 1459 2020
----------------------------+---------------------------------------------------
no1 in 0 days, 0250 | at tue feb 11 1921 2020
up 0 days, 0220 | since tue feb 11 1459 2020
down 0 days, 0012 | since tue feb 11 1459 2020
%up 97.136 | since tue feb 11 1459 2020
查看更多的命令选项:
# 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
好了,这次的分享就到这里了,上面所举的例子都是日常使用中十分常见的,如果你想要了解更多关于 uptimed 的用法,可以参考它的帮助手册。
$ man uprecords
希望本文对你有所帮助!


谷歌发布又一AI大模型黑科技丨小美AI城APP带你开启AI新时代
LNK403-409EG设计的带TRIAC调光LED驱动技术
DS2408 8通道、可编程I/O 1-Wire IC
联发科HelioP60的12nm工艺制程对标高通骁龙660
【回顾往年CES】中国手机品牌——奇酷亮相展会,吸引各界目光
如何使用uptimed来监视Linux系统
谷歌宣布Expeditions AR全部向用户开放,以及它的应用的更新
esmini仿真器实现对驾驶中或测试中车辆的后处理和可视化呈现
数字隔离器的市场应用
科创板方邦股份董事、董事长、总经理苏陟介绍、履历信息
什么是信号完整性?为什么我平时的工作没有接触到信号完整性?
窄边框,全金属 3000元能买到的高颜值手机,vivo X9Plus第一你有意见?
联发科天玑游戏引擎打造游戏体验标杆,质疑性能的可以闭嘴了
小米MAX2什么时候上市?小米MAX2最新消息:6.4寸巨屏,5000毫安大电池!
屏下摄像头下半年很难大规模量产 真全面屏未能实现
升压IC之SX1308的SX1308应用电路图与SX1308升压电路图
如何使用现代技术录制录音带
用于无线鼠标的低功率光学传感器ADNS-2080和ADNS-
直流稳压电源维修和使用方法
eFuse应对云应用过流保护的挑战