상태 수집, 쿼리 및 시각화

완료됨

상태 모델을 정확하게 나타내려면 시스템에서 다양한 데이터 세트를 수집해야 합니다. 데이터 세트에는 애플리케이션 구성 요소 및 기본 Azure 리소스의 로그 및 성능 메트릭이 포함됩니다. 데이터 세트 간에 데이터를 상호 연결하여 시스템에 대한 상태의 계층화된 표현을 빌드하는 것이 중요합니다.

코드 및 인프라 계측

모든 운영 데이터가 저장되고 모든 원격 분석이 수집되는 단일 위치에서 사용할 수 있도록 하려면 통합 데이터 싱크 가 필요합니다. 예를 들어 직원이 웹 브라우저에서 메모를 만들 때 이 작업을 추적하고 요청이 카탈로그 API를 통해 Azure Event Hubs로 이동한 것을 확인할 수 있습니다. 여기에서 주석은 백그라운드 프로세서에 의해 포착되어 Azure Cosmos DB에 저장되었습니다.

Azure Monitor Log Analytics는 운영 데이터를 저장하고 분석하는 핵심 Azure 네이티브 통합 데이터 싱크 역할을 합니다.

  • Application Insights는 애플리케이션 로그, 메트릭 및 추적을 수집하기 위해 모든 애플리케이션 구성 요소에서 권장되는 APM(애플리케이션 성능 모니터링) 도구입니다. Application Insights는 각 지역의 작업 영역 기반 구성에 배포됩니다.

    예제 애플리케이션에서 Azure Functions 네이티브 통합을 위한 백 엔드 서비스에 대해 Microsoft .NET 6에서 사용됩니다. 백 엔드 애플리케이션이 이미 있으므로 Contoso Shoes는 Azure에서 새 Application Insights 리소스만 만들고 두 함수 앱에서 설정을 구성합니다APPLICATIONINSIGHTS_CONNECTION_STRING. Azure Functions 런타임은 Application Insights 로깅 공급자를 자동으로 등록하므로 추가 작업 없이 원격 분석이 Azure에 표시됩니다. 더 많은 사용자 지정 로깅을 위해 ILogger 인터페이스를 사용할 수 있습니다.

  • 중앙 집중식 데이터 세트는 중요 업무용 워크로드에 대한 안티패턴입니다. 각 지역에는 전용 Log Analytics 작업 영역과 Application Insights 인스턴스가 있어야 합니다. 전역 리소스의 경우 별도의 인스턴스를 사용하는 것이 좋습니다. 핵심 아키텍처 패턴을 보려면 Azure에서 중요 업무용 워크로드에 대한 아키텍처 패턴을 참조하세요.

  • 각 계층은 분석 및 상태 계산을 더 쉽게 하기 위해 동일한 Log Analytics 작업 영역으로 데이터를 보내야 합니다.

Diagram that shows an example of application health data collection.

상태 모니터링 쿼리

Log Analytics, Application Insights 및 Azure Data Explorer 모두 쿼리에 KQL(Kusto 쿼리 언어)을 사용합니다. KQL을 사용하여 쿼리를 빌드하고 함수를 사용하여 메트릭을 가져오고 상태 점수를 계산할 수 있습니다.

상태를 계산하는 개별 서비스는 다음 샘플 쿼리를 참조하세요.

Catalog API

다음 샘플에서는 카탈로그 API 쿼리를 보여 줍니다.


let _maxAge = 2d; // Include data only from the last two days
let _timespanStart = ago(_maxAge); // Start time for the time span
let _timespanEnd = now(-2m); // Account for ingestion lag by stripping the last 2m
// For time frame, compare the averages to the following threshold values
let Thresholds=datatable(MetricName: string, YellowThreshold: double, RedThreshold: double) [ 
    "failureCount", 10, 50, // Failed requests, anything non-200, allow a few more than 0 for user-caused errors like 404s
    "avgProcessingTime", 150, 500 // Average duration of the request, in ms
    ];
// Calculate average processing time for each request
let avgProcessingTime = AppRequests
| where AppRoleName startswith "CatalogService"
| where OperationName != "GET /health/liveness" // Liveness requests don't do any processing, including them would skew the results
| make-series Value = avg(DurationMs) default=0 on TimeGenerated from _timespanStart to _timespanEnd step 1m
| mv-expand TimeGenerated, Value
| extend TimeGenerated = todatetime(TimeGenerated), Value=toreal(Value), MetricName= 'avgProcessingTime';
// Calculate failed requests
let failureCount = AppRequests
| where AppRoleName startswith "CatalogService" // Liveness requests don't do any processing, including them would skew the results
| where OperationName != "GET /health/liveness"
| make-series Value=countif(Success != true) default=0 on TimeGenerated from _timespanStart to _timespanEnd step 1m
| mv-expand TimeGenerated, Value
| extend TimeGenerated = todatetime(TimeGenerated), Value=toreal(Value), MetricName= 'failureCount';
// Union all together and join with the thresholds
avgProcessingTime
| union failureCount
| lookup kind = inner Thresholds on MetricName
| extend IsYellow = iff(todouble(Value) > YellowThreshold and todouble(Value) < RedThreshold, 1, 0)
| extend IsRed = iff(todouble(Value) > RedThreshold, 1, 0)
| project-reorder TimeGenerated, MetricName, Value, IsYellow, IsRed, YellowThreshold, RedThreshold
| extend ComponentName="CatalogService"

Azure Key Vault

다음 샘플에서는 Azure Key Vault 쿼리를 보여 줍니다.

let _maxAge = 2d; // Include data only from the last two days
let _timespanStart = ago(_maxAge); // Start time for the time span
let _timespanEnd = now(-2m); // Account for ingestion lag by stripping the last 2m
// For time frame, compare the averages to the following threshold values
let Thresholds = datatable(MetricName: string, YellowThreshold: double, RedThreshold: double) [
    "failureCount", 3, 10 // Failure count on key vault requests
    ];
let failureStats = AzureDiagnostics
| where TimeGenerated > _timespanStart
| where ResourceProvider == "MICROSOFT.KEYVAULT"
// Ignore authentication operations that have a 401. This is normal when using Key Vault SDK. First an unauthenticated request is made, then the response is used for authentication
| where Category=="AuditEvent" and not (OperationName == "Authentication" and httpStatusCode_d == 401)
| where OperationName in ('SecretGet','SecretList','VaultGet') or '*' in ('SecretGet','SecretList','VaultGet')
// Exclude Not Found responses because these happen regularly during 'Terraform plan' operations, when Terraform checks for the existence of secrets
| where ResultSignature != "Not Found"
// Create ResultStatus with all the 'success' results bucketed as 'Success'
// Certain operations like StorageAccountAutoSyncKey have no ResultSignature; for now, also set to 'Success'
| extend ResultStatus = case ( ResultSignature == "", "Success",
                               ResultSignature == "OK", "Success",
                               ResultSignature == "Accepted", "Success",
                               ResultSignature);
failureStats
| make-series Value=countif(ResultStatus != "Success") default=0 on TimeGenerated from _timespanStart to _timespanEnd step 1m
| mv-expand TimeGenerated, Value
| extend TimeGenerated = todatetime(TimeGenerated), Value=toreal(Value), MetricName="failureCount", ComponentName="Keyvault"
| lookup kind = inner Thresholds on MetricName
| extend IsYellow = iff(todouble(Value) > YellowThreshold and todouble(Value) < RedThreshold, 1, 0)
| extend IsRed = iff(todouble(Value) > RedThreshold, 1, 0)

카탈로그 서비스 상태 점수

결국 다양한 상태 쿼리를 함께 연결하여 구성 요소의 상태점수를 계산할 수 있습니다. 다음 샘플 쿼리는 카탈로그 서비스 상태 점수를 계산하는 방법을 보여줍니다.

CatalogServiceHealthStatus()
| union AksClusterHealthStatus()
| union KeyvaultHealthStatus()
| union EventHubHealthStatus()
| where TimeGenerated < ago(2m)
| summarize YellowScore = max(IsYellow), RedScore = max(IsRed) by bin(TimeGenerated, 2m)
| extend HealthScore = 1 - (YellowScore * 0.25) - (RedScore * 0.5)
| extend ComponentName = "CatalogService", Dependencies="AKSCluster,Keyvault,EventHub" // These values are added to build the dependency visualization
| order by TimeGenerated desc

Azure Mission-Critical Online GitHub 리포지토리에서 더 많은 쿼리 예제를 참조하세요.

쿼리 기반 경고 설정

경고는 상태를 반영하거나 영향을 주는 문제에 즉시 주의를 기울입니다. 성능이 저하된(노란색) 상태 또는 비정상(빨간색) 상태로 상태 변경이 있을 때마다 책임 있는 팀에게 알림을 보내야 합니다. 상태 모델의 루트 노드에서 경고를 설정하여 솔루션의 상태 변경에 대한 비즈니스 수준 변경을 즉시 인식하도록 합니다. 그런 다음 상태 모델 시각화를 확인하여 자세한 정보를 얻고 문제를 해결할 수 있습니다.

이 예제에서는 Azure Monitor 경고를 사용하여 애플리케이션 상태의 변화에 대응하여 자동화된 작업을 추진합니다.

시각화를 위한 대시보드

구성 요소 중단이 전체 시스템에 미치는 영향을 신속하게 이해할 수 있도록 상태 모델을 시각화하는 것이 중요합니다. 상태 모델의 궁극적인 목표는 안정적인 상태의 편차에 대한 정보에 입각한 보기를 제공하여 신속한 진단을 용이하게 하는 것입니다.

시스템 상태 정보를 시각화하는 일반적인 방법은 계층화된 상태 모델 뷰를 대시보드의 원격 분석 드릴다운 기능과 결합하는 것입니다.

Screenshot that shows an example health model dashboard of a layered model above drill-down data tables.

대시보드 기술은 상태 모델을 나타낼 수 있어야 합니다. 인기 있는 옵션으로는 Azure 대시보드, Power BI 및 Azure Managed Grafana가 있습니다.

지식 점검

1.

시스템 구성 요소는 원격 분석을 어디에서 보내야 하나요?

2.

Log Analytics 로그를 쿼리하고 상태 점수를 계산하는 데 사용되는 언어는 무엇인가요?

3.

상태 모델링에 가장 적합한 대시보드 기술은 무엇인가요?