當前位置: 首頁>>技術問答>>正文


Ubuntu係統監控工具

, , , ,

問題描述

我正在尋找係統監視工具,它們是GUI和Cli或基於Web的工具,其中包括基本功能,例如

  • CPU使用率

  • 公羊使用

  • 交換使用

  • 磁盤使用情況(空間/I /O)

  • 熱監測

我知道有很多工具可以使用,但我正在尋找一種具有這些基本功能的工具。

最佳解決方案

瀏覽 – 關注你的係統

Glances是一款免費軟件(根據LGPL授權),可通過文本界麵監控您的GNU /Linux或BSD操作係統。 Glances使用庫libstatgrab從您的係統中檢索信息,並使用Python開發。

Installation

打開終端(Ctrl + Alt + T)並運行以下命令:

從Ubuntu 16.04及以上版本,您隻需鍵入sudo apt install glances,但版本2.3 have this bug。其他:

輕鬆安裝腳本Glances

curl -L https://raw.githubusercontent.com/nicolargo/glancesautoinstall/master/install.sh | sudo /bin/bash

要麽

wget -O- https://raw.githubusercontent.com/nicolargo/glancesautoinstall/master/install.sh | sudo /bin/bash

手動安裝

sudo apt-get install python-pip build-essential python-dev lm-sensors
sudo pip install psutil logutils bottle batinfo https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard
sudo pip install glances

基本用法

要啟動glances,隻需在終端中鍵入glances

command-line,gui,system,monitoring,ubuntu

通過瀏覽,您可以看到關於係統資源的大量信息:默認情況下,CPU,負載,內存,交換網絡,磁盤I /O和進程全部在一個頁麵中,顏色代碼表示:

GREEN : the statistic is “OK”
BLUE : the statistic is “CAREFUL” (to watch)
VIOLET : the statistic is “WARNING” (alert)
RED : the statistic is “CRITICAL” (critical)

當Glances正在運行時,您可以按下一些特殊的鍵給它發送命令:

c: Sort processes by CPU%  
m: Sort processes by MEM%  
p: Sort processes by name  
i: Sort processes by IO Rate  
d: Show/hide disk I/O stats  
f: Show/hide file system stats  
n: Show/hide network stats  
s: Show/hide sensors stats  
b: Bit/s or Byte/s for network IO  
w: Delete warning logs  
x: Delete warning and critical logs  
1: Global CPU or Per Core stats  
h: Show/hide this help message  
q: Quit (Esc and Ctrl-C also work)  
l: Show/hide log messages

Cpu,Ram,交換監控

command-line,gui,system,monitoring,ubuntu

磁盤監視

command-line,gui,system,monitoring,ubuntu

係統熱量監測

如果鍵入glances --help,則會發現(-e啟用傳感器模塊(Linux-only))

glances -e

command-line,gui,system,monitoring,ubuntu

command-line,gui,system,monitoring,ubuntu

配置文件

您可以在Glances配置文件中設置閾值,在GNU /Linux上,默認配置文件位於/etc/glances/glances.conf中。

客戶端/服務器模式

此監視工具的另一個有趣功能是,隻需鍵入glances -s即可在服務器模式下啟動它,這將為Glances服務器運行在0.0.0.0:61209上提供輸出,現在可以使用glance從另一台計算機連接到它–c @server其中@server是服務器的IP地址或主機名。

Glances使用XML /RPC服務器,可以被其他客戶端軟件使用。在服務器模式下,您可以設置綁定地址(-B ADDRESS)和偵聽TCP端口(-p PORT),默認綁定地址為0.0.0.0(Glances將監聽所有網絡接口),並且TCP端口為61209.在客戶端模式下,可以設置服務器的TCP端口(-p端口)。在客戶端/服務器模式下,服務器端設置限製。版本1.6引入了一個可選的密碼來訪問服務器(-P密碼),如果在服務器上設置的話,也必須在客戶端上使用。

其他來源:PyPIGithubLinuxaria

Update

舉例來說,監控juju容器是如何看起來像Large Image

在終端號1中,Glances在服務器模式下運行,在終端號2中,juju容器正在運行apt-get update&在終端3中glances -c 192.168.1.103 Glances已連接到容器IP

command-line,gui,system,monitoring,ubuntu

次佳解決方案

indicator-SysMonitor

Indicator-SysMonitor做了一些,但做得很好。一旦安裝並運行,它將顯示頂部麵板上CPU和RAM的使用情況。簡單。

command-line,gui,system,monitoring,ubuntu

here下載

Conky的

我個人的最愛之一

command-line,gui,system,monitoring,ubuntu

Screenlet可以在Ubuntu軟件中心的screenlets-all軟件包中找到一堆不同風格的CPU和RAM監視器。

command-line,gui,system,monitoring,ubuntu

眼神

安裝:

sudo apt-get install python-pip build-essential python-dev
sudo pip install Glances
sudo pip install PySensors

command-line,gui,system,monitoring,ubuntu

VMSTAT

顯示有關CPU,內存,進程等的信息

IOSTAT

該命令行工具將顯示有關CPU的統計信息,硬盤分區的I /O信息,網絡文件係統(NFS)等。要安裝iostat,請運行以下命令:

sudo apt-get install sysstat

要啟動報告,請運行以下命令:

iostat

要僅檢查CPU統計信息,請使用以下命令:

iostat -c

有關更多參數,請使用以下命令:

iostat --help

MPSTAT

mpstat命令行實用程序將顯示每個處理器的平均CPU使用情況。要運行它,隻需使用以下命令:

mpstat

對於每個處理器的CPU使用率,請使用此命令:

mpstat -P ALL

Saidar

Saidar還允許通過命令行來監視係統設備活動。

command-line,gui,system,monitoring,ubuntu

你可以用這個命令來安裝:

sudo apt-get install saidar

要開始監控,請運行以下命令:

saidar -c -d 1

統計信息將每秒刷新一次。

的gkrellm

GKrellM是一個可定製的小部件,具有各種主題,可在桌麵係統設備信息(CPU,溫度,內存,網絡等)上顯示。

command-line,gui,system,monitoring,ubuntu

要安裝GKrellM,請運行以下命令:

sudo apt-get install gkrellm

Monitorix

Monitorix是另一個具有用於監視係統設備的web-based用戶界麵的應用程序。

command-line,gui,system,monitoring,ubuntu

使用以下命令安裝它:

sudo add-apt-repository ppa:upubuntu-com/ppa
sudo apt-get update
sudo apt-get install monitorix

通過此URL啟動Monitorix:

http://localhost/monitorix/

第三種解決方案

以下是用於監視Linux係統的工具

  1. 係統命令如topfree -mvmstatiostatiotopiotopsarnetstat等等。當您調試問題時,沒有任何東西在這些linux實用程序附近出現。這些命令為您提供了一個清晰的畫麵,它將進入您的服務器

  2. SeaLion:代理執行#1(也是用戶定義的)中提到的所有命令,這些命令的輸出可以在漂亮的Web界麵中訪問。當您在數百台服務器上進行調試時,此工具非常方便,因為安裝非常簡單。它的免費

  3. Nagios:它是所有監視/警報工具的母親。這是非常多的定製,但非常難以為初學者設置。有幾套叫做nagios插件的工具涵蓋了幾乎所有重要的Linux指標

  4. 穆寧

  5. 服務器密度:一種基於雲計算的付費服務,可收集重要的Linux指標並為用戶編寫自己的插件提供支持。

  6. New Relic:另一個眾所周知的托管監控服務。

  7. ZABBIX

第四種方案

在過去的幾年中,我使用了:

System Load Indicator

command-line,gui,system,monitoring,ubuntu

可從軟件中心獲得

第五種方案

最佳

top是監控軟件,列出所有CPU /RAM使用情況,整體CPU /RAM使用情況等等。大多數情況下默認安裝

HTOP

htop就像頂級的擴展版本。它具有上述所有功能,但您可以看到子進程並自定義顯示的所有內容。它也有顏色。

iotop

iotop專門用於監控硬核I /O它列出所有進程並顯示其硬盤驅動器的使用情況以供讀取和寫入。

第六種方案

您可能想嘗試sysmon。盡管不像Glances那麽華麗,但它非常簡單易用。

如果你想變得肮髒,並在python中做一些腳本,下麵是一些使用Python進行係統監控的基礎知識,以幫助你開始。

您需要一個名為psutil的外部模塊來監視大多數事情。使用外部模塊安裝程序最容易,而不是從源代碼構建。

注意:這些例子是用Python 2.7編寫的

sudo apt-get install pip
sudo pip install psutil

現在我們已經安裝了模塊,我們可以開始編碼。

首先,創建一個名為usage.py的文件。

gedit ~/usage.py

從導入psutil開始

import psutil

然後,創建一個函數來監視CPU核心運行的百分比。

def cpu_perc(): 

    cpu_perc = psutil.cpu_percent(interval=1, percpu=True) 
    for i in range(len(cpu_perc)):
        print "CPU Core", str(i+1),":", str(cpu_perc[i]), "%"

讓我們來分解一下,我們會嗎?

第一行cpu_num = psutil.cpu_percent(interval=1, percpu=True)查找CPU內核運行的百分比,並將其分配到名為cpu_perc的列表。

這個循環就在這裏

for i in range(len(cpu_num)):
    print "CPU Core", str(i+1),":", str(cpu_perc[i]), "%"

是一個for循環,打印出每個CPU內核的當前百分比。

我們來添加內存使用情況。

創建一個名為ram_perc的函數。

def ram_perc():
    mem = psutil.virtual_memory()
    mem_perc = mem.percent
    print "RAM: ", mem_perc, "%"

psutil.virtual_memory給出一個數據集,其中包含關於計算機中RAM的不同事實。

接下來,您可以添加一些有關您的網絡的事實。

def net():
    net = psutil.net_io_counters()
    mbytes_sent = float(net.bytes_sent) / 1048576
    mbytes_recv = float(net.bytes_recv) / 1048576
    print "MB sent: ", mbytes_sent
    print "MB received: ", mbytes_recv

由於psutil.net_io_counters()僅向我們提供有關以字節為單位發送和接收的數據包的信息,因此需要進行一些轉換。

要獲得有關交換空間的一些信息,請添加此功能。

def swap_perc():
    swap = psutil.swap_memory()
    swap_perc = swap.percent

這個很簡單。

溫度很難做,所以你可能需要做一些自己的研究來弄清楚你的硬件可以使用什麽。您將不得不顯示某個文件的內容。

磁盤使用比溫度要容易得多。您需要做的就是通過某個功能傳遞要監控的磁盤(即:/)。

def disks():
    if len(sys.argv) > 1:
        for disk in range(1, len(sys.argv)):
            tmp = psutil.disk_usage(sys.argv[disk])
            print sys.argv[disk], "\n"
            print "Megabytes total: ",
            print str(float(tmp.total) / 1048576)
            print "Megabytes used: ",
            print str(float(tmp.used) / 1048576)
            print "Megabytes free: ",
            print str(float(tmp.free) / 1048576)
            print "Percentage used: ",
            print tmp.percent, "\n"

psutil.disk_usage的原始輸出是這樣的,

>>>psutil.disk_usage('/')
sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)

但您也可以隻收到totalusedfreepercent

已完成的課程:(上述功能合並)

import psutil, os, sys
mem_perc = 0 #init var
swap_perc = 0 #init var
mbytes_sent = 0 #init var
mbytes_recv = 0 #init var
cpu_perc = 0 #init var
swap = 0 #init var
mem = 0 #init var
net = 0 #init var



def disp(degree):
    global cpu_perc
    global swap
    global swap_perc
    global mem
    global mem_perc
    global net
    global mbytes_sent
    global mbytes_recv

    cpu_perc = psutil.cpu_percent(interval=1, percpu=True)
    swap = psutil.swap_memory()
    swap_perc = swap.percent
    mem = psutil.virtual_memory()
    mem_perc = mem.percent
    net = psutil.net_io_counters()
    mbytes_sent = float(net.bytes_sent) / 1048576
    mbytes_recv = float(net.bytes_recv) / 1048576

    os.system('clear') #clear the screen

    print "-"*30
    print "CPU"
    print "-"*30
    print "CPU Temperature: " , degree, "'C"
    for i in range(len(cpu_perc)):
        print "CPU Core", str(i+1),":", str(cpu_perc[i]), "%"

    print "-"*30
    print "MEMORY"
    print "-"*30
    print "RAM: ", mem_perc, "%"
    print "Swap: ", swap_perc, "%"
    print "-"*30
    print "NETWORK"
    print "-"*30
    print "MB sent: ", mbytes_sent
    print "MB received: ", mbytes_recv
    print "-"*30
    print "DISKS"
    print "-"*30

    if len(sys.argv) > 1:
        for disk in range(1, len(sys.argv)):
            tmp = psutil.disk_usage(sys.argv[disk])
            print sys.argv[disk], "\n"
            print "Megabytes total: ",
            print str(float(tmp.total) / 1048576)
            print "Megabytes used: ",
            print str(float(tmp.used) / 1048576)
            print "Megabytes free: ",
            print str(float(tmp.free) / 1048576)
            print "Percentage used: ",
            print tmp.percent, "\n"

def main():
    print("Press Ctrl+C to exit")
    while True:
        temp = open("/sys/class/thermal/thermal_zone0/temp").read().strip().lstrip('temperature :').rstrip(' C')
        temp = float(temp) / 1000
        disp(temp)

main()

temp = open("/sys/class/thermal/thermal_zone0/temp").read().strip().lstrip('temperature :').rstrip(' C')行可能不適用於您的硬件配置。

從命令行運行該程序。將要監視的磁盤作為參數從命令行傳遞。

$ python usage.py /

Press Ctrl+C to exit

------------------------------
CPU
------------------------------
CPU Temperature:  39.0 'C
CPU Core 1 : 4.8 %
CPU Core 2 : 1.0 %
CPU Core 3 : 0.0 %
CPU Core 4 : 4.9 %
------------------------------
MEMORY
------------------------------
RAM:  33.6 %
Swap:  6.4 %
------------------------------
NETWORK
------------------------------
MB sent:  2.93382358551
MB received:  17.2131490707
------------------------------
DISKS
------------------------------
/ 

Megabytes total:  13952.484375
Megabytes used:  8542.6640625
Megabytes free:  4678.5703125
Percentage used:  61.2 

/media/calvin/Data 

Megabytes total:  326810.996094
Megabytes used:  57536.953125
Megabytes free:  269274.042969
Percentage used:  17.6 

希望這可以幫助!評論你是否有任何問題。

https://github.com/calthecoder/sysmon-1.0.1

第七種方案

systat有一個名為sar的工具,可以滿足您的所有需求。它還可以收集曆史數據,以便您可以查看前一段時間發生的情況。

第八種方案

SeaLion可以很方便使用,因為它具有內置命令來監視您的服務器性能以及您可以添加自己的自定義命令,scirpts和日誌輸出。這是非常容易設置,並找出在特定時間出了什麽問題。

command-line,gui,system,monitoring,ubuntu

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/400.html,未經允許,請勿轉載。