Monitor การทำงานของเครื่อง Linux ด้วย Netdata
จริงๆแล้วเครื่องมือที่ใช้ในการ monitor เครื่อง Linux Server มีอยู่มากมาย เครื่องมือที่จะแสดงให้ดูในวันนี้ก็เช่นกัน นั่นคือ Netdata แต่สิ่งที่แตกต่างจากเครื่องมือตัวอื่นๆก็ตรงที่ Netdata ค่อนข้างจะสวยงามและใช้งานง่ายนั่นเองครับ
(เครื่องที่ทดสอบคือ Ubuntu 16.04)
1. Install Require Package
1 |
curl -Ss 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh' >/tmp/kickstart.sh && bash /tmp/kickstart.sh -i netdata-all |
2. ติดตั้ง netdata
1 2 3 |
git clone https://github.com/firehol/netdata.git --depth=1 cd netdata ./netdata-installer.sh |
3. จากนั้นเข้าใช้งานได้เลย โดยเข้าไปที่ “IP ของเครื่องที่ติดตั้ง:19999” (โดยเราจะ monitor ได้แทบจะสถานะการทำงานทุกอย่างของเครื่องโดย default เลยครับ แทบไม่ต้องปรับแต่ง configuration อะไรเพิ่มเลย)
หากต้องการเปลี่ยนแปลง configuration ใดๆ รวมถึง port ที่ให้บริการของ netdata สามารถไปแก้ไขได้ที่ /etc/netdata/netdata.conf
4. หากต้องการให้ netdata ทำงานแบบ auto start เมื่อบูทเครื่องให้ทำโดย
1 2 3 |
cp system/netdata-lsb /etc/init.d/netdata chmod +x /etc/init.d/netdata update-rc.d netdata defaults |
โดยใน folder git ที่เรา download ลงมา หลังจากที่ใช้ ./netdata-installer.sh แล้ว จะมีการสร้าง netdata-updater.sh เพิ่มขึ้นมา ซึ่งไฟล์ดังกล่าวเอาไว้สำหรับการ update netdata version ใหม่ๆนั่นเอง หากเราต้องการจะให้ auto update อยู่เสมอให้สร้าง cronjob ขึ้นมา
1 2 3 4 |
crontab -e # add a cron-job at the bottom. This one will update netdata every day at 6:00AM: 0 6 * * * /path/to/git/downloaded/netdata/netdata-updater.sh |
หากต้องการ uninstall netdata ก็สามารถทำได้ง่ายๆเช่นกัน โดยไปที่ folder git ที่เรา download ลงมา จากนั้นใช้คำสั่ง
1 |
./netdata-uninstaller.sh --force |
ก็จะกลายเป็นการถอนการติดตั้ง netdata ออกไปจากเครื่องครับ
หากต้องการจะให้บริการหลังเครื่อง Nginx สามารถทำได้โดยการสร้าง server configuration เป็น
Configuration การเข้าถึงแบบ subdomain (Virtual Host)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
upstream backend { # the netdata server server 127.0.0.1:19999; keepalive 64; } server { # nginx listens to this listen 80; # the virtual host name of this server_name netdata.example.com; 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; } } |
Configuration การเข้าถึงแบบ directory บนเว็บไซด์
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
upstream netdata { server 127.0.0.1:19999; keepalive 64; } server { listen 80; # the virtual host name of this subfolder should be exposed #server_name netdata.example.com; 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 *; } } |
หากต้องการ monitor service ใดๆเพิ่มเติม สามารถดูได้ที่ https://github.com/firehol/netdata/tree/master/python.d
Source:: https://github.com/firehol/netdata