Azure Monitor는 Azure 리소스와 애플리케이션의 메트릭, 로그, 추적 데이터를 수집·분석·시각화하는 통합 모니터링 플랫폼이다.
구성 요소
| 컴포넌트 | 설명 |
|---|
| Metrics | 시계열 수치 데이터 (93일 보존) |
| Logs (Log Analytics) | 구조화 로그 데이터 쿼리 (KQL) |
| Application Insights | APM - 애플리케이션 성능 모니터링 |
| Alerts | 임계값·이상 탐지 기반 경보 |
| Dashboards | 메트릭·로그 시각화 |
| Workbooks | 인터랙티브 분석 보고서 |
KQL (Kusto Query Language) 예시
kusto
// 최근 1시간 오류 로그
AppExceptions
| where TimeGenerated > ago(1h)
| where SeverityLevel == 3
| summarize Count = count() by bin(TimeGenerated, 5m), ExceptionType
| order by TimeGenerated desc
// 느린 HTTP 요청 분석
AppRequests
| where TimeGenerated > ago(24h)
| where DurationMs > 2000
| project TimeGenerated, Name, DurationMs, ResultCode
| order by DurationMs desc
| take 50
Application Insights 연동 (Node.js)
typescript
import * as appInsights from 'applicationinsights';
appInsights.setup('YOUR_CONNECTION_STRING')
.setAutoCollectRequests(true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.start();
const client = appInsights.defaultClient;
client.trackEvent({ name: 'UserSignup', properties: { userId: '123' } });
client.trackMetric({ name: 'QueueDepth', value: 42 });
경보 규칙 설정
bash
# CPU 80% 초과 시 경보
az monitor metrics alert create \
--name high-cpu-alert \
--resource-group myRG \
--scopes /subscriptions/.../virtualMachines/myVM \
--condition "avg Percentage CPU > 80" \
--window-size 5m \
--evaluation-frequency 1m \
--action-group myActionGroup
관련 문서