Azure
AzureIntermediate

Azure Monitoring and Observability: Implementation Guide

4 min read
azuremonitoringobservabilityloggingalerts

TL;DR

Master Azure monitoring and observability with this comprehensive guide covering Azure Monitor, Log Analytics, Application Insights, and best practices for cloud monitoring.

Azure Monitoring and Observability: A Complete Implementation Guide

Effective monitoring and observability in Azure are crucial for maintaining reliable and performant cloud applications. This guide covers implementation details for Azure Monitor, Log Analytics, and Application Insights.

$1

Key monitoring services in Azure:

Service Purpose Key Features
Azure Monitor Platform metrics Real-time monitoring, alerts
Log Analytics Log management Query, analysis, retention
Application Insights Application monitoring APM, user analytics
Network Watcher Network monitoring Connectivity, performance

$1

$1

``powershell

Enable diagnostic settings

Set-AzDiagnosticSetting

-ResourceId $vm.Id

-WorkspaceId $workspaceId

-Enabled $true

-Category @("AllMetrics")

-MetricCategory @(

"CPU",

"Memory",

"Network",

"Disk"

)

Create metric alert

New-AzMetricAlertRule

-Name "HighCPU"

-ResourceGroupName "MonitoringRG"

-Location "East US"

-TargetResourceId $vm.Id

-MetricName "Percentage CPU"

-Operator GreaterThan

-Threshold 90

-WindowSize "00:05:00"

-TimeAggregationOperator Average

`

$1

`json

{

"name": "HighMemoryAlert",

"type": "Microsoft.Insights/metricAlerts",

"location": "global",

"properties": {

"description": "Alert when memory usage exceeds 90%",

"severity": 2,

"enabled": true,

"scopes": ["[parameters('resourceId')]"],

"evaluationFrequency": "PT1M",

"windowSize": "PT5M",

"criteria": {

"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",

"allOf": [

{

"name": "HighMemory",

"metricName": "Available Memory Bytes",

"operator": "LessThan",

"threshold": 1073741824,

"timeAggregation": "Average"

}

]

},

"actions": [

{

"actionGroupId": "[parameters('actionGroupId')]"

}

]

}

}

`

$1

$1

`powershell

Create Log Analytics workspace

New-AzOperationalInsightsWorkspace

-ResourceGroupName "MonitoringRG"

-Name "MyWorkspace"

-Location "East US"

-Sku "PerGB2018"

Configure data retention

Set-AzOperationalInsightsWorkspace

-ResourceGroupName "MonitoringRG"

-Name "MyWorkspace"

-RetentionInDays 90

``

$1

`kusto

// CPU usage by VM

Perf

| where ObjectName == "Processor" and CounterName == "% Processor Time"

| summarize AvgCPU = avg(CounterValue) by Computer, bin(TimeGenerated, 1h)

| render timechart

// Failed authentication attempts

SecurityEvent

| where EventID == 4625

| summarize FailedAttempts = count() by TargetAccount, bin(TimeGenerated, 1h)

| order by FailedAttempts desc

// Storage account operations

StorageBlobLogs

| where OperationName contains "Write"

| summarize DataWritten = sum(RequestBodySize) by AccountName, bin(TimeGenerated, 1d)

`

$1

$1

`csharp

public void ConfigureServices(IServiceCollection services)

{

services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);

services.ConfigureTelemetryModule((module, o) =>

{

module.EnableSqlCommandTextInstrumentation = true;

});

services.ConfigureTelemetryModule((module, o) =>

{

module.CollectionOptions.TrackExceptions = true;

});

}

`

$1

`csharp

public class OrderController : Controller

{

private readonly TelemetryClient _telemetry;

public OrderController(TelemetryClient telemetry)

{

_telemetry = telemetry;

}

public async Task ProcessOrder(Order order)

{

var stopwatch = Stopwatch.StartNew();

try

{

// Process order

_telemetry.TrackEvent("OrderProcessed", new Dictionary

{

{ "OrderId", order.Id },

{ "Amount", order.Amount.ToString() }

});

return Ok();

}

catch (Exception ex)

{

_telemetry.TrackException(ex);

throw;

}

finally

{

stopwatch.Stop();

_telemetry.TrackMetric("OrderProcessingTime", stopwatch.ElapsedMilliseconds);

}

}

}

`

$1

$1

Metric Threshold Action
CPU Usage 90% Scale out
Memory Usage 85% Investigate leaks
Response Time 2 seconds Optimize code
Error Rate 1% Debug issues

$1

`json

{

"name": "PerformanceDashboard",

"type": "Microsoft.Portal/dashboards",

"properties": {

"lenses": {

"0": {

"order": 0,

"parts": {

"0": {

"position": {

"x": 0,

"y": 0,

"colSpan": 6,

"rowSpan": 4

},

"metadata": {

"inputs": [

{

"name": "resourceId",

"value": "[parameters('appServiceId')]"

},

{

"name": "timeframe",

"value": "Last24Hours"

}

],

"type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart"

}

}

}

}

}

}

}

``

$1

$1

Severity Response Time Notification Channel
Critical 5 minutes SMS, Email
Warning 15 minutes Email
Information 1 hour Email digest
Error 10 minutes Teams, Email

$1

1. Monitoring Strategy

- Define monitoring objectives

- Implement proper retention

- Configure appropriate alerts

- Regular monitoring reviews

2. Data Collection

- Collect relevant metrics

- Implement proper sampling

- Configure custom metrics

- Optimize data volume

3. Alert Management

- Define severity levels

- Configure proper thresholds

- Implement alert routing

- Regular alert reviews

4. Performance Monitoring

- Monitor key metrics

- Set up baselines

- Configure auto-scaling

- Regular performance reviews

$1

Common monitoring issues and solutions:

1. Data Collection Issues

- Check agent status

- Verify connectivity

- Review collection rules

- Check quotas

2. Alert Problems

- Verify alert conditions

- Check notification channels

- Review alert history

- Test alert rules

3. Performance Issues

- Analyze metrics

- Review logs

- Check dependencies

- Monitor resources

$1

After implementing monitoring:

1. Set up dashboards

2. Configure automated responses

3. Implement log analytics

4. Train operations team

5. Regular monitoring reviews

Remember to regularly review and update your monitoring implementation to maintain optimal visibility and control.

Why This Matters

Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.

Trade-offs to Consider

Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.

When NOT to Use This

Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.

Decision Framework

Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.