Monitoring Azure Container Instances (ACI)
This tutorial guides you through setting up monitoring for your Azure Container Instances (ACI) to gain insights into their performance and health.
Introduction to ACI Monitoring
Azure Container Instances (ACI) offers a simplified way to run containers in Azure without managing virtual machines. Effective monitoring is crucial for ensuring the reliability and performance of your containerized applications. ACI integrates with Azure Monitor, providing comprehensive tools for collecting, analyzing, and acting on telemetry from your containers.
Key Monitoring Components
- Azure Monitor Metrics: Track resource utilization (CPU, memory, network) of your ACI.
- Azure Monitor Logs: Collect and query logs generated by your containers.
- Container Insights: A recommended solution for monitoring ACI, offering pre-built dashboards and alerts.
- Activity Logs: Monitor control plane operations for your ACI resources.
Prerequisites
- An Azure subscription.
- An Azure Container Instance deployed. If you don't have one, you can create one using the Azure portal or Azure CLI.
Step 1: Enabling Container Insights
Container Insights provides a unified view of your ACI deployments. You can enable it for your ACI resources.
- Navigate to your ACI resource in the Azure portal.
- Under the 'Monitoring' section, select 'Insights'.
- If Container Insights is not enabled, you will be prompted to enable it. Follow the on-screen instructions.
This typically involves deploying a Log Analytics workspace and configuring the monitoring agent.
Step 2: Accessing Metrics
You can view key performance metrics for your ACI directly from the Azure portal.
- Go to your ACI resource in the Azure portal.
- Under 'Monitoring', select 'Metrics'.
- Choose the desired metric (e.g., 'CPU Usage Percentage', 'Memory Working Set').
- Select an appropriate aggregation (e.g., 'Average', 'Maximum').
- Set the time range to view the metric data over time.
You can also pin these charts to your Azure dashboard for quick access.
Step 3: Collecting and Querying Logs
To effectively troubleshoot and understand container behavior, you need to collect and query their logs.
Configuring Log Collection:
- Ensure your container application is configured to output logs to standard output (stdout) or standard error (stderr).
- When using Container Insights, it automatically collects logs from ACI.
Querying Logs with Kusto Query Language (KQL):
Logs are stored in a Log Analytics workspace. You can query them using KQL.
ContainerLogs
| where ContainerGroupName == "your-aci-group-name"
| where TimeGenerated > ago(1h)
| project TimeGenerated, LogMessage
| order by TimeGenerated desc
Replace "your-aci-group-name" with the actual name of your ACI resource.
Step 4: Setting Up Alerts
Proactive alerting helps you respond to potential issues before they impact your users.
- Navigate to your Log Analytics workspace or ACI resource in the Azure portal.
- Go to 'Alerts' and click 'Create alert rule'.
- Configure the conditions based on metrics (e.g., high CPU usage) or log queries (e.g., specific error messages).
- Define the action group to notify you (e.g., email, SMS, webhook).
Example Alert Condition (Log-based):
ContainerLogs
| where LogMessage contains "error"
| summarize count() by bin(TimeGenerated, 5m)
| where count_ > 0
Conclusion
By leveraging Azure Monitor's capabilities, you can gain deep visibility into your ACI deployments, ensuring their health, performance, and availability. Regular monitoring and timely alerts are key to maintaining robust containerized applications in Azure.