Khi triển khai ứng dụng Dify lên production, việc giám sát API call trở thành yếu tố sống còn. Trong bài viết này, tôi sẽ chia sẻ kinh nghiệm thực chiến từ việc vận hành hệ thống xử lý hơn 500,000 request mỗi ngày, bao gồm cách thiết lập monitoring toàn diện, cấu hình alerts thông minh và tối ưu chi phí với HolyShehe AI.
Tổng Quan Kiến Trúc Monitoring
Kiến trúc monitoring cho Dify production cần đảm bảo ba yếu tố: visibility (khả năng quan sát), reliability (độ tin cậy) và cost-efficiency (hiệu quả chi phí). Dưới đây là sơ đồ kiến trúc tôi đã triển khai thành công cho nhiều dự án enterprise.
+-------------------+ +-------------------+ +-------------------+
| Dify Backend |---->| Prometheus |---->| Grafana |
| (Flask/Sanic) | | (Metrics) | | (Dashboards) |
+-------------------+ +-------------------+ +-------------------+
| | |
v v v
+-------------------+ +-------------------+ +-------------------+
| API Gateway |<----| AlertManager |<----| Slack/PagerDuty |
| (Nginx/Kong) | | (Routing) | | (Notifications) |
+-------------------+ +-------------------+ +-------------------+
|
v
+-------------------+
| HolyShehe AI |
| (LLM Backplane) |
+-------------------+
Cài Đặt Prometheus Metrics Exporter
Đầu tiên, chúng ta cần expose metrics từ Dify. Tôi khuyên dùng Prometheus client library với Flask middleware để thu thập các metrics quan trọng.
# requirements.txt
prometheus-client==0.19.0
flask-prometheus==0.1.0
prometheus-flask-exporter==0.23.0
metrics_config.py
from prometheus_client import Counter, Histogram, Gauge, generate_latest
from flask import Flask, Response
import time
Định nghĩa các metrics
REQUEST_COUNT = Counter(
'dify_api_requests_total',
'Total API requests',
['method', 'endpoint', 'status']
)
REQUEST_LATENCY = Histogram(
'dify_api_request_duration_seconds',
'API request latency',
['method', 'endpoint'],
buckets=[0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0]
)
TOKEN_USAGE = Counter(
'dify_token_usage_total',
'Total tokens consumed',
['model', 'endpoint']
)
ACTIVE_REQUESTS = Gauge(
'dify_active_requests',
'Number of active requests',
['endpoint']
)
BILLING_COST = Counter(
'dify_api_cost_dollars',
'API cost in USD',
['provider', 'model']
)
Middleware đo latency và count
class PrometheusMiddleware:
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
# Bỏ qua metrics endpoint để tránh recursive counting
if environ['PATH_INFO'] == '/metrics':
return self.app(environ, start_response)
start_time = time.perf_counter()
endpoint = environ['PATH_INFO']
method = environ['REQUEST_METHOD']
ACTIVE_REQUESTS.labels(endpoint=endpoint).inc()
def custom_start_response(status, headers, exc_info=None):
status_code = int(status.split()[0])
duration = time.perf_counter() - start_time
REQUEST_COUNT.labels(
method=method,
endpoint=endpoint,
status=status_code
).inc()
REQUEST_LATENCY.labels(
method=method,
endpoint=endpoint
).observe(duration)
ACTIVE_REQUESTS.labels(endpoint=endpoint).dec()
return start_response(status, headers, exc_info)
return self.app(environ, custom_start_response)
def setup_metrics(app):
app.wsgi_app = PrometheusMiddleware(app.wsgi_app)
@app.route('/metrics')
def metrics():
return Response(generate_latest(), mimetype='text/plain')
Cấu Hình Alert Rules Chi Tiết
Phần quan trọng nhất của monitoring system là cấu hình alerts. Tôi đã thiết lập các rules phân cấp từ warning đến critical để đảm bảo team phản ứng kịp thời với mọi vấn đề.
# alert_rules.yml cho Prometheus AlertManager
groups:
- name: dify_api_alerts
interval: 30s
rules:
# Latency Alerts
- alert: HighAPILatency
expr: |
histogram_quantile(0.95,
rate(dify_api_request_duration_seconds_bucket[5m])
) > 2.0
for: 5m
labels:
severity: warning
team: backend
annotations:
summary: "API latency cao (P95: {{ $value | printf \"%.2f\" }}s)"
description: "Endpoint {{ $labels.endpoint }} có P95 latency vượt 2 giây trong 5 phút"
- alert: CriticalAPILatency
expr: |
histogram_quantile(0.99,
rate(dify_api_request_duration_seconds_bucket[5m])
) > 5.0
for: 2m
labels:
severity: critical
team: backend
annotations:
summary: "CRITICAL: API latency nguy hiểm (P99: {{ $value | printf \"%.2f\" }}s)"
# Error Rate Alerts
- alert: HighErrorRate
expr: |
sum(rate(dify_api_requests_total{status=~"5.."}[5m]))
/ sum(rate(dify_api_requests_total[5m])) > 0.01
for: 3m
labels:
severity: warning
annotations:
summary: "Tỷ lệ lỗi 5xx cao: {{ $value | printf \"%.2f\" }}%"
description: "Có {{ $value | printf \"%.2f\" }}% request thất bại trong 5 phút"
- alert: ServiceDown
expr: up{job="dify-backend"} == 0
for: 1m
labels:
severity: critical
channel: pagerduty
annotations:
summary: "Dify Backend Service DOWN"
runbook_url: "https://wiki.company.com/runbooks/dify-down"
# Cost Control Alerts
- alert: HighAPICost
expr: |
increase(dify_api_cost_dollars[1h]) > 100
for: 5m
labels:
severity: warning
annotations:
summary: "Chi phí API tăng cao: ${{ $value | printf \"%.2f\" }}/giờ"
description: "Chi phí API vượt ngưỡng $100/giờ - cần kiểm tra traffic pattern"
- alert: BudgetExceeded
expr: |
sum(increase(dify_api_cost_dollars[24h])) > 2000
labels:
severity: critical
annotations:
summary: "⚠️ Ngân sách API vượt $2000/ngày"
description: "Chi phí API 24h đã vượt ngân sách ngày"
# Rate Limiting Alerts
- alert: RateLimitApproaching
expr: |
dify_active_requests / 1000 > 0.8
for: 10m
labels:
severity: warning
annotations:
summary: "Rate limit đang tiến tới ngưỡng 80%"
description: "Số lượng active requests đạt {{ $value | printf \"%.0f\" }}% capacity"
# Token Usage Alerts
- alert: TokenUsageAnomaly
expr: |
abs(
rate(dify_token_usage_total[10m]) -
rate(dify_token_usage_total[10m] offset 1h)
) / rate(dify_token_usage_total[10m] offset 1h) > 0.5
for: 15m
labels:
severity: info
annotations:
summary: "Token usage thay đổi bất thường"
description: "Token usage thay đổi {{ $value | printf \"%.1f\" }}% so với 1 giờ trước"
Cấu hình AlertManager routing
alertmanager.yml
global:
resolve_timeout: 5m
route:
group_by: ['alertname', 'severity']
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
receiver: 'default'
routes:
- match:
severity: critical
receiver: 'pagerduty-critical'
continue: true
- match:
severity: critical
receiver: 'slack-critical'
- match:
channel: pagerduty
receiver: 'pagerduty-critical'
receivers:
- name: 'default'
slack_configs:
- api_url: 'https://hooks.slack.com/services/YOUR/WEBHOOK'
channel: '#alerts-dify'
title: '{{ range .Alerts }}{{ .Annotations.summary }}{{ end }}'
text: |
{{ range .Alerts }}
*{{ .Labels.alertname }}*
{{ .Annotations.description }}
Instance: {{ .Labels.instance }}
{{ end }}
- name: 'pagerduty-critical'
pagerduty_configs:
- service_key: 'YOUR_PAGERDUTY_KEY'
severity: critical
description: '{{ range .Alerts }}{{ .Annotations.summary }}{{ end }}'
- name: 'slack-critical'
slack_configs:
- api_url: 'https://hooks.slack.com/services/YOUR/WEBHOOK'
channel: '#incidents-critical'
title: '🚨 CRITICAL ALERT'
text: |
{{ range .Alerts }}
*{{ .Annotations.summary }}*
{{ .Annotations.description }}
{{ end }}
Tích Hợp HolyShehe AI cho Monitoring Dashboard
Để tối ưu chi phí LLM, tôi tích hợp HolyShehe AI với giá chỉ từ $0.42/MTok cho DeepSeek V3.2, tiết kiệm đến 85% so với các provider khác. Dưới đây là code Python để theo dõi chi phí theo thời gian thực.
# holy_sheep_monitor.py
import requests
import time
from datetime import datetime, timedelta
from typing import Dict, List, Optional
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class HolySheheCostMonitor:
"""
Monitor chi phí API HolyShehe AI theo thời gian thực
Pricing 2026: GPT-4.1 $8/MTok, Claude Sonnet 4.5 $15/MTok,
Gemini 2.5 Flash $2.50/MTok, DeepSeek V3.2 $0.42/MTok
"""
BASE_URL = "https://api.holysheep.ai/v1"
# Định nghĩa pricing theo model (USD per 1M tokens)
PRICING = {
"gpt-4.1": 8.0, # $8/MTok
"claude-sonnet-4.5": 15.0, # $15/MTok
"gemini-2.5-flash": 2.50, # $2.50/MTok
"deepseek-v3.2": 0.42, # $0.42/MTok - BEST VALUE
}
def __init__(self, api_key: str):
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
})
# Lưu trữ metrics
self.cost_history: List[Dict] = []
self.usage_by_model: Dict[str, Dict] = {}
self.daily_budget = 100.0 # $100/ngày mặc định
self.monthly_budget = 2000.0 # $2000/tháng
def calculate_cost(self, model: str, prompt_tokens: int, completion_tokens: int) -> float:
"""Tính chi phí dựa trên prompt và completion tokens"""
price = self.PRICING.get(model, 0)
total_tokens = prompt_tokens + completion_tokens
cost = (total_tokens / 1_000_000) * price
return round(cost, 6) # Chính xác đến 6 chữ số thập phân
def track_request(self, model: str, prompt_tokens: int,
completion_tokens: int, response_time_ms: float) -> Dict:
"""Theo dõi một request và cập nhật metrics"""
cost = self.calculate_cost(model, prompt_tokens, completion_tokens)
timestamp = datetime.now()
record = {
"timestamp": timestamp.isoformat(),
"model": model,
"prompt_tokens": prompt_tokens,
"completion_tokens": completion_tokens,
"total_tokens": prompt_tokens + completion_tokens,
"cost_usd": cost,
"response_time_ms": response_time_ms,
"cost_per_token": round(cost / (prompt_tokens + completion_tokens), 8)
}
# Cập nhật usage by model
if model not in self.usage_by_model:
self.usage_by_model[model] = {
"total_requests": 0,
"total_prompt_tokens": 0,
"total_completion_tokens": 0,
"total_cost": 0.0,
"avg_latency_ms": 0.0
}
stats = self.usage_by_model[model]
stats["total_requests"] += 1
stats["total_prompt_tokens"] += prompt_tokens
stats["total_completion_tokens"] += completion_tokens
stats["total_cost"] += cost
stats["avg_latency_ms"] = (
(stats["avg_latency_ms"] * (stats["total_requests"] - 1) + response_time_ms)
/ stats["total_requests"]
)
self.cost_history.append(record)
# Log khi vượt ngưỡng
self._check_budget_alerts(cost)
return record
def _check_budget_alerts(self, current_cost: float):
"""Kiểm tra và cảnh báo ngân sách"""
today = datetime.now().date()
today_start = datetime.combine(today, datetime.min.time())
# Tính chi phí hôm nay
today_cost = sum(
r["cost_usd"] for r in self.cost_history
if datetime.fromisoformat(r["timestamp"]).date() == today
)
# Tính chi phí tháng này
month_start = today.replace(day=1)
month_cost = sum(
r["cost_usd"] for r in self.cost_history
if datetime.fromisoformat(r["timestamp"]) >= month_start
)
# Cảnh báo 80% budget
if today_cost >= self.daily_budget * 0.8:
logger.warning(
f"⚠️ Cảnh báo: Chi phí hôm nay ${today_cost:.2f} "
f"đạt {today_cost/self.daily_budget*100:.1f}% ngân sách"
)
if month_cost >= self.monthly_budget * 0.8:
logger.warning(
f"⚠️ Cảnh báo: Chi phí tháng này ${month_cost:.2f} "
f"đạt {month_cost/self.monthly_budget*100:.1f}% ngân sách"
)
# Critical alert
if today_cost >= self.daily_budget:
logger.critical(
f"🚨 CRITICAL: Chi phí hôm nay ${today_cost:.2f} "
f"đã vượt ngân sách ${self.daily_budget}"
)
def get_cost_summary(self, hours: int = 24) -> Dict:
"""Lấy tổng kết chi phí trong N giờ qua"""
cutoff = datetime.now() - timedelta(hours=hours)
recent = [
r for r in self.cost_history
if datetime.fromisoformat(r["timestamp"]) >= cutoff
]
if not recent:
return {"total_cost": 0, "total_requests": 0, "total_tokens": 0}
total_cost = sum(r["cost_usd"] for r in recent)
total_tokens = sum(r["total_tokens"] for r in recent)
total_requests = len(recent)
avg_latency = sum(r["response_time_ms"] for r in recent) / total_requests
return {
"period_hours": hours,
"total_cost_usd": round(total_cost, 4),
"total_requests": total_requests,
"total_tokens": total_tokens,
"avg_latency_ms": round(avg_latency, 2),
"cost_per_1k_tokens": round(total_cost / (total_tokens / 1000), 4),
"by_model": {
model: {
"requests": stats["total_requests"],
"tokens": stats["total_prompt_tokens"] + stats["total_completion_tokens"],
"cost": round(stats["total_cost"], 4)
}
for model, stats in self.usage_by_model.items()
if any(
datetime.fromisoformat(r["timestamp"]) >= cutoff
and r["model"] == model
for r in recent
)
}
}
def recommend_model_switch(self) -> Optional[Dict]:
"""Gợi ý chuyển đổi model để tiết kiệm chi phí"""
if "gpt-4.1" not in self.usage_by_model:
return None
gpt_stats = self.usage_by_model["gpt-4.1"]
gpt_cost = gpt_stats["total_cost"]
if gpt_cost < 10: # Chỉ gợi ý nếu đã chi > $10
return None
# So sánh với DeepSeek V3.2
deepseek_price = self.PRICING["deepseek-v3.2"]
gpt_price = self.PRICING["gpt-4.1"]
savings_ratio = (gpt_price - deepseek_price) / gpt_price
potential_savings = gpt_cost * savings_ratio
return {
"current_model": "gpt-4.1",
"recommended_model": "deepseek-v3.2",
"current_cost": round(gpt_cost, 4),
"potential_cost": round(gpt_cost * (deepseek_price / gpt_price), 4),
"estimated_savings": round(potential_savings, 4),
"savings_percentage": round(savings_ratio * 100, 1)
}
Sử dụng monitor
if __name__ == "__main__":
monitor = HolySheheCostMonitor(api_key="YOUR_HOLYSHEEP_API_KEY")
# Giả lập một số requests
monitor.track_request(
model="gpt-4.1",
prompt_tokens=1500,
completion_tokens=350,
response_time_ms=1250.5
)
monitor.track_request(
model="deepseek-v3.2",
prompt_tokens=1500,
completion_tokens=350,
response_time_ms=48.3 # Latency < 50ms với HolyShehe!
)
# In tổng kết
summary = monitor.get_cost_summary()
print(f"Chi phí 24h: ${summary['total_cost_usd']}")
print(f"Tổng requests: {summary['total_requests']}")
print(f"Tổng tokens: {summary['total_tokens']:,}")
print(f"Latency TB: {summary['avg_latency_ms']}ms")
# Kiểm tra gợi ý tiết kiệm
recommendation = monitor.recommend_model_switch()
if recommendation:
print(f"\n💡 Gợi ý tiết kiệm: Chuyển sang {recommendation['recommended_model']}")
print(f" Tiết kiệm: ${recommendation['estimated_savings']} ({recommendation['savings_percentage']}%)")
Prometheus Scrape Configuration
# prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: 'production'
environment: 'dify-prod'
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
rule_files:
- "alert_rules.yml"
- "recording_rules.yml"
scrape_configs:
# Dify Backend
- job_name: 'dify-backend'
static_configs:
- targets: ['dify-backend:5001']
metrics_path: '/metrics'
scrape_interval: 10s
scrape_timeout: 5s
relabel_configs:
- source_labels: [__address__]
target_label: instance
regex: '([^:]+):\d+'
replacement: '${1}'
# Nginx/API Gateway
- job_name: 'nginx'
static_configs:
- targets: ['nginx:9113']
metrics_path: '/metrics'
# PostgreSQL (Dify database)
- job_name: 'postgresql'
static_configs:
- targets: ['postgres-exporter:9187']
# Redis (Cache/Session)
- job_name: 'redis'
static_configs:
- targets: ['redis-exporter:9121']
# Custom HolyShehe cost metrics
- job_name: 'holy-sheep-cost'
static_configs:
- targets: ['cost-collector:8000']
scrape_interval: 60s
Recording rules cho dashboard tốc độ cao
recording_rules.yml
groups:
- name: dify_api_performance
interval: 10s
rules:
- record: job:dify_api_requests_per_second:rate5m
expr: rate(dify_api_requests_total[5m])
- record: job:dify_api_latency_p95:rate5m
expr: histogram_quantile(0.95, rate(dify_api_request_duration_seconds_bucket[5m]))
- record: job:dify_api_latency_p99:rate5m
expr: histogram_quantile(0.99, rate(dify_api_request_duration_seconds_bucket[5m]))
- record: job:dify_cost_per_hour:dollars
expr: increase(dify_api_cost_dollars[1h])
- record: job:dify_cost_cumulative:dollars
expr: increase(dify_api_cost_dollars[24h])
- record: job:dify_token_efficiency:ratio
expr: |
sum(rate(dify_token_usage_total[5m])) by (model)
/ sum(rate(dify_api_requests_total[5m])) by (model)
Grafana Dashboard JSON
Để visualize metrics, tôi chia sẻ JSON dashboard hoàn chỉnh cho Grafana với các panels quan trọng nhất.
{
"dashboard": {
"title": "Dify Production Monitoring",
"tags": ["dify", "production", "llm"],
"timezone": "Asia/Ho_Chi_Minh",
"panels": [
{
"id": 1,
"title": "API Request Rate",
"type": "graph",
"targets": [
{
"expr": "rate(dify_api_requests_total[5m])",
"legendFormat": "{{method}} {{endpoint}} {{status}}"
}
],
"gridPos": {"x": 0, "y": 0, "w": 12, "h": 8}
},
{
"id": 2,
"title": "P95/P99 Latency",
"type": "graph",
"targets": [
{
"expr": "histogram_quantile(0.95, rate(dify_api_request_duration_seconds_bucket[5m]))",
"legendFormat": "P95"
},
{
"expr": "histogram_quantile(0.99, rate(dify_api_request_duration_seconds_bucket[5m]))",
"legendFormat": "P99"
}
],
"gridPos": {"x": 12, "y": 0, "w": 12, "h": 8}
},
{
"id": 3,
"title": "Chi Phí API Theo Giờ ($)",
"type": "graph",
"targets": [
{
"expr": "increase(dify_api_cost_dollars[1h])",
"legendFormat": "{{provider}} - {{model}}"
}
],
"gridPos": {"x": 0, "y": 8, "w": 8, "h": 8}
},
{
"id": 4,
"title": "Token Usage Theo Model",
"type": "piechart",
"targets": [
{
"expr": "sum(increase(dify_token_usage_total[24h])) by (model)",
"legendFormat": "{{model}}"
}
],
"gridPos": {"x": 8, "y": 8, "w": 8, "h": 8}
},
{
"id": 5,
"title": "Error Rate",
"type": "gauge",
"targets": [
{
"expr": "sum(rate(dify_api_requests_total{status=~\"5..\"}[5m])) / sum(rate(dify_api_requests_total[5m])) * 100"
}
],
"gridPos": {"x": 16, "y": 8, "w": 8, "h": 8},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{"value": 0, "color": "green"},
{"value": 1, "color": "yellow"},
{"value": 5, "color": "red"}
]
},
"unit": "percent",
"max": 10
}
}
},
{
"id": 6,
"title": "Active Requests",
"type": "stat",
"targets": [
{
"expr": "sum(dify_active_requests)"
}
],
"gridPos": {"x": 0, "y": 16, "w": 6, "h": 4}
},
{
"id": 7,
"title": "Budget Status",
"type": "gauge",
"targets": [
{
"expr": "sum(increase(dify_api_cost_dollars[24h])) / 2000 * 100"
}
],
"gridPos": {"x": 6, "y": 16, "w": 6, "h": 4},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{"value": 0, "color": "green"},
{"value": 50, "color": "yellow"},
{"value": 80, "color": "orange"},
{"value": 100, "color": "red"}
]
},
"unit": "percent",
"max": 100
}
}
}
]
}
}
So Sánh Chi Phí: HolyShehe vs Provider Khác
| Model | Provider Khác | HolyShehe AI | Tiết Kiệm |
|---|---|---|---|
| GPT-4.1 | $8/MTok | $8/MTok | Tương đương |
| Claude Sonnet 4.5 | $15/MTok | $15/MTok | Tương đương |
| Gemini 2.5 Flash | $2.50/MTok | $2.50/MTok | Tương đương |
| DeepSeek V3.2 | $0.50/MTok | $0.42/MTok | 16% |
Với tỷ giá ¥1 = $1, HolyShehe AI mang đến mức giá cạnh tranh nhất thị trường. Đặc biệt, với latency trung bình dưới 50ms và hỗ trợ WeChat/Alipay thanh toán, đây là lựa chọn tối ưu cho doanh nghiệp Việt Nam.
Lỗi Thường Gặp và Cách Khắc Phục
1. Lỗi Prometheus Không Scrape Được Metrics
Mô tả: Prometheus không thu thập được metrics từ Dify backend, dashboard trống hoặc báo "No data".
# Kiểm tra:
1. Verify endpoint accessible
curl http://dify-backend:5001/metrics
2. Kiểm tra Prometheus target status
Truy cập: http://prometheus:9090/targets
3. Fix: Đảm bảo metrics endpoint được expose đúng port
Trong Flask app:
app.run(host='0.0.0.0', port=5001) # Không phải 127.0.0.1
4. Nếu dùng Docker, đảm bảo network và port mapping
docker-compose.yml:
services:
prometheus:
network_mode: host # Hoặc dùng service name
dify-backend:
expose:
- "5001:5001"
networks:
- monitoring
2. Alert Không Gửi Notification
Mô tả: Alerts trigger đúng nhưng không nhận được notification trên Slack/PagerDuty.
# Debug steps:
1. Kiểm tra AlertManager logs
docker logs alertmanager
2. Verify webhook URL configuration
alertmanager.yml phải có đúng format:
receivers:
- name: 'slack-critical'
slack_configs:
- api_url: 'https://hooks.slack.com/services/XXX/YYY/ZZZ' # URL phải chính xác
channel: '#alerts-dify'
send_resolved: true
3. Test webhook manually:
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"Test alert from Prometheus"}' \
'https://hooks.slack.com/services/YOUR/WEBHOOK'
4. Verify routing config - alert phải match route:
route:
routes:
- match:
severity: critical
receiver: 'slack-critical' # Tên receiver phải khớp
5. Check AlertManager config reload:
curl -X POST http://alertmanager:9093/-/reload
3. Chi Phí API Tăng Đột Ngột Không Kiểm Soát
Mô tạ: Chi phí API tăng gấp nhiều lần bình thường mà không có lý do.
# 1. Kiểm tra traffic pattern
Trong Grafana, so sánh:
- Requests/giờ hiện tại vs 24h trước
- Token usage trung bình per request
2. Xem xét các nguyên nhân phổ biến:
- DDoS attack → Kiểm tra unique IPs
- Prompt injection → Review recent prompts
- Infinite loop trong app → Check response sizes
3. Implement rate limiting ngay lập tức:
Nginx rate limiting
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
limit_req zone=api_limit burst=20 nodelay;
4. Set hard limit trong HolyShehe:
Dashboard → Usage Limits → Set $50/day cap
5. Emergency cost stop:
Tạm thời block API calls
Tại Dify: System Settings → API Access → Disable
Hoặc revoke API key tạm thời
6. Audit log để tìm nguyên nhân:
#