Thursday, January 20, 2011

Windows Azure Developer and Project Guidance Initializing and Configuring Diagnostic Data Sources

Windows Azure Developer and Project Guidance
Monitoring Options
Windows Azure is a cloud services operating system that serves as the development, service hosting and service management environment for the Windows Azure platform. Windows Azure provides developers with on-demand compute and storage to host, scale, and manage web applications on the internet through Microsoft datacenters.
Diagnostic API (Diagnostic Data Collection)
A separate storage account will be created to store diagnostic data, ensuring that application and monitoring data is separated and can be accessed independently.
The Windows Azure Web and Worker roles must be instrumented to enable collection for the Windows Azure diagnostic data sources shown below

Data Source
Windows Azure platform setting
Details
Stored On
Windows Azure logs
Enabled
·         Requires that trace listener be added to web.config or application.config:  <system.diagnostics>
·         The ScheduledTransferPeriod is set to 1 minute.
·         The Windows Azure diagnostics agent filter verbosity level will be set for Warning (and higher).
WADLogsTable (table)
Windows event logs
Enabled
·         Events from application and system event logs
·         The ScheduledTransferPeriod is set to 1 minute.
·         The Windows Azure diagnostics agent filter verbosity level will be set for Warning (and higher).
WADWindowsEventLogsTable (table)
IIS 7.0 Logs
Enabled
·         The ScheduledTransferPeriod is set to 10 minutes.
wad-iis-logfiles (blob container)
IIS7 Failed Request logs
Enabled
·         Enable tracing for all failed requests with status codes 400–599 under the system.webServer section of the role's web.config file.
·         The ScheduledTransferPeriod is set to 10 minutes.
wad-iis-failedreqlogfiles (blob container)
Performance counters
Enabled
·         Enable logging for performance counters.
·         Set the SampleRate and ScheduledTransferPeriod to 5 minutes.
WADPerformanceCountersTable (table)


Azure Storage Guidance and Policies
A separate storage account is created to store diagnostic data. The diagnostic data stored in Windows Azure storage is used for monitoring as well as to create application baselines.

Data Source
Windows Azure platform setting
Retention period
Stored On
Windows Azure logs
Enabled
1 week
WADLogsTable (table)
Windows event logs
Enabled
1 month
WADWindowsEventLogsTable (table)
IIS 7.0 Logs
Enabled
1 week
wad-iis-logfiles (blob container)
IIS7 Failed Request logs
Enabled
1 week
wad-iis-failedreqlogfiles (blob container)
Performance counters
Enabled
1 month
WADPerformanceCountersTable (table)

For some data sources, the size of the data can be estimated in advance (performance counters); for other sources (Microsoft Internet Information Services [IIS} logs), it cannot.
These are the minimal retention requirements; they can be change based on business or operational requirements.
Application-specific data is not stored in the same store as the diagnostic data and is not subject to this policy.
Enable Windows Azure Diagnostics Data Sources
The Windows Azure diagnostic monitor runs in Windows Azure and collects data locally for the role instance. The DiagnosticMonitor class provides methods for working with the diagnostic monitor from code running within a role.
To initialize the diagnostic monitor, override the RoleEntryPoint.OnStart method. Within this method, call the DiagnosticMonitor.Start method to start the diagnostic monitor.
The code in the following example starts the diagnostic monitor with the default initial configuration. The default initial configuration collects the Windows Azure, Windows Azure Diagnostic Infrastructure, and IIS 7.0 logs:



Code snippet:
 public override bool OnStart()
{
//Get Default Config
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
//Windows Performance Counters
List<string> counters = new List<string>();
counters.Add(@"\Processor(_Total)\% Processor Time");
counters.Add(@"\Memory\Available Mbytes");
counters.Add(@"\TCPv4\Connections Established");
counters.Add(@"\ASP.NET Applications(__Total__)\Requests/Sec");
counters.Add(@"\Network Interface(*)\Bytes Received/sec");
counters.Add(@"\Network Interface(*)\Bytes Sent/sec");
foreach (string counter in counters)
{
PerformanceCounterConfiguration counterConfig = new PerformanceCounterConfiguration();
counterConfig.CounterSpecifier = counter;
counterConfig.SampleRate = TimeSpan.FromMinutes(5);
config.PerformanceCounters.DataSources.Add(counterConfig);
}
config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
//Windows Event Logs
config.WindowsEventLog.DataSources.Add("System!*");
config.WindowsEventLog.DataSources.Add("Application!*");
config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Warning;
//Azure Trace Logs
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
//Crash Dumps
CrashDumps.EnableCollection(true);
//IIS Logs
config.Directories.ScheduledTransferPeriod=TimeSpan.FromMinutes(10);
DiagnosticMonitor.Start("DiagnosticsConnectionString", config);
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
RoleEnvironment.Changing += RoleEnvironmentChanging;
return base.OnStart();
}



Using the TraceSource to Log Events
Configuration file sections (configure the Windows Azure trace listener for this specific trace source)
<system.diagnostics>
<sources>
<source name="MyTraceSource" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<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>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="Warning"/>
</switches>
</system.diagnostics>

C# code (use the TraceSource to log events)
public static class Logging
{
private static TraceSource Ts = new TraceSource("MyTraceSource", SourceLevels.Warning);

public static void Write(TraceEventType traceType, int eventId, string message)
{
//Log event
Ts.TraceEvent(traceType, eventId, message);
}
}
Web.Config Setting for Failed Request Tracing
<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>        
For Details on Implementation, Refer

Wednesday, January 12, 2011

Windows Azure API Certificate Creation UI and Command Prompt

How to Create a x509 Certificate for the Windows Azure Management API
1.       Load the IIS 7 management console. I’m assuming here you have IIS7 installed since its required for the Windows Azure SDK.
2.       Click on your Server.
3.       Double Click Server Certificates in the IIS Section in the main panel.
4.       Click Create Self-Signed Certificate… in the Actions panel.
5.       Give it a Friendly Name.
6.       Close IIS Manager.
7.       Open Certificate Manager (Start->Run->certmgr.msc)
8.       Open Trusted Root Certification Authorities, then Certificates.
9.       Look for your certificate (Tip: Look in the Friendly Name column).
10.    Right Click your certificate, then choose All Tasks, then Export…
11.    In the Wizard, choose No, do not export the private key, then choose the DER file format.
12.    Give your cert a name. (remember to call it something.cer).
13.    Navigate to the Windows Azure Portalhttp://windows.azure.com
14.    Click the Account Tab, then click Manage My API Certificates.
15.    Browse to the certificate file you created earlier and upload it.
16.    Done!



How to Create Windows Azure API certificates through command prompt
1.      use makecert.exe (which ships with the Windows SDK) and use a command like the below:
makecert -r -pe -a sha1 -n "CN=Certificate Name" -ss My -len 2048 -sp "Microsoft Enhanced RSA and AES Cryptographic Provider" -sy 24 APICert.cer
Usage: MakeCert [ basic|extended options] [outputCertificateFile]
Basic Options
 -sk  <keyName>         Subject's key container name; To be created if not present
 -pe                             Mark generated private key as exportable
 -ss  <store>                 Subject's certificate store name that stores the output certificate
 -sr  <location>            Subject's certificate store location.<CurrentUser|LocalMachine>. 
Default to 'CurrentUser'
 -#   <number>            Serial Number from 1 to 2^31-1.  Default to be unique
 -$   <authority>          The signing authority of the certificate
                        <individual|commercial>
 -n   <X509name>       Certificate subject X500 name (eg: CN=Fred Dews)
 -?                                Return a list of basic options
 -!                                 Return a list of extended options




The next step is to upload the .cer file to the developer portal to let Windows Azure know that it should trust the certificate for API operations on your projects. The portal now has a new section called “API Certificates” under the Account tab where one can do this.


Tuesday, January 11, 2011

How to Create a x509 Certificate for the Windows Azure Management API

1.       Load the IIS 7 management console. I’m assuming here you have IIS7 installed since its required for the Windows Azure SDK.
2.       Click on your Server.
3.       Double Click Server Certificates in the IIS Section in the main panel.
4.       Click Create Self-Signed Certificate… in the Actions panel.
5.       Give it a Friendly Name.
6.       Close IIS Manager.
7.       Open Certificate Manager (Start->Run->certmgr.msc)
8.       Open Trusted Root Certification Authorities, then Certificates.
9.       Look for your certificate (Tip: Look in the Friendly Name column).
10.    Right Click your certificate, then choose All Tasks, then Export…
11.    In the Wizard, choose No, do not export the private key, then choose the DER file format.
12.    Give your cert a name. (remember to call it something.cer).
13.    Navigate to the Windows Azure Portalhttp://windows.azure.com
14.    Click the Account Tab, then click Manage My API Certificates.
15.    Browse to the certificate file you created earlier and upload it.
16.    Done!