应用tuptime工具查看Linux服务器历史和统计的运行时间
你可以使用以下工具来查看系统已经运行在Linux或类unix系统上多长时间:
uptime:显示服务器已经运行了多久时间。 last:显示reboot(重启)和shutdown(关机)时间 tuptime:反馈系统历史和统计的运行时间,和uptime命令类似,但内容比uptime命令更丰富。
找出系统最后重新启动的时间和日期
在Linux操作系统中,你可以使用下面的命令来得到系统最后重启和关机的日期和时间(在OSX / Unix系统下一样可行):
## Just show system reboot and shutdown date and time ### who -b last reboot last shutdown ## Uptime info ## uptime cat /proc/uptime awk '{ print "up " $1 /60 " minutes"}' /proc/uptime
例子输出:
[root@iZ94aucqfjcZ ~]# tuptime -bash: tuptime: command not found [root@iZ94aucqfjcZ ~]# who -b system boot 2015-12-23 23:02 [root@iZ94aucqfjcZ ~]# last reboot reboot system boot 3.10.93-1.el6.el Wed Dec 23 23:02 - 21:52 (22:49) reboot system boot 3.10.93-1.el6.el Tue Dec 22 20:50 - 23:01 (1+02:11) wtmp begins Wed Sep 17 16:33:23 2014 [root@iZ94aucqfjcZ ~]# last shutdown wtmp begins Wed Sep 17 16:33:23 2014 [root@iZ94aucqfjcZ ~]# uptime 21:53:31 up 22:51, 1 user, load average: 0.02, 0.04, 0.37 [root@iZ94aucqfjcZ ~]# cat /proc/uptime 82300.64 65087.96 [root@iZ94aucqfjcZ ~]# awk '{ print "up " $1 /60 " minutes"}' /proc/uptime up 1371.9 minutes
上面的命令用不同方式告知了系统从上次启动后运行了多长时间。
tuptime介绍
tuptime的命令行工具基于Linux系统,可以报告以下信息:
统计系统启动次数
记住初始安装时间
统计意外关机次数
平均正常运行时间和停机时间
目前的运行时间
自从第一次启动时的正常运行时间和停机率 积累了系统正常运行时间,停机时间还有总和
报告每一启动,正常运行时间和关机时间和停机时间
安装tuptime
$ cd /tmp $ git clone https://github.com/rfrail3/tuptime.git $ ls $ cd tuptime $ ls
部分安装过程:
确保你已经装了Python2.7,而且Python携带安装了sys, optparse, os, re, string, sqlite3, datetime, disutils, and locale这些模块。
你可以用以下命令简便安装:
$ sudo tuptime-install.sh
或者通过手动进行安装(根据是否是systemd进行区别安装)
如果系统中带有systemd,那么复制service文件并使之生效:
$ sudo cp /tmp/tuptime/latest/systemd/tuptime.service /lib/systemd/system/ $ sudo systemctl enable tuptime.service
如果系统中不带systemd,复制init文件:
$ sudo cp /tmp/tuptime/latest/init.d/tuptime.init.d-debian7 /etc/init.d/tuptime $ sudo update-rc.d tuptime defaults
运行tuptime
$ sudo tuptime
效果:
在一次kernel升级之后,我重新启动了系统,然后重新输入tuptime命令:
$ sudo tuptime System startups: 2 since 03:52:16 PM 08/21/2015 System shutdowns: 1 ok - 0 bad Average uptime: 7 days, 16 hours, 48 minutes and 3 seconds Average downtime: 2 hours, 30 minutes and 5 seconds Current uptime: 5 minutes and 28 seconds since 06:23:06 AM 09/06/2015 Uptime rate: 98.66 % Downtime rate: 1.34 % System uptime: 15 days, 9 hours, 36 minutes and 7 seconds System downtime: 5 hours, 0 minutes and 11 seconds System life: 15 days, 14 hours, 36 minutes and 18 seconds
你可以改变时间和日期的格式:
$ sudo tuptime -d '%H:%M:%S %m-%d-%Y'
效果:
System startups: 1 since 15:52:16 08-21-2015 System shutdowns: 0 ok - 0 bad Average uptime: 15 days, 9 hours, 21 minutes and 19 seconds Average downtime: 0 seconds Current uptime: 15 days, 9 hours, 21 minutes and 19 seconds since 15:52:16 08-21-2015 Uptime rate: 100.0 % Downtime rate: 0.0 % System uptime: 15 days, 9 hours, 21 minutes and 19 seconds System downtime: 0 seconds System life: 15 days, 9 hours, 21 minutes and 19 seconds
列举每次开机时间,正常运行时间,关机时间和停机时间:
$ sudo tuptime -e
效果:
Startup: 1 at 03:52:16 PM 08/21/2015 Uptime: 15 days, 9 hours, 22 minutes and 33 seconds System startups: 1 since 03:52:16 PM 08/21/2015 System shutdowns: 0 ok - 0 bad Average uptime: 15 days, 9 hours, 22 minutes and 33 seconds Average downtime: 0 seconds Current uptime: 15 days, 9 hours, 22 minutes and 33 seconds since 03:52:16 PM 08/21/2015 Uptime rate: 100.0 % Downtime rate: 0.0 % System uptime: 15 days, 9 hours, 22 minutes and 33 seconds System downtime: 0 seconds System life: 15 days, 9 hours, 22 minutes and 33 seconds
英文原文:http://www.cyberciti.biz/hardware/howto-see-historical-statistical-uptime-on-linux-server/
译文地址:http://coderschool.cn/1384.html
转载请注明英文原文和译文地址