มาเริ่ม มอนิเตอร์ OLVM และทำการแจ้งเตือนผ่านซอฟแวร์ Grafana กันเถอะ

Thanakrit Phuraesri
Sirisoft
Published in
9 min readDec 21, 2022

สวัสดีครับ ผมชื่อฟิวครับ ตอนนี้กำลังทำงานในตำแหน่ง Software Engineer อยู่ที่บริษัท Sirisoft ครับ ต้องขอบคุณทางบริษัท Sirisoft ที่ได้ให้โอกาสผมได้ร่วมงานกับทางบริษัทครับ วันนี้ผมจะมาแนะนำ Feature ในการ Monitor VM (Virtual Machine) ของ Software Oracle Linux Virtualization Manager (OLVM) ไปดูกันเลยว่า ตัว Oracle Linux Virtualization Manager คืออะไร และมี Feature ใน Monitor VM เป็นยังไง ไปดูกันเลยครับ

Oracle Linux Virtualization Manager คืออะไร ?

Oracle Linux Virtualization Manager หรือเรียกว่า OLVM เป็น Hypervisor ชนิดหนึ่งของ Oracle ที่จะช่วยจัดการในเรื่องของ Storage Network และรวมถึงการสร้างและจัดการ Virtual Machine (VM) และยังสามารถจัดการอย่างอื่นได้อีกด้วย ซึ่งการใช้งานนั้นสะดวกสบายมากครับเพราะตัว OLVM นั้นมีหน้า Console มาให้ด้วยจึงทำให้เรานั้นสามารถจัดการทุกอย่างผ่านหน้า Console ได้เลย จึงทำให้สะดวกสบายมากยิ่งขึ้นแต่นี้ยังไม่ได้เป็นหัวข้อหลักของเราในวันนี้เราไปดูหัวข้อหลักของเรากันเลยดีกว่า

Feature ในการ Monitor VM (Virtual Machine) ของ OLVM

ในปกติแล้วตัว OLVM นั้นได้มี Feature ในการ Monitor VM มาด้วย ซึ่งในปกติแล้ว ตัว OLVM นั้นก็จะมีการ Monitor ตัว Server ที่เป็น physical แล้ว storage อยู่แล้ว แต่ในระดับการ Monitor VM นั้นเราต้องทำการติดตั้ง Tool หรือ Software ในการ Monitor อย่างเช่น ELK หรือ Grafana จากนั้นเราก็ต้องลงตัว exporter ในการเก็บข้อมูลของเครื่องที่เราต้องการ monitor ซึ่งมันยุ่งยากมากเพราะว่าใน Server ของเรานั้นมีจำนวนเครื่อง VM ที่เยอะมาก จึงทำให้เสียเวลาในการติดตั้งเป็นอย่างมาก ซึ่งในการ Monitor VM นั้นเราต้องทำการตั้งค่าให้ตัว OLVM นั้นสร้าง Database ขึ้นมาเพื่อทำการเก็บข้อมูล Metric โดยในการตั้งค่านั้นเราต้องตั้งค่าตั้งแต่ตอนที่เราลงตัว OLVM เลย ซึ่งในที่นี้ผมใช้ Oracle Linux Virtualization Manager (OLVM) เป็น version 4.4 มาดูวิธีการติดตั้งและการตั้งค่ากันเลยครับ

Install OLVM version 4.4

dnf install oracle-ovirt-release-el8
dnf repolist
dnf install ovirt-engine

Setup and start OLVM

engine-setup

Example output setup and start OLVM

[ INFO  ] Stage: Initializing
[ INFO ] Stage: Environment setup
Configuration files: /etc/ovirt-engine-setup.conf.d/10-packaging-jboss.conf, /etc/ovirt-engine-setup.conf.d/10-packaging.conf
Log file: /var/log/ovirt-engine/setup/ovirt-engine-setup-20220725103208-vp6a4t.log
Version: otopi-1.9.5 (otopi-1.9.5-1.el8)
[ INFO ] Stage: Environment packages setup
[ INFO ] Stage: Programs detection
[ INFO ] Stage: Environment setup (late)
[ INFO ] Stage: Environment customization

--== PRODUCT OPTIONS ==--

Configure Cinderlib integration (Currently in tech preview) (Yes, No) [No]:
Configure Engine on this host (Yes, No) [Yes]:

Configuring ovirt-provider-ovn also sets the Default cluster's default network provider to ovirt-provider-ovn.
Non-Default clusters may be configured with an OVN after installation.
Configure ovirt-provider-ovn (Yes, No) [Yes]:
Configure WebSocket Proxy on this host (Yes, No) [Yes]:

* Please note * : Data Warehouse is required for the engine.
If you choose to not configure it on this host, you have to configure
it on a remote host, and then configure the engine on this host so
that it can access the database of the remote Data Warehouse host.
Configure Data Warehouse on this host (Yes, No) [Yes]:
Configure VM Console Proxy on this host (Yes, No) [Yes]:
Configure Grafana on this host (Yes, No) [Yes]:

--== PACKAGES ==--

[ INFO ] Checking for product updates...
[ INFO ] DNF Package grafana-postgres available, but not installed.
[ INFO ] No product updates found

--== NETWORK CONFIGURATION ==--

Host fully qualified DNS name of this server [kvm02.local.com]:
[WARNING] Failed to resolve kvm02.local.com using DNS, it can be resolved only locally

Setup can automatically configure the firewall on this system.
Note: automatic configuration of the firewall may overwrite current settings.
Do you want Setup to configure the firewall? (Yes, No) [Yes]:
[ INFO ] firewalld will be configured as firewall manager.

--== DATABASE CONFIGURATION ==--

Where is the DWH database located? (Local, Remote) [Local]:

Setup can configure the local postgresql server automatically for the DWH to run. This may conflict with existing applications.
Would you like Setup to automatically configure postgresql and create DWH database, or prefer to perform that manually? (Automatic, Manual) [Automatic]:
Where is the Engine database located? (Local, Remote) [Local]:

Setup can configure the local postgresql server automatically for the engine to run. This may conflict with existing applications.
Would you like Setup to automatically configure postgresql and create Engine database, or prefer to perform that manually? (Automatic, Manual) [Automatic]:

--== OVIRT ENGINE CONFIGURATION ==--

Engine admin password:
Confirm engine admin password:
[WARNING] Password is weak: The password is shorter than 8 characters
Use weak password? (Yes, No) [No]: Yes
Application mode (Virt, Gluster, Both) [Both]:
Use default credentials (admin@internal) for ovirt-provider-ovn (Yes, No) [Yes]:

--== STORAGE CONFIGURATION ==--

Default SAN wipe after delete (Yes, No) [No]:

--== PKI CONFIGURATION ==--

Organization name for certificate [local.com]:

--== APACHE CONFIGURATION ==--

Setup can configure the default page of the web server to present the application home page. This may conflict with existing applications.
Do you wish to set the application as the default page of the web server? (Yes, No) [Yes]:

Setup can configure apache to use SSL using a certificate issued from the internal CA.
Do you wish Setup to configure that, or prefer to perform that manually? (Automatic, Manual) [Automatic]:

--== SYSTEM CONFIGURATION ==--


--== MISC CONFIGURATION ==--

Please choose Data Warehouse sampling scale:
(1) Basic
(2) Full
(1, 2)[1]:
Use Engine admin password as initial Grafana admin password (Yes, No) [Yes]:

--== END OF CONFIGURATION ==--

[ INFO ] Stage: Setup validation
[WARNING] Less than 16384MB of memory is available

--== CONFIGURATION PREVIEW ==--

Application mode : both
Default SAN wipe after delete : False
Host FQDN : kvm02.local.com
Firewall manager : firewalld
Update Firewall : True
Set up Cinderlib integration : False
Configure local Engine database : True
Set application as default page : True
Configure Apache SSL : True
Engine database host : localhost
Engine database port : 5432
Engine database secured connection : False
Engine database host name validation : False
Engine database name : engine
Engine database user name : engine
Engine installation : True
PKI organization : local.com
Set up ovirt-provider-ovn : True
Grafana integration : True
Grafana database user name : ovirt_engine_history_grafana
Configure WebSocket Proxy : True
DWH installation : True
DWH database host : localhost
DWH database port : 5432
DWH database secured connection : False
DWH database host name validation : False
DWH database name : ovirt_engine_history
Configure local DWH database : True
Configure VMConsole Proxy : True

Please confirm installation settings (OK, Cancel) [OK]:
[ INFO ] Stage: Transaction setup
[ INFO ] Stopping engine service
[ INFO ] Stopping ovirt-fence-kdump-listener service
[ INFO ] Stopping dwh service
[ INFO ] Stopping vmconsole-proxy service
[ INFO ] Stopping websocket-proxy service
[ INFO ] Stage: Misc configuration (early)
[ INFO ] Stage: Package installation
[ INFO ] DNF Downloading 4 files, 16083.99KB
[ INFO ] DNF Downloaded ovirt-vmconsole-1.0.9-3.el8.noarch.rpm
[ INFO ] DNF Downloaded selinux-policy-3.14.3-80.0.4.el8_5.2.noarch.rpm
[ INFO ] DNF Downloaded selinux-policy-targeted-3.14.3-80.0.4.el8_5.2.noarch.rpm
[ INFO ] DNF Downloaded ovirt-vmconsole-proxy-1.0.9-3.el8.noarch.rpm
[ INFO ] DNF Upgraded: selinux-policy-3.14.3-80.0.4.el8_5.2.noarch
[ INFO ] DNF Upgraded: selinux-policy-targeted-3.14.3-80.0.4.el8_5.2.noarch
[ INFO ] DNF Upgraded: ovirt-vmconsole-1.0.9-3.el8.noarch
[ INFO ] DNF Upgraded: ovirt-vmconsole-proxy-1.0.9-3.el8.noarch
[ INFO ] DNF Unknown: ovirt-vmconsole-proxy-1.0.9-2.el8.noarch
[ INFO ] DNF Unknown: ovirt-vmconsole-1.0.9-2.el8.noarch
[ INFO ] DNF Unknown: selinux-policy-targeted-3.14.3-80.0.1.el8.noarch
[ INFO ] DNF Unknown: selinux-policy-3.14.3-80.0.1.el8.noarch
[ INFO ] DNF Verify: selinux-policy-3.14.3-80.0.4.el8_5.2.noarch 1/8
[ INFO ] DNF Verify: selinux-policy-3.14.3-80.0.1.el8.noarch 2/8
[ INFO ] DNF Verify: selinux-policy-targeted-3.14.3-80.0.4.el8_5.2.noarch 3/8
[ INFO ] DNF Verify: selinux-policy-targeted-3.14.3-80.0.1.el8.noarch 4/8
[ INFO ] DNF Verify: ovirt-vmconsole-1.0.9-3.el8.noarch 5/8
[ INFO ] DNF Verify: ovirt-vmconsole-1.0.9-2.el8.noarch 6/8
[ INFO ] DNF Verify: ovirt-vmconsole-proxy-1.0.9-3.el8.noarch 7/8
[ INFO ] DNF Verify: ovirt-vmconsole-proxy-1.0.9-2.el8.noarch 8/8
[ INFO ] Stage: Misc configuration
[ INFO ] Upgrading CA
[ INFO ] Initializing PostgreSQL
[ INFO ] Creating PostgreSQL 'engine' database
[ INFO ] Configuring PostgreSQL
[ INFO ] Creating PostgreSQL 'ovirt_engine_history' database
[ INFO ] Configuring PostgreSQL
[ INFO ] Creating CA: /etc/pki/ovirt-engine/ca.pem
[ INFO ] Creating CA: /etc/pki/ovirt-engine/qemu-ca.pem
[ INFO ] Updating OVN SSL configuration
[ INFO ] Updating OVN timeout configuration
[ INFO ] Creating/refreshing DWH database schema
[ INFO ] Setting up ovirt-vmconsole proxy helper PKI artifacts
[ INFO ] Setting up ovirt-vmconsole SSH PKI artifacts
[ INFO ] Configuring WebSocket Proxy
[ INFO ] Creating/refreshing Engine database schema
[ INFO ] Creating a user for Grafana
[ INFO ] Creating/refreshing Engine 'internal' domain database schema
[ INFO ] Creating default mac pool range
[ INFO ] Adding default OVN provider to database
[ INFO ] Adding OVN provider secret to database
[ INFO ] Setting a password for internal user admin
[ INFO ] Install selinux module /usr/share/ovirt-engine/selinux/ansible-runner-service.cil
[ INFO ] Generating post install configuration file '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf'
[ INFO ] Stage: Transaction commit
[ INFO ] Stage: Closing up
[ INFO ] Starting engine service
[ INFO ] Starting dwh service
[ INFO ] Starting Grafana service
[ INFO ] Restarting ovirt-vmconsole proxy service

--== SUMMARY ==--

[ INFO ] Restarting httpd
Please use the user 'admin@internal' and password specified in order to login
Web access is enabled at:
http://kvm02.local.com:80/ovirt-engine
https://kvm02.local.com:443/ovirt-engine
Internal CA CF:C8:A2:E0:42:FE:5F:19:55:B3:E2:9F:A9:7F:4C:DC:49:8D:C7:CB
SSH fingerprint: SHA256:aRJ1E8zUzNaYsXG2tCfvV4EGTMxw/mMzrKQQt2ZFZKE
[WARNING] Less than 16384MB of memory is available
Web access for grafana is enabled at:
https://kvm02.local.com/ovirt-engine-grafana/
Please run the following command on the engine machine kvm02.local.com, for SSO to work:
systemctl restart ovirt-engine

--== END OF SUMMARY ==--

[ INFO ] Stage: Clean up
Log file is located at /var/log/ovirt-engine/setup/ovirt-engine-setup-20220725103208-vp6a4t.log
[ INFO ] Generating answer file '/var/lib/ovirt-engine/setup/answers/20220725103526-setup.conf'
[ INFO ] Stage: Pre-termination
[ INFO ] Stage: Termination
[ INFO ] Execution of setup completed successfully

Config firewall

firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

Access the URL

เมื่อเราทำการเข้าหน้า Console ของ OLVM ได้เเล้ว ให้ทำการกดเข้าไปที่ Monitoring Portal

เมื่อเราเข้ามาที่หน้า Grafana ให้เลือกไปที่ Dashboards > Manage

จะมีโฟลเดอร์ Dashboards ให้เราเลือกใช้งานมากมายเราสามารถเลือก Dashboards ตามความเหมาะสมตามการใช้งานของเราได้ อันนี้เป็นตัวอย่าง dashboards ครับ

https://github.com/michalgutowski/ovirt-grafana/blob/main/images/ovirt-cluster-dashboard.png

ในส่วนของการ Monitor นั้นเราสามารถเลือกช่วงเวลาที่เราต้องการจะดูได้ และข้อมูล Metric จะเก็บเพียง 30 วันย้อนหลังเมื่อครบ 30 วัน ตัว OLVM จะทำการลบข้อมูลออกเพื่อไม่ให้ข้อมูลกินพื้นที่ Storage ของเราจนมากเกินไป

สำหรับใครที่ใช้ ตัว OLVM ที่มี version ต่ำกว่า 4.2 ลงไปต้องทำการติดตั้งตัว Grafana เพิ่ม Database และ export Dashboards เอง ซึ่งผมจะแปะลิ้งก์ขั้นตอนการทำไว้ข้างล่างนี้ครับ https://blogs.oracle.com/scoter/post/build-grafana-dashboard-for-oracle-linux-virtualization-manager-43

ต่อไปเราจะมาทำการตั้งค่าฟังก์ชัน Alert กันนะครับ เพราะเมื่อเราตั้งค่าให้สามารถ Monitor VM ได้แล้ว แต่เวลาการใช้งานจริงเราไม่ได้มานั่งดูหน้าจอ Monitor ตลอดเวลาหากเกิดมีการใช้ CPU ที่สูงเกินไปในเวลาที่เราไม่ได้ Monitor อยู่ จึงทำให้เราไม่รู้เลย เราจึงควรตั้งค่าให้มัน Alert เมื่อมีการใช้งาน CPU ที่สูงเกินไปซึ่งในการส่งข้อความให้แจ้งเตือนนั้นมาให้เรารู้ซึ่งใน Feature alert นั้นเราสามารถเลือกให้รูปแบบการแจ้งเตือนได้หลายรูปแบบไม่ว่าจะเป็นแจ้งเตือนผ่าน Email , Line ,Microsoft team , Discord และ ฯลฯ เราไปดูวิธีการทำ Alert กันเลย

ให้เราเลือกไปที่หัวข้อ Alerting > Alert rules

เมื่อเราเข้าไปแล้วให้กดไปที่ New alert rule จากนั้นให้ทำการตั้งค่าตามนี้ โดยในช่อง Rule name ผมจะใส่เป็นชื่อ Alert node ช่อง Folder จะเป็นที่สำหรับจัดเก็บ alert rule ของเรา และอันสุดท้ายจะเป็น Group คือสิทธิ์ที่บุคคลในกลุ่มที่เราต้องการให้ผู้คนในกลุ่มนั้นได้รับ Alert นั้นด้วย

ในหัวข้อ Create a query to be alerted on ให้เราทำการ query ข้อมูลที่เราต้องการที่เราจะให้มัน Alert นะครับ ในที่นี้ผมเลือกเป็นค่าการใช้งานของ CPU ครับ เมื่อเราทำการ เลือกข้อมูลได้แล้ว ให้ไปตั้งค่าว่าเราจะเลือกข้อมูลเป็นค่าแบบยกตัวอย่างเช่นค่าสุดท้ายที่รับได้ หรือ จะเป็นค่าที่มากที่สุด ซึ่งเราสามารถตั้งตามนี้ได้เลย ถ้าเราอยากให้มัน alert เมื่อไรให้ไปตั้งค่าที่ Expression ถ้าขึ้น 1 คือมันจะทำการ alert แต่ถ้าขึ้น 0 คือจะไม่ alert

ตัวอย่างที่ผมได้ตั้งเอาไว้ผมจะให้มันแจ้งเตือนก็ตอนเมื่อมีอัตราการใช้งาน CPU ที่มากกว่า 0.04 ซึ่งค่าที่ใช้งาน ณ ปัจจุบันตอนนี้ จับได้ที่ 0.0403 ซึ่งมากกว่าที่ตั้งไว้จึงทำให้ return ค่า กลับมาเป็น 1

หัวข้อต่อไปจะเป็นการตั้งค่าเวลาสำหรับการตรวจจับ alert และ ตั้งค่า details alert ของเรา ซึ่ง details alert เราสามารถออกแบบข้อความเองได้ว่าจะให้การแจ้งเตือนของเรานั้นแจ้งเตือนเราว่ายังไง

เมื่อเราทำการตั้งค่าเสร็จหมดแล้วให้กด save + exit เราก็จะได้ alert rule ของเรา
เเล้วนั้นเองซึ่งตอนตั้งค่าผมตั้งให้มันมีค่าที่ทำให้แจ้งเตือนไว้ก่อนเพื่อทดสอบการทำงานตามรูปเลยครับ

Alert rule ที่เราสร้างขึ้นซึ่งมันจะเริ่มทำงานในการตรวจจับการใช้งาน CPU ตั้งแต่เราสร้าง Alert rule เสร็จ

เราไปดูวิธีให้ Feature alert แจ้ง ผ่าน email กัน อันดับแรกให้เราเข้าที่ Alert > Notification policies เพื่อตรวจสอบว่า Root policy-default for all alerts ว่าตอนนี้มี policy เป็นยังไงบ้าง

จากนั้นให้เลือกไปที่หัวข้อ Contact point เพื่อทำการตั้งค่าว่าจะให้ส่งไปไหนรูปแบบไหนส่งไปหาใคร ใครจะเป็นผู้ได้รับ email นี้บ้าง รวมถึงยังตั้งค่ารูปแบบการแจ้งเตือนได้อีกด้วย

เพียงแค่นี้เราก็จะได้รับการแจ้งเตือนผ่าน email แล้ว เป็นยังไงกันบ้างครับเพื่อน ๆง่ายสุด ๆ ไปเลยใช่มั้ย เพื่อนๆสามารถลองไปทำตามกันได้นะครับ

ท้ายที่สุดนี้หวังว่า Blog ของผมจะเป็นประโยชน์สำหรับผู้ที่กำลังอ่านอยู่หรือผู้ที่สนใจครับถ้ามีเนื้อหาอะไรที่ตกหล่นหรือผิดพลาดประการใดต้องขออภัยด้วยครับ

ยังไม่หมด ตอนนี้ทางบริษัท Sirisoft ยังเปิดรับสมาชิกเพิ่มอยู่นะครับเพื่อนๆคนในสนใจก็ติดต่อมาได้ที่ https://lin.ee/ms8vit4 เลยครับ

👉🏻ติดตามข่าวสารอื่นๆของบริษัทได้ที่ช่องทางด้านล่างนี้เลยครับผม

Instagram: Sirisoft_official

Tiktok: https://www.tiktok.com/@sirisoft

Youtube: https://www.youtube.com/@sirisoftofficial1698

FB: https://www.facebook.com/sirisoft/

Website: https://www.sirisoft.co.th/

--

--