Prometheus Grafana Monitoring Setup คู่มือสมบูรณ์ 2026

Prometheus Grafana Monitoring Setup คู่มือสมบูรณ์ 2026 | SiamCafe Blog
prometheus grafana monitoring setup llm
--- ### วิดีโอแนะนำ: Prometheus Grafana Monitoring Setup คู่มือสมบูรณ์ 2026 **ช่อง YouTube แนะนำ:** - [▶ iCafeFX — Forex & Trading](https://www.youtube.com/@icafefx?sub_confirmation=1) - [▶ SiamCafe — IT & Server](https://www.youtube.com/@siamcafe?sub_confirmation=1) ---

Prometheus + Grafana คืออะไร — ทำไมต้องใช้คู่กัน?

Prometheus คือระบบ monitoring แบบ open-source ที่ออกแบบมาสำหรับเก็บ time-series metrics จาก server, container, application ต่างๆ โดยใช้วิธี pull-based คือ Prometheus จะไปดึงข้อมูลจาก target เป็นระยะๆ ผ่าน HTTP endpoint

Grafana คือ visualization platform ที่แสดงข้อมูลจาก Prometheus เป็น dashboard สวยงาม มี graph, alert, และ annotation ทำให้เห็นสถานะระบบแบบ real-time

ทั้งคู่ใช้ร่วมกันเป็น monitoring stack มาตรฐาน ของวงการ DevOps ในปี 2026 แทบทุกบริษัทที่ใช้ Kubernetes หรือ microservices จะใช้ Prometheus + Grafana

สถาปัตยกรรม Prometheus + Grafana Stack

ระบบ monitoring ที่สมบูรณ์ประกอบด้วย:

ติดตั้ง Prometheus + Grafana บน Ubuntu 22.04

Step 1: ติดตั้ง Prometheus

# ดาวน์โหลด Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.50.0/prometheus-2.50.0.linux-amd64.tar.gz
tar xvf prometheus-2.50.0.linux-amd64.tar.gz
sudo mv prometheus-2.50.0.linux-amd64 /opt/prometheus

# สร้าง systemd service
sudo tee /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Monitoring
After=network.target
[Service]
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.retention.time=30d
Restart=always
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus

Step 2: ตั้งค่า prometheus.yml

# /opt/prometheus/prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'node'
    static_configs:
      - targets: ['server1:9100', 'server2:9100']
  - job_name: 'nginx'
    static_configs:
      - targets: ['web1:9113']

Step 3: ติดตั้ง Grafana

sudo apt install -y apt-transport-https software-properties-common
wget -q -O - https://apt.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install grafana -y
sudo systemctl enable --now grafana-server
# เข้า http://server-ip:3000 (admin/admin)

Dashboard สำคัญที่ต้องมี

DashboardGrafana IDใช้ดูอะไร
Node Exporter Full1860CPU, RAM, Disk, Network ของทุก server
Docker Container893Container resource usage
Nginx12708Request rate, error rate, latency
MySQL7362Queries, connections, InnoDB metrics
PostgreSQL9628Query performance, connections, locks
Redis11835Memory, hit rate, connected clients

Alerting Rules ที่ Production ต้องมี

# /opt/prometheus/alert.rules.yml
groups:
- name: server-alerts
  rules:
  - alert: HighCPU
    expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
    for: 5m
    labels: { severity: warning }
    annotations:
      summary: "CPU สูงเกิน 80% บน {{ $labels.instance }}"
  - alert: DiskAlmostFull
    expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 < 15
    for: 10m
    labels: { severity: critical }
    annotations:
      summary: "Disk เหลือน้อยกว่า 15% บน {{ $labels.instance }}"
  - alert: InstanceDown
    expr: up == 0
    for: 2m
    labels: { severity: critical }
    annotations:
      summary: "{{ $labels.instance }} ไม่ตอบสนองมากกว่า 2 นาที"

FAQ — คำถามที่พบบ่อย

Q: Prometheus เก็บข้อมูลได้นานแค่ไหน?

Default คือ 15 วัน แต่ตั้งได้ผ่าน --storage.tsdb.retention.time=30d สำหรับ long-term storage แนะนำใช้ Thanos หรือ VictoriaMetrics ที่เก็บข้อมูลบน S3 ได้หลายปี

Q: Prometheus vs Zabbix vs Datadog เลือกตัวไหนดี?

Prometheus เหมาะกับ cloud-native และ Kubernetes ecosystem ฟรี แต่ต้องดูแลเอง Zabbix เหมาะกับ traditional infrastructure มี agent-based monitoring Datadog เป็น SaaS ไม่ต้องดูแลแต่แพงมาก สำหรับ DevOps ในปี 2026 Prometheus คือ standard

Q: Grafana ใช้ฟรีจริงไหม?

Grafana OSS (open-source) ใช้ฟรีตลอด ไม่มีข้อจำกัด ใช้ได้ทั้ง commercial และ personal Grafana Cloud มี free tier ให้ 10,000 metrics 50GB logs ต่อเดือน เพียงพอสำหรับทีมเล็ก

Prometheus PromQL — ภาษาสำหรับ Query Metrics

PromQL เป็นภาษาเฉพาะของ Prometheus สำหรับ query ข้อมูล metrics เป็นทักษะสำคัญที่ DevOps Engineer ต้องเรียนรู้ ตัวอย่าง PromQL ที่ใช้บ่อยในงานจริง:

การ Scale Prometheus สำหรับระบบขนาดใหญ่

Prometheus ตัวเดียวรองรับได้ประมาณ 1 ล้าน time series ถ้ามีมากกว่านี้ต้อง scale โดยมี 2 วิธีหลัก วิธีแรกคือ Federation คือใช้ Prometheus หลายตัว แต่ละตัวดูแล cluster หรือ service กลุ่มหนึ่ง แล้วมี global Prometheus มา scrape จากตัวลูกอีกที วิธีที่สองคือใช้ Thanos หรือ Cortex หรือ VictoriaMetrics ซึ่งเป็น long-term storage ที่เก็บข้อมูลบน object storage เช่น S3 ได้หลายปีโดยไม่ต้องเพิ่ม disk บน Prometheus server

สำหรับองค์กรที่เพิ่งเริ่มต้นและมี server น้อยกว่า 50 เครื่อง Prometheus ตัวเดียวก็เพียงพอ ไม่ต้อง over-engineer ด้วย Thanos ตั้งแต่แรก เริ่มจาก Prometheus ตัวเดียวกับ Grafana แล้วค่อยขยายเมื่อจำเป็น

Grafana Dashboard Best Practices

การสร้าง Grafana Dashboard ที่ดีสำหรับ production ควรปฏิบัติตามหลักการเหล่านี้:

  1. แบ่ง Dashboard ตาม Layer — สร้าง dashboard แยกสำหรับ Infrastructure Overview Service Level และ Business Metrics อย่ารวมทุกอย่างใน dashboard เดียว
  2. ใช้ Variables — ทำ dropdown ให้เลือก server instance หรือ service ไม่ต้องสร้าง dashboard ซ้ำสำหรับทุก server
  3. ตั้ง Alert Thresholds — ใช้สี เขียว เหลือง แดง แสดงสถานะ ดูแล้วเข้าใจทันทีว่าอะไรเป็นปัญหา
  4. เพิ่ม Annotations — mark deployment events บน graph เพื่อ correlate กับ performance changes
  5. ใช้ Dashboard as Code — เก็บ dashboard JSON ใน Git ใช้ Grafana provisioning ให้ restore ได้เมื่อ Grafana ตาย

Monitoring สำหรับองค์กรไทยในปี 2026

องค์กรไทยหลายแห่งยังใช้วิธี monitoring แบบดั้งเดิม เช่น SSH เข้าไปดู htop หรือรอให้ลูกค้าแจ้งว่าระบบ down การลงทุนสร้างระบบ monitoring ด้วย Prometheus และ Grafana ช่วยลดเวลา downtime ได้อย่างมาก หลายองค์กรรายงานว่า MTTR ลดลงจากหลายชั่วโมงเหลือไม่กี่นาที เพราะสามารถตรวจพบปัญหาและ alert ทีม IT ได้ทันที ก่อนที่ user จะรู้สึกถึงปัญหา

ค่าใช้จ่ายในการ setup Prometheus Grafana stack คือศูนย์บาทสำหรับ software เพราะเป็น open-source ทั้งหมด ลงทุนแค่ server สำหรับรัน Prometheus ใช้ VM ขนาดเล็ก RAM 4 GB ก็เพียงพอสำหรับ monitor server 20 ถึง 30 เครื่อง เทียบกับ Datadog ที่เริ่มต้นที่ 15 เหรียญต่อ host ต่อเดือน ถ้ามี 50 hosts ก็ประมาณ 750 เหรียญต่อเดือนหรือกว่า 25,000 บาท Prometheus จึงเป็นทางเลือกที่คุ้มค่าที่สุดสำหรับองค์กรที่มีทีม DevOps ดูแลเอง

📖 บทความที่เกี่ยวข้อง

LLM Fineอ่านบทความ → LLM Fineอ่านบทความ → LLM Fineอ่านบทความ → LLM Fineอ่านบทความ → LLM Fineอ่านบทความ →

สำหรับผู้ที่สนใจเรียนรู้เพิ่มเติม แนะนำให้ศึกษา Prometheus documentation อย่างเป็นทางการ และลองทำ hands-on lab ด้วยตัวเองบน Docker Compose จะช่วยให้เข้าใจการทำงานของ Prometheus และ Grafana ได้อย่างลึกซึ้ง

แนะนำโดยผู้เชี่ยวชาญ

Siam2Richอุปกรณ์ IT

เรียนรู้ IT, Cloud, AI, DevOps จากประสบการณ์จริง 30 ปี

▶ YouTube @icafefx

📰 บทความล่าสุด

PostgreSQL Performance Tuning Production คู่มือสมบูรณ์ 2026 thai esg — คู่มือ สมบูรณ์ 2026 | SiamCafe.net GitHub Actions CI CD Pipeline คู่มือสมบูรณ์ 2026 ดัชนี nasdaq 100 — คู่มือ สมบูรณ์ 2026 | SiamCafe.net Linux Command Line 50 คำสั่งที่ต้องรู้ คู่มือสมบูรณ์ 2026 WireGuard VPN Setup Production คู่มือสมบูรณ์ 2026

บทความแนะนำจากเครือข่าย SiamCafe

👨‍💻

อ.บอม (กิตติทัศน์ เจริญพนาสิทธิ์) ผู้ก่อตั้ง SiamCafe.net ตั้งแต่ปี 1997 ผู้เชี่

ยวชาญด้าน IT Infrastructure กว่า 30 ปี ผู้พัฒนา SquidNT Proxy (Thaiware Award 2005) ที่ปรึกษาด้าน Network และ Server ให้องค์กรทั่วประเทศ

โดยสรุป Prometheus และ Grafana เป็น monitoring stack ที่ดีที่สุดสำหรับ DevOps ในปี 2026 ฟรี ทรงพลัง และเป็นมาตรฐานของอุตสาหกรรม การลงทุนเวลาเรียนรู้ PromQL และการสร้าง Grafana dashboard จะช่วยให้คุณตรวจพบปัญหาได้เร็วขึ้น ลด downtime และเพิ่มความน่าเชื่อถือของระบบ เริ่มต้นวันนี้ด้วยการติดตั้ง Prometheus บน VM ตัวเดียว เพิ่ม Node Exporter บน server ที่ต้องการ monitor แล้วสร้าง Grafana dashboard แรกของคุณ ภายใน 1 ชั่วโมงคุณจะมี monitoring system ที่ทำงานได้จริง

บทความแนะนำ

สำหรับผู้ที่สนใจต่อยอดทักษะ IT สู่การลงทุนออนไลน์ iCafeForex.comระบบ EA Trading อัตโนมัติ ที่ช่วยให้เริ่มต้นเทรดได้อย่างมีระบบ

ลองใช้ เพื่อประกอบการตัดสินใจลงทุน พร้อมวิเคราะห์ตลาดแบบเรียลไทม์

iCafeForex Network: XM Signal | iCafeForex | SiamLanCard | Siam2R