สวัสดีครับเรามาเรียนรู้วิธีการ Monitor เครื่อง Client ด้วย icinga กัน วิธีการ Monitor เครื่อง Client โดย icinga นั้นทำได้อยู่ 2 วิธี วิธีแรก Monitor ด้วย Service ที่ให้บริการบนเครื่อง Client เช่น Service HTTP, HTTPS, FTP, SMTP, POP3, IMAP เป็นต้น และอีกวิธีหนึ่งคือ Monitor ด้วยการติดตั้ง NRPE agent บนเครื่อง Client โดยเจ้า NRPE agent นี้สามารถที่จะ Monitor ได้ละเอียดกว่าวิธีแรกคือสามารถที่จะดูขนาดของ storage, ดูการใช้งาน CPU, RAM และสามารถ Monitor อื่นๆ ได้อีกมากมาย
โดยในตัวอย่างจะมี 3 เครื่อง คือ 1)เครื่อง icinga Server (icinga) 2)เครื่อง web server (agentweb) และ 3)เครื่อง agent NRPE (agentnrpe)
ขั้นตอนการ Monitor Service HTTP เครื่อง agentweb ให้ไป config ที่เครื่อง icinga ก่อน (ในตัวอย่างตั้งชื่อ file agentweb.cfg)
vi /etc/icinga/objects/agentweb.cfg
เพิ่ม config ดังนี้
ให้แก้ในส่วน host_name เป็นชื่อ host เครื่อง agentweb และตั้ง IP Address ของเครื่อง agentweb
define host { use generic-host host_name agentweb alias A Web Server address 172.17.0.11 } define service { use generic-service host_name agentweb service_description HTTP check_command check_http }
ทำการ reload service icinga
service icinga reload
ลองเข้าไปดูที่หน้า Web UI ของ icinga จะเห็นว่ามี host agentweb แล้วดังรูป
และคลิ๊กที่หัวข้อ Service Detail และดูที่ host agentweb จะมี service http อยู่ขึ้น Status OK
ที่นี้ผมทดสอบดับเครื่อง agentweb รอสักพักก็จะขึ้น Status CRITICAL
ที่นี้มาดูการ Monitor โดยใช้ NRPE Agent กันบ้างน่ะครับ ให้เราเข้าไปที่เครื่อง agentnrpe แล้วสั่งติดตั้ง package โดยใช้คำสั่ง
apt-get update && apt install nagios-plugins nagios-nrpe-server
list file system โดยใช้คำสั่ง
df -Th
ให้ดูว่าจะ Monitor ที่ File System ไหนแล้วเข้าไปแก้ไขไฟล์ที่
vi /etc/nagios/nrpe.cfg
หาบรรทัดที่เขียนว่า
- server_address: แก้ไข IP address ของเครื่องนี้ในตัวอย่างจะใส่เป็น 172.17.0.12
- allowed_hosts: แก้ไข IP address ของเครื่อง Icinga server (icinga) ในตัวอย่างใส่เป็น 172.17.0.14
- command[check_hda1]: เปลี่ยน /dev/hda1 เป็น root filesystem ในตัวอย่างจะใส่เป็น rootfs
เมื่อแก้ไข config แล้วจะได้แบบนี้
server_address=172.17.0.12 allowed_hosts=172.17.0.14 command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p rootfs
จากนั้นสั่ง restart service nagios-nrpe-server
service nagios-nrpe-server restart
ที่เครื่อง icinga server (icinga) ให้เพิ่ม config ของ host agentnrpe
vi /etc/icinga/objects/agentnrpe.cfg
เพิ่ม config ดังนี้
- host_name: ใส่ชื่อ host name ของเครื่อง agentnrpe
- address: ใส่ IP Address เครื่อง agentnrpe
define host { use generic-host host_name agentnrpe alias My web and databases server address 172.17.0.12 }
ใส่ config อย่างอื่นเพื่อ Monitor ไปด้วย
vi /etc/icinga/objects/agentnrpe.cfg
#Monitor Service SSH define service { use generic-service host_name agentnrpe service_description SSH check_command check_ssh notifications_enabled 0 } #Monitor Load define service { use generic-service host_name agentnrpe service_description Current Load check_command check_load!10.0!9.0!7.0!20.0!9.0!7.0 } #Current Users define service { use generic-service host_name agentnrpe service_description Current Users check_command check_users!20!50 } #Monitor Disk Space define service { use generic-service host_name agentnrpe service_description Disk Space check_command check_all_disks!20%!10% }
แล้ว reload service icinga
service icinga reload
ลองเข้าไปดูที่หน้า Web UI icinga => คลิ๊กที่ Service detail แล้วดูที่ host agentnrpe จะเห็นว่ามี service monitor 4 item status OK ทั้งหมด ถือว่าเรา config มาทั้งหมดนั้นถูกต้องแล้ว
ในบทความนี้ก็จะเป็น How to แบบง่ายๆ ซึ่งหากต้องการขั้น Advance ต้องอ่านใน Document ใน Web icinga เพิ่มเติมครับ
อ่านเพิ่มเติม – How To Use Icinga To Monitor Your Servers and Services On Ubuntu 14.04