경고 규칙 API

엔드포인트: /api/metrics/alert-rules/

경고 규칙은 에이전트가 이미 보낸 데이터를 사용해 서버의 지표를 감시하다가 값이 설정한 방향으로 임계값을 지나면 경고를 발생시킵니다. 규칙은 Alpacon이 자체 일정에 따라 약 1분마다 평가합니다. 규칙이 발생하고 해제되는 방식은 모니터링 규칙을 참고하세요.

기본으로 생성되는 디스크 사용률 규칙(모든 서버가 플랜과 관계없이 갖는 규칙)을 포함해, 모든 동작에 워크스페이스의 Metrics 확장 기능이 켜져 있어야 합니다.

경고 규칙 목록 조회

경고 규칙 목록을 페이지네이션하여 가져옵니다.

GET /api/metrics/alert-rules/

쿼리 파라미터

파라미터타입설명
namestring규칙 이름으로 필터링
ownerstring소유자 사용자명으로 필터링
targetstring대상 지표로 필터링
thresholdnumber임계값으로 필터링
operatorstring방향으로 필터링 (gte 또는 lte)
devicestring장치로 필터링
severitystring심각도로 필터링 (critical, warning, info)
is_defaultboolean기본 규칙 여부로 필터링
serverstring (UUID)이 서버에 붙은 규칙만 조회
exclude_serverstring (UUID)이 서버에 붙지 않은 규칙만 조회
searchstring이름, 대상, 기본 규칙 여부로 검색
orderingstring정렬 순서. 기본값: -added_at
pageinteger페이지 번호
page_sizeinteger페이지당 결과 수 (기본값: 15, 최대: 100)

응답

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "3f1c9b2e-6a4d-4e8f-9b1a-2c3d4e5f6a7b",
      "owner": null,
      "name": "Core disk usage",
      "target": "disk-usage",
      "threshold": 90,
      "operator": "gte",
      "duration_s": 0,
      "recovery_threshold": 85,
      "no_data_after_s": null,
      "device": "",
      "severity": "warning",
      "is_default": true
    },
    {
      "id": "8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e",
      "owner": {
        "id": 1,
        "name": "admin",
        "email": "admin@example.com"
      },
      "name": "Sustained high CPU",
      "target": "cpu-usage",
      "threshold": 80,
      "operator": "gte",
      "duration_s": 300,
      "recovery_threshold": 70,
      "no_data_after_s": 600,
      "device": "",
      "severity": "critical",
      "is_default": false
    }
  ]
}

필요한 스코프: alert_rule:read

예시

curl -X GET "https://your-workspace.ap1.alpacon.io/api/metrics/alert-rules/?target=cpu-usage" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""

경고 규칙 생성

새 경고 규칙을 만듭니다.

POST /api/metrics/alert-rules/

요청 본문

{
  "name": "Sustained high CPU",
  "target": "cpu-usage",
  "threshold": 80,
  "operator": "gte",
  "duration_s": 300,
  "recovery_threshold": 70,
  "no_data_after_s": 600,
  "severity": "critical"
}

요청 파라미터

필드타입필수설명
namestringYes규칙 이름. 워크스페이스 내에서 유일해야 함
targetstringYes감시할 지표: cpu-usage, memory-usage, disk-usage, peak-read-bps, peak-write-bps, avg-read-bps, avg-write-bps, peak-input-pps, peak-input-bps, peak-output-pps, peak-output-bps, avg-input-pps, avg-input-bps, avg-output-pps, avg-output-bps
thresholdnumberYes경고를 발생시키는 값
operatorstringNogte: 임계값 이상일 때 발생(기본값). lte: 임계값 이하일 때 발생
duration_sintegerNo경고가 발생하기까지 조건이 유지되어야 하는 시간(초). 기본값 0이면 조건을 만족하는 첫 샘플에서 바로 발생
recovery_thresholdnumberNo경고가 해제되기 위해 지표가 돌아와야 하는 값. 선택한 operator에서 회복하는 쪽에 있어야 함(gte라면 threshold보다 낮게, lte라면 threshold보다 높게). 비워 두면 threshold 자체가 해제 기준이 됨
no_data_after_sintegerNo이 시간(초) 동안 샘플이 도착하지 않으면 별도의 경고를 발생시킴. 이 대상의 수집 간격 이상, 86400(24시간) 이하여야 함. 비워 두면 이 기능을 사용하지 않음
devicestringNo규칙을 디스크나 네트워크 인터페이스 하나로 제한. 장치 단위로 측정되는 대상(disk-usage와 위 디스크 I/O·네트워크 대상들)에만 설정 가능하며, 서버 전체를 대상으로 하는 cpu-usage, memory-usage에는 거부됨
severitystringNo발생하는 경고의 심각도: critical, warning, info 중 하나. 기본값 warning
is_defaultbooleanNo이후 등록되는 모든 서버에 자동으로 붙는 규칙인지 여부. 대상과 장치 조합당 기본 규칙은 하나만 가능

응답

{
  "id": "8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e",
  "owner": {
    "id": 1,
    "name": "admin",
    "email": "admin@example.com"
  },
  "name": "Sustained high CPU",
  "target": "cpu-usage",
  "threshold": 80,
  "operator": "gte",
  "duration_s": 300,
  "recovery_threshold": 70,
  "no_data_after_s": 600,
  "device": "",
  "severity": "critical",
  "is_default": false
}

필요한 스코프: alert_rule:create

예시

curl -X POST "https://your-workspace.ap1.alpacon.io/api/metrics/alert-rules/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\"" \
  -H "Content-Type: application/json" \
  -d '{"name": "Sustained high CPU", "target": "cpu-usage", "threshold": 80, "duration_s": 300}'

경고 규칙 상세 조회

특정 경고 규칙을 ID로 조회합니다.

GET /api/metrics/alert-rules/{rule_id}/

경로 파라미터

파라미터타입설명
rule_idstring (UUID)조회할 경고 규칙의 ID

응답

{
  "id": "8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e",
  "owner": {
    "id": 1,
    "name": "admin",
    "email": "admin@example.com"
  },
  "name": "Sustained high CPU",
  "target": "cpu-usage",
  "threshold": 80,
  "operator": "gte",
  "duration_s": 300,
  "recovery_threshold": 70,
  "no_data_after_s": 600,
  "device": "",
  "severity": "critical",
  "is_default": false
}

필요한 스코프: alert_rule:read

예시

curl -X GET "https://your-workspace.ap1.alpacon.io/api/metrics/alert-rules/8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""

경고 규칙 수정

기존 경고 규칙을 수정합니다. PATCH를 통한 부분 업데이트를 지원합니다.

PATCH /api/metrics/alert-rules/{rule_id}/

경로 파라미터

파라미터타입설명
rule_idstring (UUID)수정할 경고 규칙의 ID

요청 본문

{
  "threshold": 85,
  "recovery_threshold": 75
}

요청 파라미터

경고 규칙 생성과 같은 필드이며, 모두 선택 사항입니다. operatorthreshold를 바꾸면 이 규칙 자체의 복귀 임계값이나 서버 오버라이드의 복귀 임계값이 바뀐 값의 잘못된 쪽에 남게 될 경우, 그 수정은 거부됩니다.

응답

수정된 필드를 포함한 전체 경고 규칙 객체를 반환합니다 (경고 규칙 상세 조회와 같은 스키마).

필요한 스코프: alert_rule:update

예시

curl -X PATCH "https://your-workspace.ap1.alpacon.io/api/metrics/alert-rules/8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\"" \
  -H "Content-Type: application/json" \
  -d '{"threshold": 85, "recovery_threshold": 75}'

경고 규칙 삭제

경고 규칙을 삭제합니다. 기본 규칙(is_default: true)은 기본 상태로 지정된 채로는 삭제할 수 없습니다. 먼저 is_default를 해제하세요.

DELETE /api/metrics/alert-rules/{rule_id}/

경로 파라미터

파라미터타입설명
rule_idstring (UUID)삭제할 경고 규칙의 ID

응답

204 No Content

필요한 스코프: alert_rule:delete

예시

curl -X DELETE "https://your-workspace.ap1.alpacon.io/api/metrics/alert-rules/8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""

오류 코드

상태오류 코드설명
400metrics_alert_rule_exists이 대상과 장치 조합에 이미 기본 규칙이 있음
400metrics_alert_rule_recovery_threshold_invalidrecovery_thresholdthreshold의 회복하는 쪽에 있지 않음
400metrics_alert_rule_no_data_window_too_shortno_data_after_s가 이 대상의 수집 간격보다 짧음
400metrics_alert_rule_no_data_window_too_longno_data_after_s가 86400초(24시간)보다 김
400metrics_alert_rule_device_not_supported서버 전체를 대상으로 하는 지표(cpu-usage, memory-usage)에 device를 지정함
400metrics_alert_rule_cannot_be_deletedis_defaulttrue인 규칙을 삭제하려고 함
401UNAUTHORIZED유효하지 않거나 누락된 인증 정보
403FORBIDDEN권한 부족, 또는 이 워크스페이스에서 Metrics 확장 기능이 꺼져 있음
404NOT_FOUND경고 규칙을 찾을 수 없음
최종 수정: