Try to use netdata on CentOS 7

Twitter上偶然看到一張很漂亮的動態監控圖,查看之後才知道是由一款名爲netdata的開源工具實現,獲取實時(秒級)數據並用動態圖表展示,數據從/proc相關文件獲取(Linux中一切皆文件,內核將硬件虛擬成文件來進行管理)。

Introduction

netdata代碼發佈在GitHub上。

以下是相關文檔

Prerequisites

netdata依賴一些包,如makegccautoconfautogenautomakepkg-configgit等。

git可使用yum安裝,也可參考本人的Compile Install And Configure Git On CentOS7通過源碼編譯安裝。

執行如下命令安裝依賴包

 

sudo yum install -y libuuid libuuid-devel zlib zlib-devel gcc make autoconf automake pkgconfig

#根據個人情況使用

sudo yum install -y git

Node.js

官方稱:netdata使用node.js進行數據收集,其node.d.plugin會在系統路徑(system path)中查找node.js的可執行文件。

官方強烈建議使用node.js,並稱

Only node.js will work with netdata.

關於node.js的安裝,可參考本人的 Compile and Install Node.js on CentOS7

Netdata Build Introduction

通過git下載netdata倉庫後進行安裝,官方提供的操作步驟

 

# download it – the directory 'netdata.git' will be created

git clone https://github.com/firehol/netdata.git netdata.git –depth=1

cd netdata.git

# build it

./netdata-installer.sh

如果想自定義安裝目錄(如/opt),可使用如下命令

 

./netdata-installer.sh –install /opt

實際操作過程是

 

./configure –prefix=/opt/netdata/usr –sysconfdir=/opt/netdata/etc –localstatedir=/opt/netdata/var –with-zlib –with-math –with-user=netdata CFLAGS=-O3

make

make install

groupadd -r netdata

useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata

chown -R netdata:netdata /opt/netdata/usr/share/netdata/web

chmod 0775 /opt/netdata/usr/share/netdata/web

chown -R netdata:netdata /opt/netdata/etc/netdata

chmod 0775 /opt/netdata/etc/netdata

chown -R netdata:netdata /opt/netdata/var/cache/netdata

chmod 0775 /opt/netdata/var/cache/netdata

chown -R netdata:netdata /opt/netdata/var/log/netdata

chmod 0775 /opt/netdata/var/log/netdata

chown root /opt/netdata/usr/libexec/netdata/plugins.d/apps.plugin

chmod 4755 /opt/netdata/usr/libexec/netdata/plugins.d/apps.plugin

注意:自定義安裝路徑後,配置文件路徑對應更改

FILE PATH
the daemon /opt/netdata/usr/sbin/netdata
config files /opt/netdata/etc/netdata
web files /opt/netdata/usr/share/web/netdata
plugins /opt/netdata/usr/libexec/netdata
cache files /opt/netdata/var/cache/netdata (輪詢數據)
log files /opt/netdata/var/log/netdata

Updating

如何更新,官方提供的方案是

 

# update it

cd /path/to/netdata.git

git pull

# rebuild it and install it

./netdata-installer.sh

即更新git倉庫後,重新安裝即可。

Installation

以安裝到目錄/opt爲例

 

 

 

#進入/opt目錄

cd /opt

#git下載倉庫

sudo git clone https://github.com/firehol/netdata.git netdata.git –depth=1

#進入目錄

cd netdata.git

#執行安裝,並指定安裝路徑

sudo ./netdata-installer.sh –install /opt

安裝完成後提示

 

Running command:

/opt/netdata/usr/sbin/netdata

OK. NetData Started!

Downloading default configuration from netdata…

New configuration saved for you to edit at /opt/netdata/etc/netdata/netdata.conf

ok. NetData is installed and is running.

Hit http://localhost:19999/ from your browser.

To stop netdata, just kill it, with:

killall netdata

To start it, just run it:

/opt/netdata/usr/sbin/netdata

Enjoy!

INFORMATION:

I see you have kernel memory de-duper (called Kernel Same-page Merging,

or KSM) available, but it is not currently enabled.

To enable it run:

echo 1 >/sys/kernel/mm/ksm/run

echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs

If you enable it, you will save 20-60% of netdata memory.

目錄樹

 
 

[flying@lemp netdata]$ pwd

/opt/netdata

[flying@lemp netdata]$ tree -L 3

.

├── etc

│ └── netdata

│ ├── apps_groups.conf

│ ├── charts.d.conf

│ └── netdata.conf

├── usr

│ ├── libexec

│ │ └── netdata

│ ├── sbin

│ │ └── netdata

│ └── share

│ └── netdata

└── var

├── cache

│ └── netdata

└── log

└── netdata

13 directories, 4 files

[flying@lemp netdata]$

Configuration

Systemd Support

使用systemd管理netdata,官方提供了netdata-systemd示例文件 鏈接

創建文件/usr/lib/systemd/system/netdata.service,寫入如下內容

 

[Unit]

Description=netdata

After=network.target httpd.service nginx.service squid.service nfs-server.service mysqld.service named.service postfix.service

[Service]

Type=forking

WorkingDirectory=/opt/netdata

User=root

Group=root

PIDFile=/var/run/netdata/netdata.pid

ExecStart=/opt/netdata/usr/sbin/netdata

ExecStop=/bin/kill -SIGTERM $MAINPID

TimeoutStopSec=30

[Install]

WantedBy=multi-user.target

直接執行
systemctl status|start|restart|stop|reload|enable|disable netdata.service
可能無法成功,可先執行
killall netdata,再執行systemctl命令。

  • 啓動 systemctl start netdata.service
  • 開機啓動 systemctl enable netdata.service

Plugins

官方提供了一些Shell腳本做插件擴展,可用於監控mysqlnginxapache等服務。

安裝後存放路徑爲/opt/netdata/usr/libexec/netdata/charts.d/

 

1

2

3

4

5

6

7

8

9

10

11

 

[flying@lemp ~]$ cd /opt/netdata/usr/libexec/netdata/charts.d

[flying@lemp charts.d]$ pwd

/opt/netdata/usr/libexec/netdata/charts.d

[flying@lemp charts.d]$ ls

airsearches.chart.sh example.chart.sh opensips.chart.sh

apache.chart.sh load_average.chart.sh postfix.chart.sh

ap.chart.sh mem_apps.chart.sh README.md

cpu_apps.chart.sh mysql.chart.sh sensors.chart.sh

cpufreq.chart.sh nginx.chart.sh squid.chart.sh

crsproxy.chart.sh nut.chart.sh

[flying@lemp charts.d]$

官方說明 https://github.com/firehol/netdata/blob/master/charts.d/README.md

而配置文件路徑是/opt/netdata/etc/netdata/,如果需要添加某功能插件,在該目錄下新建對應配置文件,以下是示例:

nginx.chart.sh

腳本文件: /opt/netdata/usr/libexec/netdata/charts.d/nginx.chart.sh

腳本通過http://127.0.0.1:80/stub_status獲取stub_status信息,在Nginx配置文件中配置

 

location /stub_status {

stub_status on;

access_log off;

allow 127.0.0.1;

deny all;

}

使用nginx -t檢查是否有於法錯誤,執行systemctl reload nginx重新載入配置文件。

執行systemctl restart netdata.service重啓netdata服務後,即可查看到已經正常監控Nginx。

apache.chart.sh

腳本文件: /opt/netdata/usr/libexec/netdata/charts.d/apache.chart.sh

腳本通過http://127.0.0.1:80/server-status?auto獲取

在目錄/etc/httpd/conf.d下創建文件status.conf,寫入如下內容

 

<location /server-status>

SetHandler server-status

Order Deny,Allow

Deny from all

Allow from 127.0.0.1

</location>

ExtendedStatus On

使用httpd -t檢查是否有於法錯誤,執行systemctl reload httpd重新載入配置文件。

執行systemctl restart netdata.service重啓netdata服務後,即可查看到已經正常監控Apache httpd。

mysql.chart.sh

腳本文件: /opt/netdata/usr/libexec/netdata/charts.d/mysql.chart.sh

根據官方文檔提供的操作說明,始終操作不成功。直接閱讀腳本mysql.chart.sh,讓無法解決。

以下是netdata錯誤日誌中信息

 

[flying@lemp netdata]$ pwd

/opt/netdata/var/log/netdata

[flying@lemp netdata]$ cat error.log | grep mysql

charts.d: mysql: cannot get global status for 'mariadb'. Please set mysql_opts[mariadb]='options' to whatever needed to get connected to the mysql server, in /opt/netdata/etc/netdata/mysql.conf

charts.d: mysql: no mysql servers found. Please set mysql_opts[name]='options' to whatever needed to get connected to the mysql server, in /opt/netdata/etc/netdata/mysql.conf

charts.d: chart 'mysql' check() function reports failure.

[flying@lemp netdata]$

暫時擱置

Working

啓動netdata.service後,在瀏覽器地址欄中輸入

 

http://127.0.0.1:19999/

http://localhost:19999/

即可看到動態圖表,顯示內容如http://netdata.firehol.org/中顯示。

Virtualization On-line

本人在VPS上測試成功,在瀏覽器中輸入URL,即可顯示可視化數據。

通過https://仍能正常使用SSL,但會出現一個問題,無法再使用http://(會自動跳轉到https),須清空瀏覽器緩存才可以,該問題暫未能解決。

以下圖片來自Netstat的git倉庫 地址

  • Overview

 

 

  • Disk I/O

     

  • Network interfaces

     

  • Network QoS

     

  • Applications

     

Running Behind Nginx

通過Nginx訪問netdata可參考官方文檔 Running behind nginx

此處為其配置SSL證書

As a virtual host

Nginx配置文件

 
 

upstream backend {

server 127.0.0.1:19999;

keepalive 64;

}

server {

listen 80;

server_name netdata.lemptest.tech;

return 301 https://$server_name$request_uri;

}

server {

listen 443 ssl default_server;

server_name netdata.lemptest.tech;

location / {

proxy_set_header X-Forwarded-Host $host;

proxy_set_header X-Forwarded-Server $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://backend;

proxy_http_version 1.1;

proxy_pass_request_headers on;

proxy_set_header Connection "keep-alive";

proxy_store off;

}

ssl_configuation

}

截圖

 

Subfolder Of Existing Virtual Host

Nginx配置文件

 
upstream netdata {

server 127.0.0.1:19999;

keepalive 64;

}

# redirect http to https

server {

listen 80;

server_name lemptest.tech;

return 301 https://$server_name$request_uri;

}

server {

listen 443 ssl default_server;

server_name lemptest.tech;

root /usr/share/nginx/html;

location /netdata {

return 301 /netdata/;

}

location ~ /netdata/(?<ndpath>.*) {

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-Host $host;

proxy_set_header X-Forwarded-Server $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;

proxy_pass_request_headers on;

proxy_set_header Connection "keep-alive";

proxy_store off;

proxy_pass http://netdata/$ndpath$is_args$args;

gzip on;

gzip_proxied any;

gzip_types *;

}

ssl_configuation

}

截圖

 

Netdata Official Collection

偶然間到Netdata的github看了下,隨意點進了一個頁面what our users say about netdata?,意外發現自己這篇文章的截圖被ktsaou展示出來了,好激動。

此爲鏈接錨點
https://github.com/firehol/netdata/issues/148#issuecomment-206824520

Read more

How to migrate Raspberry Pi 5 OS from micro SD to NVME m.2 SSD

首先我買了Raspberry Pi CM5後來買了Raspberry Pi CM5 I/O board來當個人電腦使用,系統是安裝在256GB SD卡上運行的很好。用久了在開啟較肥的程式像Web Browser或LiberOffice會有慢半拍的反應,而有了升級NVME m.2 SSD念頭。 因為Raspberry Pi 5支援的最快PCIe gen3 x 4就不去考慮快的Gen4 or Gen5 m.2 SSD。找了ADATA出的 LEGEND 710入門級的產品,會利用HMB(Host Memory Buffer)來加速I/O速度,因為是Raspberry Pi OS kernel會認不得而無法正常使用 事先在SD卡的/boot/firmware/cmdline.txt 加入 kernel command line參數如下,然後重開機m.

By Phillips Hsieh

How to document Home Lab and Network

運維機房和跨域的網路,會遇到各式需求與問題,用對工具才能分析問題,個人覺得最重要的是使用能處理問題的工具。 推薦目前想學和正在使用的平台與軟體,協助將公司/家用機房文件化 佈告欄任務管理 Focalboard 白板可管理任務指派 網路架構文件編寫 netbox 精細管理網路設備與連接線路 IP 資源管理 phpipam 專注網路IP分配 邏輯塊文件編寫 draw.io 視覺化概念圖 機房設備管理 ITDB 管理設備生命週期與使用者

By Phillips Hsieh

如何在Raspberry Pi4上安裝Proxmox for ARM64

第一步 準備好Raspberry Pi 4 / CM4 4GB RAM,這裡要留意CM4如果是買有內建eMMC storage會限制不能使用SD卡開機而限制本地空間容量,如果沒有NAS外接空間或使用USB開機的話,建議買CM4 Lite插上大容量SD卡 第二步 去Armbian官網下載最小化Debian bookworm image https://www.armbian.com/rpi4b/ Armbian 25.2.2 Bookworm Minimal / IOT 然後寫入SD/USB開機碟,寫入方法參考官方文件 https://github.com/raspberrypi/usbboot/blob/master/Readme.md Note: 官方提供的預先設定系統方法,可以在Armbian初次啟動自動化完成系統設定。連結在此 https://docs.armbian.com/User-Guide_Autoconfig/

By Phillips Hsieh

世界越快心越慢

在晚飯後的休息時間,我特別享受在客廳瀏灠youtube上各樣各式創作者的影音作品。很大不同於傳統媒體,節目多是針對大多數族群喜好挑選的,在youtube上我會依心情看無腦的動畫、一些旅拍記錄、新聞時事談論。 尤其在看了大量的Youtube的分享後,我真的感受到會限制我的是我的無知,特別是那些我想都沒想過的實際應用,在學習後大大幫助到我的生活和工作層面。 休息在家時,我喜歡想一些沒做過的菜,動手去設計生活和工作上的解決方案,自己是真的很難閒著沒事做。 如創作文章,陪養新的習慣都能感覺到成長的喜悅,是不同於吃喝玩樂的快樂的。 創作不去限制固定的形式,文字是創作、影像聲音也是創作,記錄生活也是創作,我想留下的就是創造—》實現—》回憶,這樣子的循環過程,在留下的足跡面看到自己一路上的成長、失敗、絕望、重新再來。 雖然大部份的時候去做這些創作也不明白有什麼特別的意義,但不去做也不會留下什麼,所以呀不如反事都去試試看,也許能有不一樣的水花也許有意想不到的結果,投資自己永遠不會是失敗的決定,不是嗎?先問問自己再開始計畫下一步,未來沒人說得準。 像最近看youtube仍大一群人在為DOS開

By Phillips Hsieh