Monitoring App Services
Effective monitoring is crucial for understanding the health, performance, and resource utilization of your application services. This guide outlines the key tools and metrics available for monitoring your app services, helping you to proactively identify and resolve issues.
Key Monitoring Areas
When monitoring app services, focus on these core areas:
- Performance Metrics: Track response times, request rates, error rates, and CPU/memory usage.
- Availability: Ensure your service is accessible and responding to requests.
- Resource Utilization: Monitor disk space, network traffic, and database connections.
- Application Logs: Capture detailed information about application events, warnings, and errors.
- Security Events: Monitor for suspicious activity and potential security breaches.
Tools and Features
Azure Application Insights
Azure Application Insights is a powerful Application Performance Management (APM) service that is integrated with Azure App Service. It provides rich telemetry about your application's performance and usage.
Key features of Application Insights include:
- Live Metrics Stream: Real-time monitoring of application requests, performance, and failures.
- Performance Analysis: Identify performance bottlenecks and slow-running operations.
- Failure Analysis: Detect, diagnose, and prioritize exceptions and failures.
- Usage Analysis: Understand how users interact with your application.
- Alerting: Configure alerts based on predefined metrics or custom queries.
Azure Monitor
Azure Monitor is a comprehensive solution for collecting, analyzing, and acting on telemetry from your Azure and on-premises environments. It provides a unified view of application health and performance.
Key components of Azure Monitor for App Services:
- Metrics: Collects numerical data about your app service, such as CPU percentage, memory working set, HTTP server errors, and data in/out.
- Logs: Collects log data from your app service, including application logs, web server logs, and diagnostics logs.
- Alerts: Allows you to set up rules to trigger notifications or actions when specific conditions are met.
- Dashboards: Create custom dashboards to visualize key metrics and logs in one place.
Configuring Monitoring
Enabling Application Insights
To enable Application Insights for your App Service:
- Navigate to your App Service in the Azure portal.
- Under the "Monitoring" section, select "Application Insights".
- Click "Turn on Application Insights".
- Choose an existing Application Insights resource or create a new one.
- Click "Apply".
Configuring Diagnostic Logs
You can configure diagnostic logs to capture detailed information about your App Service:
- Navigate to your App Service in the Azure portal.
- Under the "Monitoring" section, select "Diagnostic logs".
- Choose the log categories you want to collect (e.g., AppServiceHTTPLogs, AppServiceAppLogs).
- Select a destination for your logs, such as a Storage account, Log Analytics workspace, or Event Hub.
- Click "Save".
Common Monitoring Metrics
Here are some of the most important metrics to monitor for your App Services:
| Metric | Description | Typical Threshold |
|---|---|---|
| CPU Percentage | The percentage of CPU utilized by the App Service instance. | < 70-80% (sustained) |
| Memory Working Set | The amount of physical memory used by the App Service instance. | < 80% of allocated memory |
| HTTP 5xx Errors | The number of server-side errors (5xx status codes) returned by the application. | 0 or very low |
| HTTP 4xx Errors | The number of client-side errors (4xx status codes) returned by the application. | Low and indicative of expected user behavior. |
| Requests | The total number of HTTP requests received by the App Service. | Monitor trends and spikes. |
| Response Time | The average time taken to respond to HTTP requests. | As low as possible, typically under 1-2 seconds. |
| Data In/Out | The amount of data transferred over the network by the App Service. | Monitor for unexpected spikes. |
Example: Setting up an alert for High CPU Usage
To set up an alert when CPU Percentage exceeds 80% for 15 minutes:
- Go to your App Service in the Azure portal.
- Under "Monitoring", select "Alerts".
- Click "Create rule".
- Scope: Select your App Service.
- Condition:
- Signal type: Metrics
- Signal name: CPU Percentage
- Alert logic: Threshold - Static
- Operator: Greater than
- Threshold value: 80
- Aggregation granularity (Period): 5 Minutes
- Frequency of evaluation: 1 Minute
- Actions: Configure an action group (e.g., send an email, trigger a webhook).
- Details: Name your alert rule (e.g., "AppService-HighCPU-Alert").
- Click "Create rule".
By leveraging Azure Application Insights and Azure Monitor, you can gain deep insights into the behavior of your app services, ensuring their stability and performance.