Saturday, May 7, 2011

Initializing Windows Azure Diagnostic – Part 2

As you have read in my previous article how to initialize Windows Azure diagnostic monitor. Now we will see how to collect different diagnostic data. I am defining a connection string for the role. For that right click on the role and click on properties. Now from the connection tab you can add configuration string.
clip_image002

1) Collecting data from event logs
Open the Role entry point class. Add following code to the OnStart() function
var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.WindowsEventLog.DataSources.Add("System!*");
config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Warning;
config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

So, first you need to get DiagnosticMonitorConfiguration object. Then you can add channel to the datasource. You can add multiple channels. Windows Azure cannot log Security channel. You can define log level filter, so that only those logs are transferred. You have to define schedule transfer period, so that after that time span logs are transferred to the account you specified in the configuration. Now start the diagnostic monitor with the connection and new configuration.

2) Collect data from Performance Counters
Open the Role entry point class. Add following code to the OnStart() function

var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\Processor(_Total)\% Processor Time",
SampleRate = TimeSpan.FromMinutes(1.0),
});
config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5.0);
DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

Here I have defined a performance counter which takes sample for processor time in every minute. You can add multiple performance counters in the data souce. And then transfer the log to azure account defined in the connection string after every 5 minutes.

3) Collect data from IIS logs
IIS logs are collected only for web role because worker and VM roles don’t run under IIS.
To enable IIS logging add following code to the web.config.

<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure, Module, Page, AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server"
areas="Authentication, Security, Filter, StaticFile, CGI, Compression, Cache, RequestNotifications, Module"
verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="400-599" />
</add>
</traceFailedRequests>
</tracing>
After adding this code IIS logs are automatically logged. No additional API calls are required.

4) Collect data from crash dumps
In the role entry point class add the following code;

Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(true);

Pass true for enabling complete crash dump data, or false for partial crash dump data.

Initializing Windows Azure Diagnostics- Part 1

As we have seen in my previous blog that some of diagnostics data is stored in table, while some in blob. For collecting diagnostics data, we must initialize Windows Azure diagnostic monitor. Windows Azure diagnostic monitor runs in Windows Azure and in the compute emulator and collects diagnostic data for a role instance. Only Windows Azure Logs, Windows Azure Diagnostic Infrastructure Logs and IIS logs are configured in the diagnostic monitor by default. We can collect other diagnostic data by importing diagnostic module. A role instance that imports the Diagnostic module starts, it starts the diagnostic monitor.
To start diagnostic monitor for a role open the role entry point class and make sure that you are using Microsoft.WindowsAzure.Diagnostics namespace in the class. Now on the Azure service project right click on the role and click Properties. Here I am configuring a web role.
clip_image002
Now in the configuration section check enable diagnostics. And specify the account credentials
clip_image004
You can either use development storage or can give your account credentials. Just click on “…” and will ask for the credentials.
clip_image006
Now when you open your .cscfg file it has a new setting for the webrole like
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccountName;AccountKey=myAccountKey" />
</ConfigurationSettings>

And in the .csdef file it import the module like:
<Imports>
<Import moduleName="Diagnostics" />
</Imports>

If you are using a web role or worker role template for creating roles then in the web.config or app.config following code is added. Or you can just inherit a class from RoleEntryPoint and add the following code in the config file.


<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>


 If you want to create a web role just override OnStart() method, and if you want to create a workerrole override OnStart() and Run() method. We will see it in my next article.

Friday, March 11, 2011

Understanding Diagnostics in Windows Azure

 

Windows Azure diagnostics provides facility to store diagnostics data. Azure diagnostics supports logging and monitoring of diagnostics data. It uses blob service or table service to save diagnostics data, depending on the diagnostics data. Before logs are saved in a container they are indexed in WADDirectoriesTable table in the storage account.
Following diagnostics data is stored in table storage:
Data Source Table name in Azure Storage Detail
Windows Azure Logs WADLogsTable These are the application logs dumped from the application.
Windows Azure Diagnostics Infrastructure Logs WADDiagnosticInfrastructureLogsTable These are the logs about running of diagnostics service.
Windows Event logs WADWindowsEventLogsTable These are the logs generated on the instance where logs are running.
Performance counters WADPerformanceCountersTable These are the performance matrices like memory utilization, processor utilization, response time etc.
Following diagnostics data is stored in blob storage:
Data Source Container name in azure storage Detail
IIS Logs wad-iis-logfiles These are the IIS logs generated by role instances.
Failed Request Logs wad-iis-failedreqlogfiles These are the IIS failed requests logs generated by role instances.
Crash Dumps wad-crash-dumps These are the logs generated on the application crash.

Wednesday, March 9, 2011

Deploying an application in Windows Azure

In the previous article we have seen how to create a Hello World application in azure. In this article we will see how to deploy it in Windows azure. To deploy an application in azure, two files are needed- a package file and a configuration file. Configuration file is already in CloudService1 named ServiceConfiguration.cscfg. Now for the package file just right click on the CloudService project and click Publish.
clip_image002
Then it asks to create just a package file or to deploy it in azure.
clip_image004
If first option is selected then it creates the package file and opens the explorer.
clip_image006
Once we have a package file (.cspkg) and configuration file (.cscfg) then we can deploy it through management portal, or azure service management cmdlets, or Cerebrata’s CloudStorageStudio, or Cerebrata’s Azure management cmdlets. We can directly upload it through visual studio also, if we select second option from publish dialog. It needs a subscriptionId and a X509 v3 certificate as shown below:
clip_image008
Then we have to provide deployment environment and storage account.
Whichever option we had selected, we need:
a) A Windows Azure Subscription – when we sign up for azure, a subscription is associated with our live Id.
b) A Windows Azure Hosted Service – we need to create a hosted service for deployment. It provides two deployment environment- production and staging.
c) A Windows Azure storage account – When we deploy through visual studio then package file is first uploaded in blob storage of the storage account, and then deployed from the blob service.
So summarizing deployment through management portal in some simple steps:
1) We need a package file and a configuration file to deploy.
2) To create a package file click publish and create package only option from project.
3) Sign In the management portal.
4) Create a new hosted Service if you want to deploy in a new service.
5) Then in deployment environment either deploy in production or staging.
6) Then start the deployment.
7) You can see the progress of the deployment on the portal
8) To delete a deployment first click on stop, and when it is stopped delete it.

Tuesday, March 1, 2011

Creating a “Hello world” application in Azure

In this article we will see how to create a “Hello World!!!” application in azure in .net. I had used Visual Studio 2010 along with azure SDK 1.3 installed. Start visual studio and select a new project. In the cloud template select Windows Azure Cloud Service.
clip_image002
Once you click OK. It asks for selecting a Role. Here we are adding an ASP.Net Web role.
clip_image004
It will create two projects- CloudService1 (Azure Service Project) and WebRole1 (ASP.net Project). The Azure service project is used to configure the application, and to create a deployment package. ASP.Net project is like a normal web project.
clip_image006
Here I removed header div from the SiteMaster.
clip_image008
And add a text “Hello World!!!!” in the default.aspx
clip_image010
And we are done. Now Select Cloud Service as your startup project and run it. When you run it, azure simulation environment is initialized, and it starts development storage and development fabric.
clip_image012
And here you can see your Hello World!!!
clip_image014
If you select WebRole1 as your startup project and run the solution. It will run as a normal ASP.Net project and hosted locally on localhost.
If you click on the Azure Simulation and select “Show development Fabric UI” then it will show the azure services running on your machine.
clip_image016
Here My CloudService1 is running having a single instance of WebRole.
clip_image018

Thursday, February 24, 2011

Overview of Windows Azure

Windows Azure


Windows azure is Microsoft’s cloud platform. It includes Windows Azure operating system that serves as the Platform-as-a-Service (PAAS) and Infrastructure-as-a Service (IAAS). In order to understand AAS lets take an example-

1) To deploy or use software we first need servers, firewalls, switches etc.

2) Once server is setup then we need an OS then application server or database.

3) Then we have to install the actual application.

So we need some infrastructure, then platform and software. Windows Azure provides platform and infrastructure by providing a scalable and cost-effective computing, storage and networking resources on demand.

Windows Azure has three main components in azure: Compute, Storage and Fabric.

1) Windows Azure Compute:

Windows azure provides hosting environment for managed code. It provides computation service through roles. Windows azure supports 3 types of roles:

a) Web roles used for web application programming and supported by IIS7

b) Worker roles used for background processing of web roles.

c) Virtual Machine (VM) roles used for migrating windows server applications to Windows azure in an easy way.

Within a subscription one can have zero or more hosted service. Each hosted service can have deployment- either production or staging. And each deployment can have one or more roles of any types. Each role can have multiple instances.

2) Windows Azure Storage:

Windows azure provides storage in cloud. It provides 4 types of storage services:

a) Queues for messaging between web roles and worker roles.

b) Tables for storing structural data.

c) BLOBs (Binary Large Objects) to store text, files or large data.

d) Windows Azure Drives (VHD) to mount a page blob. These can be uploaded and downloaded via blobs.


3) Windows Azure AppFabric:

AppFabric provides infrastructure services for developing, deploying and managing Windows azure application. It provides 5 services:

a) Service bus It provides secure connectivity between distributed and disconnected applications in cloud.

b) Access control It grants access control to application and services based on the identity user. So the authorization decisions are pulled out from application into a set of rules that can transform incoming security claims into claims that applications understand.

c) Caching It provides caching for high speed access, scaling, and high availability of data to application. It is available for developer preview only.

d) Integration It provides integration between windows azure application and other SAAS. It will be available by CTP 2011.

e) Composite App It provides a hosting environment for WCF web services and workflows. It will be available by CTP 2011.

Monday, June 28, 2010

Creating commands in powerShell

Learn how to create commands in few simple steps:
For creating commands in powerShell, I had installed templates for it, which I get from here: http://channel9.msdn.com/ShowPost.aspx?PostID=256835. There are VB.NET and C# ones.
clip_image002
clip_image004
1) Now select a powerShell project as shown:
clip_image006
The project contains a PSSnapin file and a reference to the assembly System.Management.Automation
2) In the PSSnapIn.cs fill information as required.
[RunInstaller(true)]
public class WindowsPowerShell1SnapIn : PSSnapIn
{
public override string Name
{
get { return "MyFirstSnapIn"; }
}
public override string Vendor
{
get { return "Reeta"; }
}
public override string VendorResource
{
get { return "WindowsPowerShell1,"; }
}
public override string Description
{
get { return "Registers the CmdLets and Providers in this assembly"; }
}
public override string DescriptionResource
{
get { return "WindowsPowerShell1,Registers the CmdLets and Providers in this assembly"; }
}
}
3) Now add a new cmdlet class.
clip_image008
4) In this cmdlet we simply add a value to a parameter and output it.
[Cmdlet(VerbsCommon.Get, "Hello", SupportsShouldProcess = true)]
In this attribute “Get” is our verb and “Proc” is subject. Different verbs can be used. Read http://msdn.microsoft.com/en-us/library/ms714428(VS.85).aspx for more information.
5) To add parameter write :
[Parameter(Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enter a name")]
[ValidateNotNullOrEmpty]
public string Name
{
get;
set;
}
To validate a parameter we can add different attribute on a parameter. We can add help message for the parameter By “HelpMessage”. We can indicate that a parameter is mandatory by adding “Mandatory= true”. We can add position for a parameter.
6) Now add a code to write the parameter value in ProcessRecord(). When this command runs it execute code written in Processrecord().
WriteObject will write values on the commandlet.
7) For running the power shell we first need to install the dll.
On visual studio command prompt use - installUtil yourAssemblyPath.dll
8) Now add the SnapIn in the power shell using command:
Add-PSSnapin MyFirstSnapIn
clip_image010
9) Now get the registered SnapIn list by command :
Get-PSSnapIn –registered
10) Now run the command using:
Get-Hello –Name Reeta
It will output – Hello Reeta
Since we had written position in the Parameter attribute we don’t need to specify –Name. if we write- Get-Hello Reeta, it gives same output.
If we don’t provide any parameter then it says that it is mandatory.
These are just simple steps for creating a command in powerShell. I get help from this blog http://blogs.msdn.com/b/daiken/archive/2007/02/07/creating-a-windows-powerShell-cmdlet-using-the-visual-studio-windows-powerShell-templates.aspx