Tools: ตรวจ CPU/Memory ทุกชั่วโมงด้วย Garudust Agent Cron ในตัว - 2025 Update
สิ่งที่ต้องมี
1. ติดตั้ง Binary
2. ตั้ง Config
3. รัน Server
4. รัน Server แบบ Daemon ด้วย systemd
5. เช็ก Log
6. เพิ่ม Job แบบ Runtime ผ่าน API
7. ตั้ง Alert ผ่าน Telegram (ทางเลือก)
เปรียบเทียบกับ System Cron
สรุป config ทั้งหมด garudust-agent มี cron scheduler ในตัวอยู่แล้ว ภายใต้ crates/garudust-cron ที่ wraps tokio_cron_scheduler ไว้ หน้าที่ของมันคือยิง agent task ตาม schedule โดยตรง — ไม่ต้องสร้าง process ใหม่ทุกรอบ session ยังอยู่ใน RAM ข้าม tick ได้ และ agent สร้าง/ลบ job เองตอน runtime ได้ด้วย บทความนี้ใช้ระบบ cron ใน garudust ทำงานให้ถูกต้อง ไฟล์ config อยู่ที่ ~/.garudust/config.yaml — สร้าง directory ก่อน: ที่ startup จะเห็น log ยืนยัน cron ถูก register: เมื่อ cron fire จะเห็น: หรือถ้า agent เจอปัญหา: สำหรับ production ไม่ควรรันใน terminal ค้างไว้ — ใช้ systemd: เมื่อรันด้วย systemd: ถ้าอยากเก็บ log เป็นไฟล์แยก ใส่เพิ่มใน systemd unit: นอกจาก static job ใน config แล้ว agent มี tool cron_create / cron_list / cron_delete ให้ใช้ตอน runtime — สั่งผ่าน HTTP API ได้เลย: agent จะใช้ tool cron_create สร้าง job ให้อัตโนมัติ: หมายเหตุ — Cron syntax ต่างกัน 2 แบบ: Tip: Runtime jobs หายเมื่อ restart — สำหรับ permanent job ให้ใส่ใน config.yaml เสมอ Runtime jobs เหมาะสำหรับทดสอบ schedule ก่อน commit config หรือ one-off jobs ชั่วคราว เพิ่ม platform Telegram เข้าไปใน config — agent จะส่งข้อความหา admin โดยตรงเมื่อ cron fire และเจอปัญหา: จุดเด่นที่ system cron ทำไม่ได้: agent จำ pattern ข้ามรอบได้ เช่น รู้ว่า CPU spike ทุก 14:00 คือ backup job ไม่ใช่ anomaly — เพราะ memory session ยังอยู่ในหน่วยความจำระหว่าง tick garudust-agent → github.com/garudust-org/garudust-agent Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse
$ ARCH=$(uname -m) -weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-${ARCH}-unknown-linux-gnu.tar.gz" tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server garudust-server --version
# garudust-server 0.13.1
ARCH=$(uname -m) -weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-${ARCH}-unknown-linux-gnu.tar.gz" tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server garudust-server --version
# garudust-server 0.13.1
ARCH=$(uname -m) -weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-${ARCH}-unknown-linux-gnu.tar.gz" tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server garudust-server --version
# garudust-server 0.13.1
# macOS (Apple Silicon)
-weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-aarch64-apple-darwin.tar.gz"
tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server
# macOS (Apple Silicon)
-weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-aarch64-apple-darwin.tar.gz"
tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server
# macOS (Apple Silicon)
-weight: 500;">curl -Lo garudust.tar.gz \ "https://github.com/ninenox/garudust-agent/releases/download/v${GARUDUST_VERSION}/garudust-aarch64-apple-darwin.tar.gz"
tar -xzf garudust.tar.gz
chmod +x garudust-server
-weight: 600;">sudo mv garudust-server /usr/local/bin/garudust-server
mkdir -p ~/.garudust
mkdir -p ~/.garudust
mkdir -p ~/.garudust
# ~/.garudust/config.yaml model: "gpt-4o-mini"
api_key: "sk-..." tools: terminal: enabled: true sandbox: none # รันบน host โดยตรง — monitoring อ่านอย่างเดียว ปลอดภัย approval_mode: auto # cron รันโดยไม่มีคนนั่งดู ต้องเป็น auto # ── cron ──────────────────────────────────────────────────────────────────────
cron: timezone: "Asia/Bangkok" # IANA timezone — ถ้าไม่ระบุ default เป็น UTC jobs: - schedule: "0 * * * *" # 5-field unix cron: ทุกชั่วโมง นาทีที่ 0 task: > ตรวจสอบสุขภาพของระบบตอนนี้ด้วยคำสั่งต่อไปนี้: 1. `top -bn1 | head -20` 2. `ps aux --sort=-%cpu | head -10` 3. `free -h` 4. `ps aux --sort=-%mem | head -10` รายงานผลเป็นภาษาไทยตาม threshold ที่กำหนดไว้ # (ทางเลือก) จัดระเบียบ memory ของ agent ทุกคืน memory_consolidation: "0 3 * * *" # (ทางเลือก) ลบ memory เก่ากว่า 30 วัน memory_expiry: "0 4 * * *" system_prompt: | คุณคือ system monitor สำหรับเซิร์ฟเวอร์นี้ Threshold สำหรับแจ้งเตือน: - CPU รวม > 80% → ⚠️ WARNING - CPU รวม > 95% → 🔴 CRITICAL - Memory > 75% → ⚠️ WARNING - Memory > 90% → 🔴 CRITICAL เมื่อเกิน threshold ให้: 1. ระบุ process ที่กินสูงสุด 5 อันดับ 2. ประเมินว่าเป็น spike ชั่วคราว หรือ trend ต่อเนื่อง 3. แนะนำ action ถ้าจำเป็น ถ้าทุกอย่างปกติ สรุปสั้น 2–3 บรรทัดก็พอ ตอบเป็นภาษาไทยเสมอ
# ~/.garudust/config.yaml model: "gpt-4o-mini"
api_key: "sk-..." tools: terminal: enabled: true sandbox: none # รันบน host โดยตรง — monitoring อ่านอย่างเดียว ปลอดภัย approval_mode: auto # cron รันโดยไม่มีคนนั่งดู ต้องเป็น auto # ── cron ──────────────────────────────────────────────────────────────────────
cron: timezone: "Asia/Bangkok" # IANA timezone — ถ้าไม่ระบุ default เป็น UTC jobs: - schedule: "0 * * * *" # 5-field unix cron: ทุกชั่วโมง นาทีที่ 0 task: > ตรวจสอบสุขภาพของระบบตอนนี้ด้วยคำสั่งต่อไปนี้: 1. `top -bn1 | head -20` 2. `ps aux --sort=-%cpu | head -10` 3. `free -h` 4. `ps aux --sort=-%mem | head -10` รายงานผลเป็นภาษาไทยตาม threshold ที่กำหนดไว้ # (ทางเลือก) จัดระเบียบ memory ของ agent ทุกคืน memory_consolidation: "0 3 * * *" # (ทางเลือก) ลบ memory เก่ากว่า 30 วัน memory_expiry: "0 4 * * *" system_prompt: | คุณคือ system monitor สำหรับเซิร์ฟเวอร์นี้ Threshold สำหรับแจ้งเตือน: - CPU รวม > 80% → ⚠️ WARNING - CPU รวม > 95% → 🔴 CRITICAL - Memory > 75% → ⚠️ WARNING - Memory > 90% → 🔴 CRITICAL เมื่อเกิน threshold ให้: 1. ระบุ process ที่กินสูงสุด 5 อันดับ 2. ประเมินว่าเป็น spike ชั่วคราว หรือ trend ต่อเนื่อง 3. แนะนำ action ถ้าจำเป็น ถ้าทุกอย่างปกติ สรุปสั้น 2–3 บรรทัดก็พอ ตอบเป็นภาษาไทยเสมอ
# ~/.garudust/config.yaml model: "gpt-4o-mini"
api_key: "sk-..." tools: terminal: enabled: true sandbox: none # รันบน host โดยตรง — monitoring อ่านอย่างเดียว ปลอดภัย approval_mode: auto # cron รันโดยไม่มีคนนั่งดู ต้องเป็น auto # ── cron ──────────────────────────────────────────────────────────────────────
cron: timezone: "Asia/Bangkok" # IANA timezone — ถ้าไม่ระบุ default เป็น UTC jobs: - schedule: "0 * * * *" # 5-field unix cron: ทุกชั่วโมง นาทีที่ 0 task: > ตรวจสอบสุขภาพของระบบตอนนี้ด้วยคำสั่งต่อไปนี้: 1. `top -bn1 | head -20` 2. `ps aux --sort=-%cpu | head -10` 3. `free -h` 4. `ps aux --sort=-%mem | head -10` รายงานผลเป็นภาษาไทยตาม threshold ที่กำหนดไว้ # (ทางเลือก) จัดระเบียบ memory ของ agent ทุกคืน memory_consolidation: "0 3 * * *" # (ทางเลือก) ลบ memory เก่ากว่า 30 วัน memory_expiry: "0 4 * * *" system_prompt: | คุณคือ system monitor สำหรับเซิร์ฟเวอร์นี้ Threshold สำหรับแจ้งเตือน: - CPU รวม > 80% → ⚠️ WARNING - CPU รวม > 95% → 🔴 CRITICAL - Memory > 75% → ⚠️ WARNING - Memory > 90% → 🔴 CRITICAL เมื่อเกิน threshold ให้: 1. ระบุ process ที่กินสูงสุด 5 อันดับ 2. ประเมินว่าเป็น spike ชั่วคราว หรือ trend ต่อเนื่อง 3. แนะนำ action ถ้าจำเป็น ถ้าทุกอย่างปกติ สรุปสั้น 2–3 บรรทัดก็พอ ตอบเป็นภาษาไทยเสมอ
garudust-server
garudust-server
garudust-server
INFO garudust-server 0.13.1 | model: gpt-4o-mini | port: 3000
INFO cron job registered cron="0 * * * *" task="ตรวจสอบสุขภาพของระบบ..."
INFO memory consolidation cron registered cron="0 3 * * *"
INFO memory expiry cron registered cron="0 4 * * *"
INFO garudust-server listening on 0.0.0.0:3000
INFO garudust-server 0.13.1 | model: gpt-4o-mini | port: 3000
INFO cron job registered cron="0 * * * *" task="ตรวจสอบสุขภาพของระบบ..."
INFO memory consolidation cron registered cron="0 3 * * *"
INFO memory expiry cron registered cron="0 4 * * *"
INFO garudust-server listening on 0.0.0.0:3000
INFO garudust-server 0.13.1 | model: gpt-4o-mini | port: 3000
INFO cron job registered cron="0 * * * *" task="ตรวจสอบสุขภาพของระบบ..."
INFO memory consolidation cron registered cron="0 3 * * *"
INFO memory expiry cron registered cron="0 4 * * *"
INFO garudust-server listening on 0.0.0.0:3000
INFO cron job starting task="ตรวจสอบสุขภาพของระบบ..."
INFO cron job completed task="ตรวจสอบสุขภาพของระบบ..." iterations=3
INFO cron job starting task="ตรวจสอบสุขภาพของระบบ..."
INFO cron job completed task="ตรวจสอบสุขภาพของระบบ..." iterations=3
INFO cron job starting task="ตรวจสอบสุขภาพของระบบ..."
INFO cron job completed task="ตรวจสอบสุขภาพของระบบ..." iterations=3
ERROR cron job failed task="ตรวจสอบสุขภาพของระบบ..." error="..."
ERROR cron job failed task="ตรวจสอบสุขภาพของระบบ..." error="..."
ERROR cron job failed task="ตรวจสอบสุขภาพของระบบ..." error="..."
-weight: 600;">sudo tee /etc/systemd/system/garudust-monitor.-weight: 500;">service > /dev/null <<EOF
[Unit]
Description=Garudust System Monitor
After=network.target [Service]
Type=simple
User=$USER
ExecStart=/usr/local/bin/garudust-server
Restart=on-failure
RestartSec=10
Environment=RUST_LOG=info [Install]
WantedBy=multi-user.target
EOF -weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now garudust-monitor
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status garudust-monitor
-weight: 600;">sudo tee /etc/systemd/system/garudust-monitor.-weight: 500;">service > /dev/null <<EOF
[Unit]
Description=Garudust System Monitor
After=network.target [Service]
Type=simple
User=$USER
ExecStart=/usr/local/bin/garudust-server
Restart=on-failure
RestartSec=10
Environment=RUST_LOG=info [Install]
WantedBy=multi-user.target
EOF -weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now garudust-monitor
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status garudust-monitor
-weight: 600;">sudo tee /etc/systemd/system/garudust-monitor.-weight: 500;">service > /dev/null <<EOF
[Unit]
Description=Garudust System Monitor
After=network.target [Service]
Type=simple
User=$USER
ExecStart=/usr/local/bin/garudust-server
Restart=on-failure
RestartSec=10
Environment=RUST_LOG=info [Install]
WantedBy=multi-user.target
EOF -weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now garudust-monitor
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status garudust-monitor
# Log real-time
journalctl -u garudust-monitor -f # Log ย้อนหลัง 1 ชั่วโมง
journalctl -u garudust-monitor --since "1 hour ago" # กรองเฉพาะรอบที่ cron fire
journalctl -u garudust-monitor -g "cron job" # หารอบที่มี WARNING หรือ CRITICAL
journalctl -u garudust-monitor --since today | grep -E "WARNING|CRITICAL|⚠️|🔴"
# Log real-time
journalctl -u garudust-monitor -f # Log ย้อนหลัง 1 ชั่วโมง
journalctl -u garudust-monitor --since "1 hour ago" # กรองเฉพาะรอบที่ cron fire
journalctl -u garudust-monitor -g "cron job" # หารอบที่มี WARNING หรือ CRITICAL
journalctl -u garudust-monitor --since today | grep -E "WARNING|CRITICAL|⚠️|🔴"
# Log real-time
journalctl -u garudust-monitor -f # Log ย้อนหลัง 1 ชั่วโมง
journalctl -u garudust-monitor --since "1 hour ago" # กรองเฉพาะรอบที่ cron fire
journalctl -u garudust-monitor -g "cron job" # หารอบที่มี WARNING หรือ CRITICAL
journalctl -u garudust-monitor --since today | grep -E "WARNING|CRITICAL|⚠️|🔴"
[Service]
StandardOutput=append:/var/log/garudust-monitor.log
StandardError=append:/var/log/garudust-monitor.log
[Service]
StandardOutput=append:/var/log/garudust-monitor.log
StandardError=append:/var/log/garudust-monitor.log
[Service]
StandardOutput=append:/var/log/garudust-monitor.log
StandardError=append:/var/log/garudust-monitor.log
# สร้าง job ตรวจ disk ทุก 6 ชั่วโมง
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -H "Content-Type: application/json" \ -d '{ "message": "สร้าง cron job label: disk_check ทุก 6 ชั่วโมง ให้รัน df -h แล้วแจ้งถ้า disk ใด partition ใดเกิน 85%" }' | jq .reply
# สร้าง job ตรวจ disk ทุก 6 ชั่วโมง
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -H "Content-Type: application/json" \ -d '{ "message": "สร้าง cron job label: disk_check ทุก 6 ชั่วโมง ให้รัน df -h แล้วแจ้งถ้า disk ใด partition ใดเกิน 85%" }' | jq .reply
# สร้าง job ตรวจ disk ทุก 6 ชั่วโมง
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -H "Content-Type: application/json" \ -d '{ "message": "สร้าง cron job label: disk_check ทุก 6 ชั่วโมง ให้รัน df -h แล้วแจ้งถ้า disk ใด partition ใดเกิน 85%" }' | jq .reply
{ "reply": "✅ สร้าง cron job 'disk_check' แล้ว\nschedule: 0 0 */6 * * *\ntask: รัน df -h ตรวจ disk..."
}
{ "reply": "✅ สร้าง cron job 'disk_check' แล้ว\nschedule: 0 0 */6 * * *\ntask: รัน df -h ตรวจ disk..."
}
{ "reply": "✅ สร้าง cron job 'disk_check' แล้ว\nschedule: 0 0 */6 * * *\ntask: รัน df -h ตรวจ disk..."
}
# ดู job ทั้งหมดที่ active ตอนนี้
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "แสดง cron jobs ทั้งหมด"}' | jq .reply # ลบ job
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "ลบ cron job label: disk_check"}' | jq .reply
# ดู job ทั้งหมดที่ active ตอนนี้
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "แสดง cron jobs ทั้งหมด"}' | jq .reply # ลบ job
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "ลบ cron job label: disk_check"}' | jq .reply
# ดู job ทั้งหมดที่ active ตอนนี้
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "แสดง cron jobs ทั้งหมด"}' | jq .reply # ลบ job
-weight: 500;">curl -s -X POST http://localhost:3000/chat \ -d '{"message": "ลบ cron job label: disk_check"}' | jq .reply
# ~/.garudust/.env
TELEGRAM_TOKEN=bot_token_here
# ~/.garudust/.env
TELEGRAM_TOKEN=bot_token_here
# ~/.garudust/.env
TELEGRAM_TOKEN=bot_token_here
# config.yaml — เพิ่ม/แก้ cron.jobs section นี้
cron: timezone: "Asia/Bangkok" jobs: - schedule: "0 * * * *" task: > ตรวจ CPU/Memory ของระบบ ถ้าพบ WARNING หรือ CRITICAL ให้ส่งข้อความแจ้งไปยัง admin ทาง Telegram ด้วย พร้อมระบุ process และ % ที่เกิน threshold
# config.yaml — เพิ่ม/แก้ cron.jobs section นี้
cron: timezone: "Asia/Bangkok" jobs: - schedule: "0 * * * *" task: > ตรวจ CPU/Memory ของระบบ ถ้าพบ WARNING หรือ CRITICAL ให้ส่งข้อความแจ้งไปยัง admin ทาง Telegram ด้วย พร้อมระบุ process และ % ที่เกิน threshold
# config.yaml — เพิ่ม/แก้ cron.jobs section นี้
cron: timezone: "Asia/Bangkok" jobs: - schedule: "0 * * * *" task: > ตรวจ CPU/Memory ของระบบ ถ้าพบ WARNING หรือ CRITICAL ให้ส่งข้อความแจ้งไปยัง admin ทาง Telegram ด้วย พร้อมระบุ process และ % ที่เกิน threshold
~/.garudust/
├── config.yaml ← cron.jobs, tools, system_prompt
└── .env ← API keys, tokens (ไม่ commit)
~/.garudust/
├── config.yaml ← cron.jobs, tools, system_prompt
└── .env ← API keys, tokens (ไม่ commit)
~/.garudust/
├── config.yaml ← cron.jobs, tools, system_prompt
└── .env ← API keys, tokens (ไม่ commit)
garudust-server -weight: 500;">start ↓
register cron jobs จาก config.yaml ↓
ทุก 1 ชม. → agent run → terminal tool → top/free/ps ↓
log ออก stdout/journald ↓ (ถ้าต่อ Telegram)
send alert เมื่อเกิน threshold
garudust-server -weight: 500;">start ↓
register cron jobs จาก config.yaml ↓
ทุก 1 ชม. → agent run → terminal tool → top/free/ps ↓
log ออก stdout/journald ↓ (ถ้าต่อ Telegram)
send alert เมื่อเกิน threshold
garudust-server -weight: 500;">start ↓
register cron jobs จาก config.yaml ↓
ทุก 1 ชม. → agent run → terminal tool → top/free/ps ↓
log ออก stdout/journald ↓ (ถ้าต่อ Telegram)
send alert เมื่อเกิน threshold - Linux / macOS
- garudust-server binary (v0.13.1+)
- API key จาก OpenAI-compatible endpoint - Static job ใน config.yaml → 5-field unix cron ปกติ เช่น 0 * * * *
- Runtime job ผ่าน API → 6-field (เพิ่ม field วินาทีนำหน้า) เช่น 0 0 * * * * = ทุกชั่วโมง, 0 0 */6 * * * = ทุก 6 ชั่วโมง