使用 tuptime 工具查看 Linux 服务器系统的开机时间的历史和统计

简介:

你可以使用下面的工具来查看 Linux 或类 Unix 系统运行了多长时间:

  • uptime : 告诉你服务器运行了多长的时间。
  • lastt : 显示重启和关机时间。
  • tuptime : 报告系统的运行时间历史和运行时间统计,这是指重启之间的运行时间。和 uptime 命令类似,不过输出结果更有意思。

找出系统上次重启时间和日期

可以使用下面的命令来获取Linux操作系统的上次重启和关机时间及日期(在OSX/类Unix系统上也可以用):

 
  1. ### 显示系统重启和关机时间
  2. who -b
  3. last reboot
  4. last shutdown
  5. ### 开机信息
  6. uptime
  7. cat /proc/uptime
  8. awk '{ print "up " $1 /60 " minutes"}' /proc/uptime
  9. w

样例输出:

图01:用于找出服务器开机时间的多个Linux命令

图01:用于找出服务器开机时间的多个Linux命令

跟 tuptime 问打个招呼吧

tuptime 命令行工具可以报告基于 Linux 的系统上的下列信息:

  1. 系统启动次数统计
  2. 注册首次启动时间(也就是安装时间)
  3. 正常关机和意外关机统计
  4. 平均开机时间和故障停机时间
  5. 当前开机时间
  6. 首次启动以来的开机和故障停机率
  7. 累积系统开机时间、故障停机时间和合计
  8. 报告每次启动、开机时间、关机和故障停机时间

安装

输入下面的命令来克隆 git 仓库到 Linux 系统中

 
  1. $ cd /tmp
  2. $ git clone https://github.com/rfrail3/tuptime.git
  3. $ ls
  4. $ cd tuptime
  5. $ ls

样例输出:

图02:克隆git仓库

图02:克隆git仓库

确保你安装了带有 sys,optparse,os,re,string,sqlite3,datetime,disutils 和 locale 模块的 Python v2.7。

你可以像下面这样来安装:

 
  1. $ sudo tuptime-install.sh

或者,可以手工安装(基于 systemd 或非 systemd ):

 
  1. $ sudo cp /tmp/tuptime/latest/cron.d/tuptime /etc/cron.d/tuptime

如果系统是systemd的,拷贝服务文件并启用:

 
  1. $ sudo cp /tmp/tuptime/latest/systemd/tuptime.service /lib/systemd/system/
  2. $ sudo systemctl enable tuptime.service

如果系统不是systemd的,拷贝初始化文件:

 
  1. $ sudo cp /tmp/tuptime/latest/init.d/tuptime.init.d-debian7 /etc/init.d/tuptime
  2. $ sudo update-rc.d tuptime defaults

运行

只需输入以下命令:

 
  1. $ sudo tuptime

样例输出:

图03:tuptime工作中

图03:tuptime工作中

在一次更新内核后,我重启了系统,然后再次输入了同样的命令:

 
  1. $ sudo tuptime
  2. System startups: 2 since 03:52:16 PM 08/21/2015
  3. System shutdowns: 1 ok - 0 bad
  4. Average uptime: 7 days, 16 hours, 48 minutes and 3 seconds
  5. Average downtime: 2 hours, 30 minutes and 5 seconds
  6. Current uptime: 5 minutes and 28 seconds since 06:23:06 AM 09/06/2015
  7. Uptime rate: 98.66 %
  8. Downtime rate: 1.34 %
  9. System uptime: 15 days, 9 hours, 36 minutes and 7 seconds
  10. System downtime: 5 hours, 0 minutes and 11 seconds
  11. System life: 15 days, 14 hours, 36 minutes and 18 seconds

你可以像下面这样修改日期和时间格式:

 
  1. $ sudo tuptime -d '%H:%M:%S %m-%d-%Y'

样例输出:

 
  1. System startups: 1 since 15:52:16 08-21-2015
  2. System shutdowns: 0 ok - 0 bad
  3. Average uptime: 15 days, 9 hours, 21 minutes and 19 seconds
  4. Average downtime: 0 seconds
  5. Current uptime: 15 days, 9 hours, 21 minutes and 19 seconds since 15:52:16 08-21-2015
  6. Uptime rate: 100.0 %
  7. Downtime rate: 0.0 %
  8. System uptime: 15 days, 9 hours, 21 minutes and 19 seconds
  9. System downtime: 0 seconds
  10. System life: 15 days, 9 hours, 21 minutes and 19 seconds

计算每次启动、开机时间、关机和故障停机时间:

 
  1. $ sudo tuptime -e

样例输出:

 
  1. Startup: 1 at 03:52:16 PM 08/21/2015
  2. Uptime: 15 days, 9 hours, 22 minutes and 33 seconds
  3. System startups: 1 since 03:52:16 PM 08/21/2015
  4. System shutdowns: 0 ok - 0 bad
  5. Average uptime: 15 days, 9 hours, 22 minutes and 33 seconds
  6. Average downtime: 0 seconds
  7. Current uptime: 15 days, 9 hours, 22 minutes and 33 seconds since 03:52:16 PM 08/21/2015
  8. Uptime rate: 100.0 %
  9. Downtime rate: 0.0 %
  10. System uptime: 15 days, 9 hours, 22 minutes and 33 seconds
  11. System downtime: 0 seconds
  12. System life: 15 days, 9 hours, 22 minutes and 33 seconds
  13. 本文来自云栖社区合作伙伴“Linux中国”,原文发布日期:2015-09-28
目录
相关文章
|
9天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
26 0
|
9天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
15 0
|
9天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
12天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 <<EOF binary put file.txt quit EOF ```
27 4
|
16天前
|
存储 前端开发 Linux
Linux系统之部署ToDoList任务管理工具
【4月更文挑战第1天】Linux系统之部署ToDoList任务管理工具
61 1
|
18天前
|
存储 传感器 运维
linux系统资源统计工具
【4月更文挑战第1天】Linux系统监控工具如dstat、htop、glances、vmstat、top、iostat、mpstat、sar和atop,用于跟踪CPU、内存、磁盘I/O、网络和进程性能。这些工具提供实时、交互式和历史数据分析,助力管理员优化系统性能和故障排查。例如,dstat是vmstat等工具的增强版,htop提供彩色界面的进程管理,而atop则结合了多种功能并记录历史数据。
27 5
linux系统资源统计工具
|
9天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
19 0
|
5天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1053 6
|
11天前
|
监控 Linux
|
14天前
|
资源调度 JavaScript 安全
Linux系统之部署web-check网站分析工具
【4月更文挑战第3天】Linux系统之部署web-check网站分析工具
61 9