> For the complete documentation index, see [llms.txt](https://docs-epc.gitbook.io/ncs-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-epc.gitbook.io/ncs-documents/database-as-a-service/sql-database/monitor-sql-database-with-percona-monitoring-and-management-pmm.md).

# Monitor SQL Database with Percona Monitoring and Management (PMM)

## Prerequisite

* มี Database Instance ใน Project ([ขั้นตอนการสร้าง SQL Database Instance](/ncs-documents/database-as-a-service/sql-database/create-sql-database-instance.md))
* Database Instance จะต้องมี Monitoring User เพื่อใช้เชื่อมต่อ PMM ([ขั้นตอนการสร้าง Monitoring User](/ncs-documents/database-as-a-service/sql-database/manage-monitoring-user/create-monitoring-user.md))

## Instructions

### 1. สร้าง Compute Instance สำหรับการใช้งาน PMM บน NIPA Clouc Space

ปัจจุบัน NCS ให้บริการ Deployment Script เพื่อให้ง่ายต่อการติดตั้ง PMM หลังสั่งสร้างสำเร็จ จะสามารถเข้าใช้งาน Percona Monitoring and Management (PMM) ผ่าน External IP ได้ทันที โดยมีขั้นตอนการสร้าง ดังนี้

### 1.1 เข้าสู่หน้า Compute Instances

เลือกรายการ “Compute Instances” ที่ Sidebar จากเมนู Compute

<figure><img src="/files/dgIIFzMhA62mjYVbhV5W" alt=""><figcaption><p>เข้าหน้า Compute Instance</p></figcaption></figure>

### 1.2 เข้าสู่หน้า Launch Compute Instance

กดปุ่ม + “Compute Instance(s)” ที่มุมขวาบนของหน้าเพื่อทำการ Launch Compute Instance

<figure><img src="/files/zvbyJmiJ21yk6i0YA0VU" alt=""><figcaption><p>กดปุ่ม + “Compute Instance(s)” </p></figcaption></figure>

### 1.3 เลือก Source เป็น Deployment Script ของ Percona Monitoring and Management (PMM)

ตั้งค่าข้อมูลเริ่มต้นต่าง ๆ ของ Compute Instance โดยเมื่อถึงขั้นตอนการเลือก Source ให้เลือกเป็น Deployment Script ของ Percona Monitoring and Management (PMM)&#x20;

<figure><img src="/files/5Ma1uqKWzGVwhcoQFWTN" alt=""><figcaption><p>เลือก Source เป็น Deployment Script ของ Percona Monitoring and Management (PMM)</p></figcaption></figure>

### 1.4 สามารถเปลี่ยนแปลงค่าเริ่มต้นของ Username และ Password สำหรับเข้าใช้งาน PMM

ใน step ถัดมา สามารถตั้งค่าเริ่มต้นของ Username และ Password สำหรับเข้าใช้งาน PMM ได้ตามต้องการ โดยการจัดการ User สามารถทำได้ผ่าน PMM หลังการเข้าถึงครั้งแรก

<figure><img src="/files/Bbr7WnSurukv5SyiZdOk" alt=""><figcaption><p>กำหนด Username และ Password ของ PMM</p></figcaption></figure>

### 1.5 กรอกข้อมูลการ Launch Compute Instance ให้ครบถ้วน แล้วกด Launch เพื่อสั่งสร้าง

จะต้องตั้งค่า Security Group ให้สามารถเข้าใช้งาน HTTPS ได้ เพื่อให้สามารถใช้งานได้ผ่าน Web Browser

<figure><img src="/files/GQolqh0voLsw93MDKOdw" alt=""><figcaption><p>เพิ่ม Default Security Group ที่เป็น HTTPS</p></figcaption></figure>

{% hint style="info" %}
สามารถศึกษาขั้นตอนการ [Launch Compute Instance](/ncs-documents/compute/compute-instance/launch-compute-instance.md) โดยละเอียด เพื่อกรอกข้อมูลได้อย่างถูกต้อง
{% endhint %}

เมื่อกรอกข้อมูลครบถ้วนและตรวจสอบความถูกต้องอีกครั้ง จากนั้นกดปุ่ม LAUNCH เพื่อสั่งสร้าง

<figure><img src="/files/u4SvTiqd64vxfrUpRMcT" alt=""><figcaption><p>กดปุ่ม LAUNCH</p></figcaption></figure>

### 1.6 PMM จะสามารถใช้งานได้ หลังจากคำสั่งสำเร็จ

รอให้  OS status เป็น HEALTHY และ Instance status เป็น active จึงสามารถเข้าถึง PMM ผ่าน Web Browser ได้

<figure><img src="/files/DfpFoMJ47Qckmgc6TuV3" alt=""><figcaption><p>OS status เป็น HEALTHY และ Instance status เป็น active</p></figcaption></figure>

{% hint style="info" %}
แม้ว่า OS Status ของ Compute Instance เป็น HEALTHY แล้ว ก็อาจจะใช้เวลาอีกซักพักหนึ่ง ระหว่างที่ Deployment Script สำหรับติดตั้ง PMM ทำงาน
{% endhint %}

### 2. เข้า PMM เพื่อเชื่อมต่อ Database Instance โดยใช้ Monitoring User ที่สร้างไว้

เข้า PMM ผ่าน Web Browser โดยกรอก https\://\[ External IP ของ Compute Instance ที่ได้จากขั้นตอนที่ 1.6 ]

### 2.1 Log in เข้า PMM&#x20;

กรอก Username และ Password ที่ได้กำหนดจากขั้นตอนที่ 1.4

<figure><img src="/files/DysKUSns4cB7O5Ec3sFu" alt=""><figcaption><p>กรอก Username และ Password</p></figcaption></figure>

### 2.2 เข้าหน้า Add Service และเลือก MySQL

เลือก “Add Service” ภายใต้เมนู PMM Configuration ที่ Sidebar เพื่อเชื่อมต่อ Database กับ PMM

<figure><img src="/files/hmtJa7dbT4QnuyU7IvBx" alt=""><figcaption><p>เลือก “Add Service”</p></figcaption></figure>

เลือก MySQL สำหรับ Database ที่ใช้งานบน NCS

<figure><img src="/files/25rYMzknPZYcVtUdlYgI" alt=""><figcaption><p>เลือก MySQL </p></figcaption></figure>

### 2.3 กำหนดชื่อของ Service

กำหนดชื่อของ Service โดยแนะนำให้ใช้ชื่อเดียวกับ Database Instance บน NCS เพื่อให้ง่ายต่อการใช้งาน

<figure><img src="/files/YZk8SnT1QQbMrWmExGH3" alt=""><figcaption><p>กำหนดชื่อของ Service</p></figcaption></figure>

### 2.4 กรอก Hostname โดยใช้ External IP ของ Database Instance

กรอก Hostname ของ Database ซึ่งเป็นเลข External IP ของ Database Instance โดยดูได้จาก หน้า Database Instances และ Database Instance Detail

<figure><img src="/files/aOWYYaBAQln7R0Q2YhD2" alt=""><figcaption><p>กรอก Hostname</p></figcaption></figure>

<figure><img src="/files/G0iE3abOnkWeI0ge9rV6" alt=""><figcaption><p>External IP ของ Database Instance ที่หน้า Database Instances</p></figcaption></figure>

<figure><img src="/files/Ql9mmt3lVRpyek2bz3ah" alt=""><figcaption><p>External IP ของ Database Instance ที่หน้า Database Instance Detail</p></figcaption></figure>

### 2.5 กรอก Username และ Password ของ Monitoring User

กรอก Username และ Password ของ Monitoring User ที่จะเชื่อมต่อ โดย host ที่เชื่อมต่อ ต้องมีเงื่อนไขตรงตามขอบเขตการเข้าถึงของ Database นั้น ๆ ที่กำหนดไว้

<figure><img src="/files/xhvXGTcBXWeHI3T3znFu" alt=""><figcaption><p>กรอก Username และ Password ของ Monitoring User </p></figcaption></figure>

ระบบแสดงเฉพาะ Username ของ Monitoring User ที่หน้า Database Detail

<figure><img src="/files/KqVF7LbKMhUZouP9szQG" alt=""><figcaption><p>ระบบแสดง Username ของ Monitoring User</p></figcaption></figure>

### 2.6 กรอกข้อมูลอื่น ๆ ให้ครบถ้วน และตรวจสอบอีกครั้ง

กำหนด Labels, Additional options และ Table statistic limit ตามการใช้งาน แล้วตรวจสอบความถูกต้อง

<figure><img src="/files/EldKjw6BVgbAK8twtfpg" alt=""><figcaption><p>กำหนด Labels, Additional options และ Table statistic limit ตามการใช้งาน </p></figcaption></figure>

### 2.7 กดปุ่ม "Add service"&#x20;

กดปุ่ม "Add service" หากไม่พบ error บน PMM แสดงว่าคำสั่งสำเร็จ

<figure><img src="/files/Plkml9P8UfnOZb5wDFxU" alt=""><figcaption><p>กดปุ่ม Add service</p></figcaption></figure>

### 2.8 สามารถเริ่มใช้งาน PMM หลังคำสั่งสำเร็จ

ที่ Sidebar จะแสดงรายการ "MySQL" และสามารถเข้าไปเพื่อเรื่มใช้งาน

<figure><img src="/files/7yNpiroytnGWGh9HQ697" alt=""><figcaption><p>สามารถเริ่มใช้งาน Dashboard ของ PMM สำหรับ MySQL</p></figcaption></figure>
