WooCommerce Observability
WordPress WooCommerce Observability Monitoring Logging Performance Alerting Core Web Vitals Revenue Order Checkout
| Layer | What to Monitor | Tool | Alert |
|---|---|---|---|
| Uptime | HTTP Status, Response Time | UptimeRobot / BetterUptime | Down → Immediate |
| Performance | TTFB, LCP, FID, CLS | PageSpeed / New Relic | LCP > 2.5s → Warning |
| Server | CPU, RAM, Disk, PHP-FPM | Grafana + node_exporter | CPU > 80% → Warning |
| Database | Slow Query, Connections | Query Monitor / PMM | Slow Query > 1s → Warning |
| WooCommerce | Orders, Revenue, Cart | WC Analytics / Custom | Order drop > 50% → Critical |
| Security | Login Attempt, File Change | Wordfence / WP Activity Log | Brute Force → Block + Alert |
Monitoring Setup
# === WooCommerce Monitoring with WP-CLI & Custom Script ===
# WP-CLI Commands for monitoring
# wp plugin list --status=active --format=json # Active plugins
# wp plugin list --update=available --format=json # Plugins need update
# wp core version # WordPress version
# wp core check-update # Check WP update
# wp wc order list --status=processing --format=json # Pending orders
# wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type='product' AND post_status='publish'"
# wp db query "SHOW FULL PROCESSLIST" # Active DB connections
# wp cron event list # Scheduled cron events
# PHP-FPM Status monitoring
# curl http://localhost/status?json
# {
# "pool": "www",
# "accepted conn": 12345,
# "active processes": 5,
# "idle processes": 15,
# "max active processes": 20,
# "slow requests": 3
# }
from dataclasses import dataclass
@dataclass
class MonitorCheck:
check: str
command: str
threshold: str
frequency: str
alert: str
checks = [
MonitorCheck("Site Uptime",
"curl -o /dev/null -s -w '%{http_code}' https://shop.example.com",
"HTTP 200 = OK, อื่น = Down",
"ทุก 1 นาที",
"Down → SMS + Slack ทันที"),
MonitorCheck("Page Load Time",
"curl -o /dev/null -s -w '%{time_total}' https://shop.example.com",
"< 2s = Good, > 3s = Slow, > 5s = Critical",
"ทุก 5 นาที",
"> 3s → Warning, > 5s → Critical"),
MonitorCheck("PHP-FPM Active",
"curl http://localhost/status?json | jq .active_processes",
"< 80% of max = Good",
"ทุก 1 นาที",
"> 90% max → Scale up / Optimize"),
MonitorCheck("MySQL Slow Queries",
"wp db query 'SHOW GLOBAL STATUS LIKE \"Slow_queries\"'",
"< 10/hour = Good",
"ทุก 15 นาที",
"> 50/hour → Optimize Queries"),
MonitorCheck("WooCommerce Orders",
"wp wc order list --after=today --format=count",
"Compare with yesterday same time",
"ทุกชั่วโมง",
"Drop > 50% → Investigate"),
MonitorCheck("Disk Usage",
"df -h /var/www | awk 'NR==2{print $5}'",
"< 80% = Good",
"ทุก 15 นาที",
"> 85% → Warning, > 95% → Critical"),
]
print("=== Monitor Checks ===")
for c in checks:
print(f" [{c.check}] Freq: {c.frequency}")
print(f" Command: {c.command}")
print(f" Threshold: {c.threshold}")
print(f" Alert: {c.alert}")
Performance Optimization
# === WooCommerce Performance Stack ===
@dataclass
class OptimizeLayer:
layer: str
tool: str
config: str
impact: str
optimizations = [
OptimizeLayer("Page Cache",
"LiteSpeed Cache / WP Super Cache / WP Rocket",
"Cache HTML Pages, Exclude Cart/Checkout/My-Account",
"Load Time ลด 50-80%"),
OptimizeLayer("Object Cache",
"Redis (recommended) / Memcached",
"wp-config.php: WP_REDIS_HOST, WP_REDIS_PORT",
"Database Query ลด 40-60%"),
OptimizeLayer("CDN",
"Cloudflare (Free) / Bunny CDN / KeyCDN",
"DNS Proxy, Static Assets Cache, Image Polish",
"Global Load Time ลด 30-50%"),
OptimizeLayer("Image Optimization",
"ShortPixel / Imagify / EWWW",
"WebP Format, Lazy Loading, Resize to Max Width",
"Page Size ลด 30-60%"),
OptimizeLayer("Database Optimization",
"WP-Optimize / Advanced Database Cleaner",
"ลบ Revision Transient Spam, Optimize Tables",
"Query Speed เพิ่ม 20-40%"),
OptimizeLayer("PHP Upgrade",
"PHP 8.2+ (จาก PHP 7.4)",
"php.ini: opcache.enable=1, memory_limit=256M",
"PHP Speed เพิ่ม 30-50%"),
OptimizeLayer("HTTP/2 + Brotli",
"Nginx / LiteSpeed Web Server",
"http2 on, brotli on, brotli_comp_level 6",
"Transfer Size ลด 20-30%"),
]
print("=== Performance Stack ===")
for o in optimizations:
print(f" [{o.layer}] Tool: {o.tool}")
print(f" Config: {o.config}")
print(f" Impact: {o.impact}")
Dashboard & Alerting
# === Observability Dashboard ===
@dataclass
class DashPanel:
panel: str
metrics: str
source: str
alert_rule: str
panels = [
DashPanel("Revenue Real-time",
"Orders/hour, Revenue/hour, AOV, Conversion Rate",
"WooCommerce Analytics API / Custom Query",
"Revenue drop > 50% vs yesterday → Critical"),
DashPanel("Site Health",
"Uptime %, Response Time p50 p95 p99, Error Rate",
"UptimeRobot API / Synthetic Monitoring",
"Uptime < 99.9% → Warning"),
DashPanel("Server Resources",
"CPU, RAM, Disk, Network, PHP-FPM Pool",
"Prometheus node_exporter + php-fpm_exporter",
"CPU > 80% for 5min → Warning"),
DashPanel("Core Web Vitals",
"LCP, FID, CLS, TTFB per page",
"Chrome UX Report / PageSpeed API",
"LCP > 2.5s → Optimization needed"),
DashPanel("Security Events",
"Login Attempts, File Changes, Blocked IPs",
"Wordfence API / WP Activity Log",
"Brute Force > 100/hr → Block IP Range"),
DashPanel("Plugin Status",
"Active/Inactive, Updates Available, Conflicts",
"WP-CLI scheduled scan",
"Security Update Available → Urgent"),
]
print("=== Dashboard ===")
for p in panels:
print(f" [{p.panel}] Metrics: {p.metrics}")
print(f" Source: {p.source}")
print(f" Alert: {p.alert_rule}")
เคล็ดลับ
- Cache: ใช้ Page Cache + Object Cache + CDN ครบ 3 ชั้น
- Query Monitor: ติดตั้ง Query Monitor Plugin ดู Slow Query ใน Development
- Uptime: ตั้ง Uptime Monitor ตรวจทุกนาที แจ้ง SMS ทันที
- Revenue: Monitor Revenue ทุกชั่วโมง ถ้าลดฮวบ อาจมี Bug
- Update: อัพเดท WordPress Plugin PHP สม่ำเสมอ
WooCommerce Observability คืออะไร
Metrics Performance Logs PHP Error Traces Checkout Payment Alerts Site Down Slow New Relic Grafana Query Monitor WP Activity Log
ต้อง Monitor อะไรบ้าง
TTFB LCP FID CLS CPU RAM PHP-FPM Slow Query Orders Revenue Cart Abandonment Checkout Conversion Uptime HTTP Status Plugin Security
ตั้งค่าอย่างไร
Query Monitor WooCommerce Logs WP Activity Log UptimeRobot PageSpeed New Relic Grafana Prometheus WP-CLI Cron Google Analytics
แก้ปัญหา Performance อย่างไร
Cache Plugin CDN Cloudflare Image WebP Minimize CSS JS Database Optimize ลด Plugin PHP 8.2+ MySQL 8.0 Redis Object Cache HTTP/2 Brotli
สรุป
WordPress WooCommerce Observability Monitoring Performance Cache CDN Redis Core Web Vitals Revenue Order Uptime Alert Dashboard Production
