Netdata – Linux 系統的即時效能監控工具
Netdata 是一款經過高度最佳化的 Linux 實用程式,它可以即時(每秒)監控 Linux 系統、應用程式、SNMP 裝置等的效能,並透過 Web 瀏覽器顯示完整的互動式圖表,以便使用者檢視收集到的所有值。本文介紹瞭如何為 Linux 系統找到一個即時效能監控工具。
功能
它監控總 CPU 使用率和每個核心的 CPU 使用率、中斷、軟中斷以及頻率。
它監控記憶體、RAM、交換分割槽和核心的使用情況。
它監控磁碟 I/O(每個磁碟:頻寬、操作、積壓、利用率等)。
它監控網路介面,包括:頻寬、資料包、錯誤、丟棄等)。
它監控 Netfilter/iptables Linux 防火牆連線、事件、錯誤等。
它監控程序(執行、阻塞、分叉、活動等)。
它使用程序樹監控系統應用程式(CPU、記憶體、交換分割槽、磁碟讀寫、執行緒等)。
使用 mod_status 監控 Apache 和 Nginx 狀態。
監控 MySQL 資料庫:查詢、更新、鎖定、問題、執行緒等。
它監控 Postfix 郵件伺服器的訊息佇列。
監控 Squid 代理伺服器的頻寬和請求。
它監控硬體感測器(溫度、電壓、風扇、電源、溼度等)。
它監控 SNMP 裝置。
在安裝 netdata 實用程式之前,請確保系統上已安裝以下基本構建環境軟體包,如果沒有,請安裝它們。使用以下命令安裝通用構建環境:
$ sudo apt-get install zlib1g-dev gcc make git autoconf autogen automake pkg-config
示例輸出應如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done gcc is already the newest version (4:5.3.1-1ubuntu1). gcc set to manually installed. make is already the newest version (4.1-6). make set to manually installed. pkg-config is already the newest version (0.29.1-0ubuntu1). pkg-config set to manually installed. The following additional packages will be installed: autogen-doc autotools-dev git-man liberror-perl libopts25 libopts25-dev libsigsegv2 m4 Suggested packages: autoconf-archive gnu-standards autoconf-doc libtool git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn The following NEW packages will be installed: autoconf autogen autogen-doc automake autotools-dev git git-man liberror-perl libopts25 libopts25-dev libsigsegv2 m4 zlib1g-dev 0 upgraded, 13 newly installed, 0 to remove and 7 not upgraded. Need to get 6,721 kB of archives. After this operation, 35.2 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 libsigsegv2 amd64 2.10-4 [14.1 kB] Get:2 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 m4 amd64 1.4.17-5 [195 kB] Get:3 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 autoconf all 2.69-9 [321 kB] Get:4 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 libopts25 amd64 1:5.18.7-3 [57.8 kB] Get:5 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 libopts25-dev amd64 1:5.18.7-3 [93.0 kB] Get:6 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 autogen amd64 1:5.18.7-3 [550 kB] .................................................................................................
從 git 克隆 netdata 儲存庫,並執行以下命令安裝 netdata 安裝程式指令碼以構建它。
$ sudo git clone https://github.com/firehol/netdata.git --depth=1
示例輸出應如下所示:
Cloning into 'netdata'... remote: Counting objects: 253, done. remote: Compressing objects: 100% (241/241), done. remote: Total 253 (delta 10), reused 137 (delta 1), pack-reused 0 Receiving objects: 100% (253/253), 1.33 MiB | 471.00 KiB/s, done. Resolving deltas: 100% (10/10), done. Checking connectivity... done.
現在進入 netdata 目錄並使用以下命令安裝 netdata 安裝程式:
$ cd netdata $ sudo ./netdata-installer.sh
示例輸出應如下所示:
Welcome to netdata! Nice to see you are giving it a try! You are about to build and install netdata to your system. It will be installed at these locations: - the daemon at /usr/sbin/netdata - config files at /etc/netdata - web files at /usr/share/netdata - plugins at /usr/libexec/netdata - cache files at /var/cache/netdata - log files at /var/log/netdata - pid file at /var/run This installer allows you to change the installation path. Press Control-C and run the same command with --help for help. Press ENTER to build and install netdata to your system > :----------------------------------------------------------------------------- Running command: ./autogen.sh autoreconf: Entering directory `.' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I m4 autoreconf: configure.ac: tracing autoreconf: configure.ac: not using Libtool autoreconf: running: /usr/bin/autoconf --force autoreconf: running: /usr/bin/autoheader --force autoreconf: running: automake --add-missing --copy --force-missing configure.ac:33: installing './compile' configure.ac:32: installing './config.guess' configure.ac:32: installing './config.sub' configure.ac:31: installing './install-sh' configure.ac:31: installing './missing' src/Makefile.am: installing './depcomp' autoreconf: Leaving directory `.' :----------------------------------------------------------------------------- Running the command: ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-zlib --with-math --with-user=netdata CFLAGS=-O3 checking whether to enable maintainer-specific portions of Makefiles... no checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking minix/config.h usability... no checking minix/config.h presence... no checking for minix/config.h... no checking whether it is safe to define __EXTENSIONS__... yes checking if compiler needs -Werror to reject unknown flags... no checking for the pthreads library -lpthreads... no checking whether pthreads work without any flags... no checking whether pthreads work with -Kthread... no checking whether pthreads work with -kthread... no checking for the pthreads library -llthread... no checking whether pthreads work with -pthread... yes checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE checking if more special flags are required for pthreads... no checking for PTHREAD_PRIO_INHERIT... yes checking for uint8_t... yes checking for uint16_t... yes checking for uint32_t... yes checking for inline... inline checking for sin in -lm... yes checking for ZLIB... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating charts.d/Makefile config.status: creating conf.d/Makefile config.status: creating netdata.spec config.status: creating node.d/Makefile config.status: creating plugins.d/Makefile config.status: creating src/Makefile config.status: creating system/Makefile config.status: creating web/Makefile config.status: creating contrib/Makefile .............................................
要啟動 netdata,請使用以下命令:
# /usr/sbin/netdata
現在開啟您喜歡的 Web 瀏覽器,並輸入以下 URL:
http://127.0.0.1:19999/
示例輸出應如下所示:
要停止 netdata,請使用以下命令:
$ sudo killall netdata
您也可以隨時使用以下 URL 檢視 netdata 的執行配置:
http://127.0.0.1:19999/netdata.conf
示例輸出應如下所示:
# NetData Configuration # You can uncomment and change any of the options below. # The value shown in the commented settings, is the default value. # global netdata configuration [global] # config directory = /etc/netdata # plugins directory = /usr/libexec/netdata/plugins.d # web files directory = /usr/share/netdata/web # cache directory = /var/cache/netdata # log directory = /var/log/netdata # host access prefix = # debug flags = 0x00000000 # memory deduplication (ksm) = yes # debug log = /var/log/netdata/debug.log # error log = /var/log/netdata/error.log # errors flood protection period = 1200 # errors to trigger flood protection = 200 # access log = /var/log/netdata/access.log # memory mode = save # hostname = linux # history = 3600 # update every = 1 # pthread stack size = 8388608 # run as user = netdata # web files owner = netdata # web files group = netdata # http port listen backlog = 100 # port = 19999 # ip version = any # bind socket to IP = * # disconnect idle web clients after seconds = 60 # enable web responses gzip compression = yes [plugins] # tc = yes # idlejitter = yes # proc = yes # cgroups = yes # checks = no # plugins directory = /usr/libexec/netdata/plugins.d # enable running new plugins = yes # check for new plugins every = 60 # apps = yes # charts.d = yes # node.d = yes # per plugin configuration [plugin:tc] # script to run to get tc values = /usr/libexec/netdata/plugins.d/tc-qos-helper.sh # enable new interfaces detected at runtime = yes # cleanup unused classes every = 60 [plugin:idlejitter] # loop time in ms = 20
要更新 netdata,請使用以下命令:
# cd /path/to/netdata.git # git pull # ./netdata-installer.sh
恭喜!現在,您瞭解了“Netdata – Linux 系統的即時效能監控工具”。我們將在下一篇文章中學習更多關於此類命令的知識。繼續關注!