Linux中國

使用 tuptime 工具查看 Linux 伺服器系統的開機時間的歷史和統計

圖01:用於找出伺服器開機時間的多個Linux命令

tuptime 問打個招呼吧

tuptime 命令行工具可以報告基於 Linux 的系統上的下列信息:

  1. 系統啟動次數統計
  2. 註冊首次啟動時間(也就是安裝時間)
  3. 正常關機和意外關機統計
  4. 平均開機時間和故障停機時間
  5. 當前開機時間
  6. 首次啟動以來的開機和故障停機率
  7. 累積系統開機時間、故障停機時間和合計
  8. 報告每次啟動、開機時間、關機和故障停機時間

安裝

輸入下面的命令來克隆 git 倉庫到 Linux 系統中

$ cd /tmp
$ git clone https://github.com/rfrail3/tuptime.git
$ ls
$ cd tuptime
$ ls

樣例輸出:

Fig.02: Cloning a git repo

圖02:克隆git倉庫

確保你安裝了帶有 sys,optparse,os,re,string,sqlite3,datetime,disutils 和 locale 模塊的 Python v2.7。

你可以像下面這樣來安裝:

$ sudo tuptime-install.sh

或者,可以手工安裝(基於 systemd 或非 systemd ):

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

如果系統是systemd的,拷貝服務文件並啟用:

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

如果系統不是systemd的,拷貝初始化文件:

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

運行

只需輸入以下命令:

$ sudo tuptime

樣例輸出:

Fig.03: tuptime in action

圖03: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

via: http://www.cyberciti.biz/hardware/howto-see-historical-statistical-uptime-on-linux-server/

作者:Vivek Gite 譯者:GOLinux 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國