您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)怎么記錄Linux的系統(tǒng)運行時間的統(tǒng)計信息,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Linux/Unix 系統(tǒng)管理員對服務(wù)器的系統(tǒng)運行時間有一種奇怪的癡迷。這里有一個關(guān)于這個主題的 xkcd 漫畫,一個好的系統(tǒng)管理員是一股不可阻擋的力量,他佇立在你家貓咪博客的服務(wù)器之前,對抗黑暗勢力。
Fig.01: Devotion to Duty https://xkcd.com/705/
我們可以使用 uptime
命令或 w 命令 或 top
命令來判斷 Linux 系統(tǒng)運行了多久。我可以使用 tuptime
工具保留每次重新啟動的運行時間,以獲得系統(tǒng)運行時間的歷史和統(tǒng)計報告。
這就像 uptime
命令一樣,但輸出結(jié)果更令人印象深刻。最近我發(fā)現(xiàn)了另一種稱為 uptimed
的工具,用于記錄關(guān)于機器的系統(tǒng)運行時間和統(tǒng)計信息。讓我們看看如何使用 Linux 操作系統(tǒng)上的 uptimed
和 uprecords
來獲得運行時間的記錄統(tǒng)計信息。
查找系統(tǒng)運行時間非常簡單,只需在基于 Linux 的系統(tǒng)上鍵入以下命令即可:
$ uptime -pup 2 weeks, 4 days, 7 hours, 28 minutes
要保留有關(guān) uptime
的歷史統(tǒng)計信息,請使用 tuptime 或 uptimed
工具。
安裝 uptimed
的最簡單的方式是通過你的軟件包管理器,比如 apt/apt-get/yum 這些你的 Linux 發(fā)行版的朋友。
鍵入以下 apt 命令/apt-get 命令:
$ sudo apt-get install uptimed
示例輸出:
Reading package lists... DoneBuilding dependency tree Reading state information... DoneThe following additional packages will be installed: libuptimed0The following NEW packages will be installed: libuptimed0 uptimed0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.Need to get 40.7 kB of archives.After this operation, 228 kB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://mirrors.linode.com/ubuntu xenial/universe amd64 libuptimed0 amd64 1:0.3.17-4 [9,050 B]Get:2 http://mirrors.linode.com/ubuntu xenial/universe amd64 uptimed amd64 1:0.3.17-4 [31.6 kB]Fetched 40.7 kB in 0s (2,738 kB/s) Preconfiguring packages ...Selecting previously unselected package libuptimed0.(Reading database ... 39163 files and directories currently installed.)Preparing to unpack .../libuptimed0_1%3a0.3.17-4_amd64.deb ...Unpacking libuptimed0 (1:0.3.17-4) ...Selecting previously unselected package uptimed.Preparing to unpack .../uptimed_1%3a0.3.17-4_amd64.deb ...Unpacking uptimed (1:0.3.17-4) ...Processing triggers for systemd (229-4ubuntu21) ...Processing triggers for ureadahead (0.100.0-19) ...Processing triggers for man-db (2.7.5-1) ...Setting up libuptimed0 (1:0.3.17-4) ...Setting up uptimed (1:0.3.17-4) ...Processing triggers for libc-bin (2.23-0ubuntu9) ...Processing triggers for systemd (229-4ubuntu21) ...Processing triggers for ureadahead (0.100.0-19) ...
首先 在 CentOS/RHEL 使用 EPEL 倉庫:
$ sudo yum -y install epel-release
然后,鍵入以下 yum 命令:
$ sudo yum install uptimed
示例輸出:
Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: centos.excellmedia.net * epel: ftp.cuhk.edu.hk * extras: centos.excellmedia.net * updates: centos.excellmedia.netResolving Dependencies--> Running transaction check---> Package uptimed.x86_64 0:0.4.0-6.el7 will be installed--> Finished Dependency Resolution Dependencies Resolved =============================================================================== Package Arch Version Repository Size===============================================================================Installing: uptimed x86_64 0.4.0-6.el7 epel 47 k Transaction Summary===============================================================================Install 1 Package Total download size: 47 kInstalled size: 98 kIs this ok [y/d/N]: yDownloading packages:uptimed-0.4.0-6.el7.x86_64.rpm | 47 kB 00:01 Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : uptimed-0.4.0-6.el7.x86_64 1/1 Verifying : uptimed-0.4.0-6.el7.x86_64 1/1 Installed: uptimed.x86_64 0:0.4.0-6.el7 Complete!
如果你正在使用 Fedora Linux,運行以下 dnf
命令:
$ sudo dnf install uptimed
鍵入以下 pacman
命令:
$ sudo pacman -S uptimed
鍵入以下 emerge
命令:
$ sudo emerge --ask uptimed
使用文本編輯器編輯 /etc/uptimed.conf
文件,例如 vim
命令:
$ sudo vim /etc/uptimed.conf
最少設(shè)置一個 email 地址來發(fā)送記錄。假定有個兼容 sendmail 的 MTA 安裝在 /usr/lib/sendmail
。
EMAIL=vivek@server1.cyberciti.biz
保存并關(guān)閉文件。
使用 systemctl
命令啟動 uptimed
服務(wù):
$ sudo systemctl enable uptimed
$ sudo systemctl start uptimed ## start it ##$ sudo systemctl stop uptimed ## stop it ##$ sudo systemctl restart uptimed ## restart it ##$ sudo systemctl status uptimed ## view status ##
示例輸出:
● uptimed.service - uptime record daemon Loaded: loaded (/lib/systemd/system/uptimed.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-11-09 17:49:14 UTC; 18min ago Main PID: 11137 (uptimed) CGroup: /system.slice/uptimed.service └─11137 /usr/sbin/uptimed -f Nov 09 17:49:14 gfs04 systemd[1]: Started uptime record daemon.
只需鍵入以下命令即可查看 uptimed(8)
程序的統(tǒng)計信息:
$ uprecords
示例輸出:
Fig.02: uprecords in action
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
關(guān)于“怎么記錄Linux的系統(tǒng)運行時間的統(tǒng)計信息”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。