Uptime Kuma Monitoring
Uptime Kuma Open Source Monitoring ตรวจสอบ Uptime เว็บไซต์ Services HTTP TCP Ping DNS Docker gRPC Dashboard แจ้งเตือน Telegram Discord Slack Email Self-hosted
High Availability HA Monitoring ทำงานตลอด 24/7 Instance ล่ม Instance อื่นแทน ตรวจสอบต่อเนื่อง แจ้งเตือนไม่ขาด Production Environment
Uptime Kuma Setup
# === Uptime Kuma Docker Setup ===
# 1. Basic Docker Run
# docker run -d \
# --name uptime-kuma \
# --restart always \
# -p 3001:3001 \
# -v uptime-kuma:/app/data \
# louislam/uptime-kuma:1
# 2. Docker Compose (Production)
# version: "3.8"
# services:
# uptime-kuma:
# image: louislam/uptime-kuma:1
# container_name: uptime-kuma
# restart: always
# ports:
# - "3001:3001"
# volumes:
# - ./data:/app/data
# - /var/run/docker.sock:/var/run/docker.sock:ro
# environment:
# - UPTIME_KUMA_DB_TYPE=sqlite
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:3001/"]
# interval: 30s
# timeout: 10s
# retries: 3
# 3. Kubernetes Deployment
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: uptime-kuma
# spec:
# replicas: 1
# selector:
# matchLabels:
# app: uptime-kuma
# template:
# spec:
# containers:
# - name: uptime-kuma
# image: louislam/uptime-kuma:1
# ports:
# - containerPort: 3001
# volumeMounts:
# - name: data
# mountPath: /app/data
# resources:
# requests:
# memory: 256Mi
# cpu: 100m
# limits:
# memory: 512Mi
# cpu: 500m
# readinessProbe:
# httpGet:
# path: /
# port: 3001
# initialDelaySeconds: 10
# volumes:
# - name: data
# persistentVolumeClaim:
# claimName: uptime-kuma-pvc
# 4. Nginx Reverse Proxy
# server {
# listen 443 ssl http2;
# server_name status.example.com;
# ssl_certificate /etc/ssl/cert.pem;
# ssl_certificate_key /etc/ssl/key.pem;
# location / {
# proxy_pass http://localhost:3001;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# }
# }
from dataclasses import dataclass, field
from typing import List, Dict
@dataclass
class Monitor:
name: str
monitor_type: str
target: str
interval: int # seconds
expected_status: int = 200
timeout: int = 10
class UptimeKumaConfig:
"""Uptime Kuma Configuration"""
def __init__(self):
self.monitors: List[Monitor] = []
def add_monitor(self, monitor: Monitor):
self.monitors.append(monitor)
def show(self):
print(f"\n{'='*55}")
print(f"Uptime Kuma Monitors")
print(f"{'='*55}")
for m in self.monitors:
print(f"\n [{m.monitor_type}] {m.name}")
print(f" Target: {m.target}")
print(f" Interval: {m.interval}s | Timeout: {m.timeout}s")
config = UptimeKumaConfig()
monitors = [
Monitor("Website", "HTTP", "https://example.com", 60, 200),
Monitor("API Health", "HTTP", "https://api.example.com/health", 30, 200),
Monitor("Database", "TCP", "db.example.com:5432", 60),
Monitor("Redis", "TCP", "redis.example.com:6379", 30),
Monitor("DNS", "DNS", "example.com", 300),
Monitor("Ping Server", "Ping", "10.0.0.1", 60),
Monitor("Docker Nginx", "Docker", "nginx-container", 60),
Monitor("gRPC Service", "gRPC", "grpc.example.com:50051", 30),
]
for m in monitors:
config.add_monitor(m)
config.show()
# Supported Protocols
protocols = {
"HTTP/HTTPS": "ตรวจ Status Code, Response Time, SSL Expiry",
"TCP": "ตรวจ Port เปิด/ปิด",
"Ping (ICMP)": "ตรวจ Server ตอบสนอง",
"DNS": "ตรวจ DNS Resolution",
"Docker": "ตรวจ Container Status",
"gRPC": "ตรวจ gRPC Health Check",
"MQTT": "ตรวจ MQTT Broker",
"Keyword": "ตรวจ Keyword ใน Response Body",
"Push": "รับ Heartbeat จาก Application",
}
print(f"\n\nSupported Protocols:")
for proto, desc in protocols.items():
print(f" {proto}: {desc}")
HA Architecture
# ha_setup.py — Uptime Kuma High Availability
from dataclasses import dataclass
from typing import List
@dataclass
class HAInstance:
name: str
location: str
monitors: List[str]
status: str
class HAArchitecture:
"""Uptime Kuma HA Architecture"""
def __init__(self):
self.instances: List[HAInstance] = []
def add_instance(self, instance: HAInstance):
self.instances.append(instance)
def show(self):
print(f"\n{'='*55}")
print(f"Uptime Kuma HA Architecture")
print(f"{'='*55}")
for inst in self.instances:
print(f"\n [{inst.name}] ({inst.location})")
print(f" Status: {inst.status}")
print(f" Monitors: {', '.join(inst.monitors)}")
def failover(self, failed_instance: str):
"""Failover Scenario"""
failed = next((i for i in self.instances if i.name == failed_instance), None)
if failed:
failed.status = "DOWN"
active = [i for i in self.instances if i.status == "UP"]
print(f"\n FAILOVER: {failed_instance} is DOWN")
print(f" Active instances: {len(active)}")
for a in active:
print(f" {a.name} ({a.location}) — taking over monitoring")
ha = HAArchitecture()
instances = [
HAInstance("Primary", "Bangkok (TH)",
["Website", "API", "Database", "Redis"], "UP"),
HAInstance("Secondary", "Singapore (SG)",
["Website", "API", "Database", "Redis"], "UP"),
HAInstance("Tertiary", "Tokyo (JP)",
["Website", "API", "DNS"], "UP"),
]
for inst in instances:
ha.add_instance(inst)
ha.show()
ha.failover("Primary")
# HA Strategies
strategies = {
"Multi-Instance": {
"desc": "หลาย Uptime Kuma Instances แต่ละ Location",
"pros": "ตรวจจากหลายมุมมอง Geographic Redundancy",
"cons": "Config ซ้ำ Alert อาจซ้ำ",
},
"Kubernetes Deployment": {
"desc": "Deploy บน K8s ใช้ PVC สำหรับ Data",
"pros": "Auto-restart, Resource Management",
"cons": "SQLite ไม่รองรับ Multi-replica",
},
"External Database": {
"desc": "ใช้ PostgreSQL/MariaDB แทน SQLite",
"pros": "รองรับ Multiple Instances แชร์ Data",
"cons": "ต้อง Setup Database HA เพิ่ม",
},
"Watchdog": {
"desc": "Monitor ตรวจ Monitor (Meta-monitoring)",
"pros": "รู้ทันทีเมื่อ Monitoring ล่ม",
"cons": "เพิ่มความซับซ้อน",
},
}
print(f"\n\nHA Strategies:")
for strategy, info in strategies.items():
print(f"\n [{strategy}]")
print(f" {info['desc']}")
print(f" Pros: {info['pros']}")
print(f" Cons: {info['cons']}")
Alerting Configuration
# alerting.py — Uptime Kuma Alerting
alerting_channels = {
"Telegram": {
"setup": "Bot Token + Chat ID",
"config": "Notification -> Telegram -> Bot Token, Chat ID",
"features": "ข้อความ + รูปภาพ Status",
},
"Discord": {
"setup": "Webhook URL",
"config": "Notification -> Discord -> Webhook URL",
"features": "Embed Message + Status Color",
},
"Slack": {
"setup": "Webhook URL หรือ Bot Token",
"config": "Notification -> Slack -> Webhook/Bot",
"features": "Channel Message + Blocks",
},
"Email (SMTP)": {
"setup": "SMTP Server, Port, Username, Password",
"config": "Notification -> Email -> SMTP Config",
"features": "Email Alert + HTML Template",
},
"PagerDuty": {
"setup": "Integration Key",
"config": "Notification -> PagerDuty -> Integration Key",
"features": "Incident Management + Escalation",
},
"Webhook": {
"setup": "URL + Custom Headers",
"config": "Notification -> Webhook -> URL",
"features": "Custom JSON Payload",
},
"LINE Notify": {
"setup": "Access Token",
"config": "Notification -> LINE Notify -> Token",
"features": "LINE Message (Thailand)",
},
}
print("Alerting Channels:")
for channel, info in alerting_channels.items():
print(f"\n [{channel}]")
print(f" Setup: {info['setup']}")
print(f" Features: {info['features']}")
# Alert Best Practices
alert_practices = {
"Escalation": "Telegram ก่อน -> ถ้าไม่แก้ 5 นาที -> PagerDuty",
"Deduplication": "ส่ง Alert ครั้งเดียว ไม่ซ้ำจนกว่า Recover",
"Maintenance Window": "ปิด Alert ระหว่าง Maintenance",
"Status Page": "อัปเดต Status Page อัตโนมัติเมื่อ Down",
"Runbook Link": "แนบ Runbook Link ใน Alert Message",
"Multi-channel": "แจ้ง Critical ทุกช่องทาง Info เฉพาะ Slack",
}
print(f"\n\nAlert Best Practices:")
for practice, desc in alert_practices.items():
print(f" {practice}: {desc}")
Best Practices
- Multi-Location: ตรวจจากหลาย Location ป้องกัน False Positive
- Interval: Critical Services ตรวจทุก 30 วินาที ทั่วไป 60 วินาที
- SSL Expiry: ตั้ง Monitor SSL Certificate Expiry แจ้งเตือนก่อน 30 วัน
- Reverse Proxy: ใช้ Nginx + SSL สำหรับ Dashboard
- Backup: Backup data/ folder ทุกวัน
- Meta-monitoring: มี Monitor ตรวจ Uptime Kuma เอง
Uptime Kuma คืออะไร
Open Source Monitoring ตรวจ Uptime เว็บไซต์ Services HTTP TCP Ping DNS Docker gRPC Dashboard แจ้งเตือน Telegram Discord Slack Self-hosted ทางเลือก UptimeRobot
ทำไมต้อง HA สำหรับ Monitoring
Monitoring ล่มจะไม่รู้ Service อื่นล่ม HA ทำงานตลอด 24/7 Instance ล่ม Instance อื่นแทน ตรวจสอบต่อเนื่อง แจ้งเตือนไม่ขาด Production สำคัญ
Uptime Kuma ตั้งค่า HA อย่างไร
หลาย Instances แต่ละ Location Load Balancer Dashboard External Database PostgreSQL แทน SQLite Docker Swarm Kubernetes Deploy Health Check อัตโนมัติ
Uptime Kuma รองรับ Protocol อะไรบ้าง
HTTP HTTPS TCP Ping DNS Docker gRPC MQTT Keyword Push Steam Gamedig ตรวจ Status Code Response Time SSL Expiry Port Container
สรุป
Uptime Kuma Open Source Monitoring HTTP TCP Ping DNS Docker gRPC HA Multi-Instance Multi-Location External Database Alerting Telegram Discord Slack PagerDuty SSL Expiry Meta-monitoring Backup
