Hey Checkyourlogs Fans,
Azure Web Apps is a robust platform-as-a-service (PaaS) offering that enables developers to seamlessly deploy, manage, and scale web applications. However, troubleshooting issues in production environments can be daunting, especially when problems like slow response times, application crashes, or deployment failures arise. To aid in diagnosing and resolving these problems, Microsoft provides the Kudu tool as part of the Azure Web Apps platform. This blog post dives deep into using Kudu, exploring its various functionalities and detailing how to use it effectively for troubleshooting.
What is Kudu?
Kudu is a set of diagnostic and management tools built into Azure Web Apps. It allows developers and administrators to interact directly with their application environments. It provides many features, including the ability to view logs, examine environment variables, interact with files, run diagnostic commands, and even inspect the application’s running processes.
Kudu is accessible from the Azure Portal via your Azure Web App’s “Advanced Tools” tab. Once opened, it provides a web-based interface where you can use several troubleshooting and administrative features, such as:
- A Command Prompt and PowerShell interface
- File system access for uploading and downloading files
- Process Explorer for monitoring running processes
- Diagnostic logs
- Performance monitoring tools
In this guide, we’ll explore how to use these features effectively to diagnose and resolve issues with your Azure Web Apps.
Accessing Kudu
To start troubleshooting with Kudu, follow these steps:
- Navigate to your Web App in the Azure Portal:
- Open the Azure Portal and search for your Web App under App Services.
- Go to Advanced Tools:
- In the left-hand menu, scroll to Advanced Tools and click on it. This will redirect you to the Kudu console for your Web App.
- Launch Kudu:
- You’ll now see the Kudu interface, which contains several tabs, such as Debug Console, Process Explorer, Environment, and more.
Kudu Features and How to Use Them
1. Debug Console (CMD and PowerShell)
The Kudu console provides a Command Prompt and PowerShell interface for interacting with your Web App’s underlying file system and executing scripts.
Accessing the Debug Console:
- In the Kudu interface, click on the Debug Console tab.
- You’ll be prompted to choose between CMD and PowerShell.
Key Uses of the Debug Console:
- Running diagnostic commands: You can run common commands like ipconfig, ping, or custom scripts to test network connectivity and troubleshoot performance.
- Managing files: You can view, upload, or delete files directly from the console, which is useful when you need to adjust configuration settings or add debugging logs.
Example Commands:
- List files and directories:
dir
This will display all files and folders in your web app’s root directory.
- View contents of a file:
type <filename>
This command is handy for quickly viewing logs or configuration files.
- Running a custom script: You can also upload PowerShell or batch scripts to the root directory and run them directly from the command line.
Uploading and Downloading Files via Kudu:
- Uploading files:
- In the Debug Console, navigate to the directory where you want to upload the file.
- Click on the Upload button in the top-right corner.
- Select the file from your local machine and click “Open.”
- Downloading files:
- Navigate to the file you want to download.
- Right-click on the file and choose Download.
These file management capabilities are invaluable when adding debugging files or extracting logs for offline analysis.
2. Process Explorer
Kudu’s Process Explorer allows you to monitor the processes running on your Azure Web App. This is particularly useful for identifying performance bottlenecks, memory leaks, or rogue processes consuming excessive CPU or memory.
How to Use Process Explorer:
- Open the Process Explorer tab.
- You’ll see a list of processes running on your Web App, including the w3wp.exe (the IIS Worker Process responsible for running your web app) and other background services.
Key Information:
- PID (Process ID): Each process has a unique Process ID, which can help identify specific instances of the application worker process.
- CPU and Memory Usage: Each process’s CPU and memory consumption is displayed in real-time, allowing you to detect resource-intensive processes.
Common Scenarios:
- High CPU Usage: If your web app is slow or unresponsive, check if any process consumes an unusually high amount of CPU.
- Memory Leaks: A sudden or consistent increase in memory usage by w3wp.exe could indicate a memory leak, which may require debugging of the application code or libraries.
You can also kill processes directly from the Process Explorer by clicking the Kill button next to the process. This is useful when you need to reset a misbehaving process or free up resources for other services.
3. Environment Information
The Environment tab in Kudu provides detailed information about the environment in which your web app is running. This includes:
- Environment Variables: This section shows all the system environment variables available to your app, such as PATH, TEMP, and custom environment variables you’ve defined.
- Runtime Information: Information about your app’s framework version, platform, and other dependencies.
Troubleshooting with Environment Variables:
Environment variables can help identify issues with your application configuration. For instance:
- Missing Environment Variables: If your app relies on a specific variable (like DATABASE_URL) and is missing, it may fail to connect to external services. To resolve these issues, you can inspect and modify environment variables from the Azure Portal and restart the app.
4. Log Stream and Diagnostic Logs
Viewing its logs is one of the most critical aspects of troubleshooting any application. Kudu provides access to real-time logs and historical log files.
Accessing the Log Stream:
- Go to your web app’s log stream under the monitoring section on the Azure Portal.
- Enable Application Logging (Filesystem) and Web Server Logging to ensure logs are written to disk.
- In the Kudu console, navigate to the LogFiles directory in the Debug Console to view specific logs, including HTTP and application logs.
Types of Logs:
- HTTP Logs: These provide details of requests to your application, including response codes, request paths, and user agents. It’s helpful when diagnosing 404 (Not Found) or 500 (Internal Server Error) issues.
- Application Logs: If your app is configured to write logs (e.g., using logging libraries in .NET, Node.js, or Python), you can access them in the LogFiles directory.
5. Using Diagnostic Tools in Kudu
In addition to the above, Kudu offers several diagnostic tools to help you troubleshoot complex issues:
Memory Dump and Profiling
You can generate memory dumps and perform performance profiling directly from the Kudu console for advanced troubleshooting.
- Memory Dump: This can be particularly useful for debugging memory leaks or crashes. You can capture a snapshot of the current memory usage and download the dump for offline analysis using debugging tools like WinDbg.
- Profiling: The profiler helps capture performance data, which helps identify performance bottlenecks, such as slow code paths or resource contention.
6. Custom Deployment Scripts
Another powerful feature of Kudu is its support for custom deployment scripts. If you encounter issues during deployment or want to customize the process, you can create a custom deployment file or use a deployment script tailored to your app.
7. App Service Diagnostics
In addition to Kudu, Azure provides App Service Diagnostics for deeper insights into application performance and issues. This tool can be accessed from the Diagnose and solve problems blade of your Web App in the Azure Portal.
Key Features:
- Availability and Performance: Detects downtime, high latency, and other performance-related issues.
- Configuration and Management: Provides insights into configuration issues causing failures.
- Health Checks: Regular health checks of your web app can help identify issues before they escalate into critical outages.
Thanks,
Dave