iT邦幫忙

0

請問 `sar` 命令是否現在不建議使用? 建議使用什麼命令監控系統資源呢?

今天閱讀 鳥哥的 Linux 私房菜 -- 程序與資源管理
image-20200910090822444

發現想按照文中使用 sar 查詢 ubuntu 的系統資源情況,發現以下錯誤

test@test:~$ sar
Cannot open /var/log/sysstat/sa10: No such file or directory
Please check if data collecting is enabled

搜尋 google 找到文章 14.04 - Cannot open /var/log/sysstat/sa20: No such file or directory - Ask Ubuntu

Open /etc/default/sysstat using your favorite file editor and change ENABLED="false" to ENABLED="true"

vi /etc/default/sysstat
----
# Should sadc collect system activity informations? Valid values
# are "true" and "false". Please do not put other values, they
# will be overwritten by debconf!
ENABLED="true"
----

Restart sysstat: sudo service sysstat restart

and now here you are!

叫我去修改 /etc/default/sysstat 文件,將ENABLED改成true

但是我輸入 vi /etc/default/sysstat 去修改時,會跳出以下警告跟阻擋

test$ vi /etc/default/sysstat
W10: Warning: Changing a readonly file 
--我按enter確認

E325: ATTENTION
Found a swap file by the name "/var/tmp/sysstat.swp"
          owned by: test   dated: Wed Sep 09 08:37:26 2020
         file name: /etc/default/sysstat
          modified: YES
         user name: test   host name: test
        process ID: 4681
While opening file "/etc/default/sysstat"
             dated: Wed Sep 09 08:35:41 2020

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/default/sysstat"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/var/tmp/sysstat.swp"
    to avoid this message.

Press ENTER or type command to continue
--我按enter確認
--修改ENABLED改成true
$ :wq!
"/etc/default/sysstat" E212: Can't open file for writing

image-20200910081759397

接著爬文 : [SOLVED] E212 cant open file for writing. I have root access

這篇文章說建議不要修改

Note: Just because you're root, doesn't mean you can do things that can't be done. For instance, if you have a file's permissions set for read only, you can't normally edit it without changing permissions to read/write. Also, lock-files may block access to a service, etc. Think of root as "super-user," with pervasive authority to change things in the system,... not a "God mode," omnipotent and able to change the rules of the system.

請問 sar 命令是否現在不建議使用? 那要使用什麼命令監控系統資源呢? 像是 windows 工作管理員

sam0407 iT邦大師 1 級 ‧ 2020-09-11 10:49:25 檢舉
在ubuntu下系統管理的指令或修改系統檔案時,不是都要在前面多打個sudo?
您試試:
sudo sar
sudo vi /etc/default/sysstat
您好,可以了

$ sudo vi /etc/default/sysstat
ENABLED="true"
$ sudo sar
Cannot open /var/log/sysstat/sa11: No such file or directory
Please check if data collecting is enabled
$ sudo /etc/init.d/sysstat restart
* Starting the system activity data collector sadc [ OK ]
g$ sudo sar
Linux 4.19.104-microsoft-standard (DESKTOP) 09/11/20 _x86_64_ (8 CPU)

11:33:39 LINUX RESTART (8 CPU)
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
一級屠豬士
iT邦大師 1 級 ‧ 2020-09-10 10:28:38
最佳解答

sar 是 sysstat 中的其中一個.sysstat 是成熟穩定的套件.

以往也有人介紹過,例如
https://ithelp.ithome.com.tw/articles/10105353

另外我也有介紹過

https://ithelp.ithome.com.tw/articles/10160219

https://ithelp.ithome.com.tw/articles/10160341

https://ithelp.ithome.com.tw/articles/10160435

https://ithelp.ithome.com.tw/articles/10160624

https://ithelp.ithome.com.tw/articles/10161735

裡面提到的 feedgnuplot, 因為ithelp 後來改版,連結有變化.
所以在這裡

https://ithelp.ithome.com.tw/articles/10161728

感謝 一級屠豬士 大神的回答

我要發表回答

立即登入回答