A day with .Net

My day to day experince in .net

Archive for April, 2012

On Demand Diagnostic Transfer

Posted by vivekcek on April 17, 2012

On Demand transfer helps you to transfer diganostic logs up on your request.

1. Create a simple azure web role project.In the WebRole.cs file add the below code in OnStart() method.This code will start diagnostic monitor with collecting performance counter logs.

 public override bool OnStart()
        {

            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            config.PerformanceCounters.DataSources.Add(

                new PerformanceCounterConfiguration()
                {

                    CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                    SampleRate = TimeSpan.FromSeconds(5)

                }

                );

            config.PerformanceCounters.BufferQuotaInMB = 200;
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            return base.OnStart();
        }

2. Build the project and it will be deployed to development fabric.Find the deployment-id from compute emulator.In our case it is “deployment16(14)”

3. Now create new windows form project and add reference to Azure SDK DLL’S from ref folder of 1.6 version.

Microsoft.WindowsAzure.ServiceRuntime.dll
Microsoft.WindowsAzure.Diagnostics.dll
Microsoft.WindowsAzure.StorageClient

4. Design a web from with a textbox and button.Enter the deploymentID in text box.

5. The full code of the form application is given below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.Diagnostics.Management;
namespace OnDeamnd
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DeploymentDiagnosticManager dianosticManger = new DeploymentDiagnosticManager("UseDevelopmentStorage=true", textBox1.Text);
            var myRoleInstanceDiagnosticManger = dianosticManger.GetRoleInstanceDiagnosticManagersForRole("DiagnosticWeb");

            DataBufferName dataSourceToTransfer = DataBufferName.PerformanceCounters;

            OnDemandTransferOptions transferoptions = new OnDemandTransferOptions();

            //Transfer log from past 1 hour
            transferoptions.From = DateTime.UtcNow - TimeSpan.FromHours(1.0);
            transferoptions.To = DateTime.UtcNow;
            //Message sended to queue when transfer completed
            transferoptions.NotificationQueueName = "transferoptionqueue";

            foreach (var instanceagnet in myRoleInstanceDiagnosticManger)
            {
                Guid requestID = instanceagnet.BeginOnDemandTransfer(dataSourceToTransfer, transferoptions);
            }

        }
    }
}

Posted in Azure | Tagged: | Leave a Comment »

Remotely Change Diagnostic Configuration Azure

Posted by vivekcek on April 13, 2012

In normal scenarios we configure diagnostic in WebRoles OnStart() method.But if we want to change the default configuration remotely,i mean from out side windows azure

using a windows application.We can done this using azure SDK DLL’s.

In this post i will show you how to add a performance counter to a deployed and running web role through a windows application.

1. Create a simple azure web role project.In the WebRole.cs file add the below code in OnStart() method.This code will start diagnostic monitor with default configuration

 public override bool OnStart()
        {
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            return base.OnStart();
                       
        }

2. Build the project and it will be deployed to development fabric.Find the deployment-id from compute emulator.In our case it is “deployment16(14)”

3. Now create new windows form project and add reference to Azure SDK DLL’S from ref folder of 1.6 version.

Microsoft.WindowsAzure.ServiceRuntime.dll
Microsoft.WindowsAzure.Diagnostics.dll
Microsoft.WindowsAzure.StorageClient

4. Design a web from with a textbox and button.Enter the deploymentID in text box.

5. The full code of the form application is given below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.Diagnostics.Management;
namespace DiagnosticConfig
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnConfigure_Click(object sender, EventArgs e)
        {
            DeploymentDiagnosticManager dmanger = new DeploymentDiagnosticManager("UseDevelopmentStorage=true",textBox1.Text);

            //Get the diagnostic mangers of all the instances of the role DignosticWeb
            var DiganosticMangerCollectionOfRoleInstances = dmanger.GetRoleInstanceDiagnosticManagersForRole("DignosticWeb");

            //Create a performance counter configuration that can be applied to all role instances.
            PerformanceCounterConfiguration ProcessorTime = new PerformanceCounterConfiguration() {

                CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                SampleRate=TimeSpan.FromMilliseconds(5.0)
              };
            //Apply performance counter to all role instances

            foreach (var instnceDiagnosticAgent in DiganosticMangerCollectionOfRoleInstances)
            {
                DiagnosticMonitorConfiguration instanceConfig = instnceDiagnosticAgent.GetCurrentConfiguration();
                instanceConfig.PerformanceCounters.DataSources.Add(ProcessorTime);
                instanceConfig.PerformanceCounters.BufferQuotaInMB = 200;
                instanceConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                instnceDiagnosticAgent.SetCurrentConfiguration(instanceConfig);

            }
        }
    }
}


Posted in Azure | Tagged: , , | 1 Comment »

Custom Error Logs -Azure

Posted by vivekcek on April 11, 2012

You can collect data in a custom log file. The custom log file is created in a local storage resource. You create the local storage resource by using the LocalResource Class and adding the local storage resource to the configuration of the Windows Azure diagnostic monitor. Perform the following steps to initialize the collection of custom log data.

1. Open the service definition file (CSDEF) using your favorite text editor and add the LocalStorage element. The following example shows the element added to the definition of a web role:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Diagnostics" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="DiagnosticWeb">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
    <LocalResources>
      <LocalStorage name="LocalResource" cleanOnRoleRecycle="false" sizeInMB="200" />
    </LocalResources>
  </WebRole>
</ServiceDefinition>

2. Add the following code in OnStart() of WebRole.cs

 LocalResource loc = RoleEnvironment.GetLocalResource("LocalResource");

            DirectoryConfiguration dirconfig = new DirectoryConfiguration();
            dirconfig.Container = "wad-customlogs-container";
            dirconfig.DirectoryQuotaInMB = loc.MaximumSizeInMegabytes;
            dirconfig.Path = loc.RootPath;

            var diaConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
            dirconfig.DirectoryQuotaInMB = 200;
            diaConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            diaConfig.Directories.DataSources.Add(dirconfig);
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diaConfig);

            File.Create(loc.RootPath + "vivek.txt");

            return base.OnStart();

The above code will transfer the file vivek.txt to wad-customlogs-container.

Posted in Azure | Tagged: , | Leave a Comment »

Trace Logs

Posted by vivekcek on April 11, 2012

Trace Logs can be configured by the below code.These logs are transferred to azure table named “WADLogsTable”

 public override bool OnStart()
        {
          
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            DiagnosticMonitorTraceListener tmp = new DiagnosticMonitorTraceListener();
            System.Diagnostics.Trace.Listeners.Add(tmp);
            config.Logs.BufferQuotaInMB = 200;
            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            System.Diagnostics.Trace.Write("Test");
            return base.OnStart();
            
        }

Posted in Azure | Tagged: , , | Leave a Comment »

Windows Event Logs

Posted by vivekcek on April 11, 2012

Windows event logs can be configured by the below code.These logs are transferred to azure table named “WADWindowsEventLogsTable”

 public override bool OnStart()
        {
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.WindowsEventLog.DataSources.Add("System!*");
            config.WindowsEventLog.BufferQuotaInMB = 200;
            config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Undefined;
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            return base.OnStart();

            
        }

Posted in Azure | Tagged: , | Leave a Comment »

Windows Azure Performance Counter Logs

Posted by vivekcek on April 11, 2012

The Following code in the OnStart() method of WebRole.cs can be used to transfer Performance Counter Logs.


 public override bool OnStart()
        {
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration()
                    {
                        CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                        SampleRate = TimeSpan.FromSeconds(5.0)
                    }
                );

            config.PerformanceCounters.BufferQuotaInMB = 200;
            config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            return base.OnStart();

            
        }

Performance counter log is stored in azure table “WADPerformanceCountersTable”

To view various performance counters in your system go to server explorer and expand your system name.

Processor Time Counter.

Some Performance Counters are:

Processor utilization : Processor\% Processor Time\_Total

Memory utilization: Memory\Available MBytes

Disk Utilization : PhysicalDisk\Bytes/sec\_Total

Network Utilization : Network Interface\Bytes Total/Sec\nic name

Posted in Azure | Tagged: , , | Leave a Comment »

Windows Azure Diagnostic Infrastructure Logs

Posted by vivekcek on April 11, 2012

Diagnostic Infrastructure Logs are collected by default.We can perform a scheduled transfer of this log into azure storage using the below code.

 public override bool OnStart()
        {
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            config.DiagnosticInfrastructureLogs.BufferQuotaInMB = 200;
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString",config);
            return base.OnStart();
        }

In the code initially we take the default configuration and change it via code.Diagnostic Infrastructure Logs are normally stored in azure table named “WADDiagnosticInfrastructureLogsTable”

Posted in Azure | Tagged: , | Leave a Comment »

Configuring Azure Diagnostic

Posted by vivekcek on April 10, 2012

The procedure for configuring azure diagnostic are.

1. Set the diagnostic connection string.

2. View the default Configuration file.

3. Change the default configuration file.

1. Set the diagnostic connection string.

In this step we will configure the the storage location for azure diagnostic data.It can be either your development storage or azure storage account.Currently i am going to use my development storage.Right click on your role select properties the select settings.Then Add Setting with Name=”Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString”, Type=”ConnectionString”,and Value=”UseDevelopmentStorage=true”

Now go to WebRole.cs file and add folllowing code to start diagnostic monitor with the connection string.

public override bool OnStart()
        {
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
            return base.OnStart();
        }


2. View the default Configuration file.

On deployment a diagnostic configuration file is created in blob container named “wad-control-container”.The file name will be like (deploymentId)(RoleName)(RoleInstanceName).This will be an xml file.

<?xml version="1.0"?>
<ConfigRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DataSources>
    <OverallQuotaInMB>4080</OverallQuotaInMB>
    <Logs>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <ScheduledTransferLogLevelFilter>Undefined</ScheduledTransferLogLevelFilter>
    </Logs>
    <DiagnosticInfrastructureLogs>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <ScheduledTransferLogLevelFilter>Undefined</ScheduledTransferLogLevelFilter>
    </DiagnosticInfrastructureLogs>
    <PerformanceCounters>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <Subscriptions />
    </PerformanceCounters>
    <WindowsEventLog>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <Subscriptions />
      <ScheduledTransferLogLevelFilter>Undefined</ScheduledTransferLogLevelFilter>
    </WindowsEventLog>
    <Directories>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <Subscriptions>
        <DirectoryConfiguration>
          <Path>c:\dftemp\Resources\2cd3f044-03f6-481c-8868-b1b0ee2ca957\directory\DiagnosticStore\FailedReqLogFiles</Path>
          <Container>wad-iis-failedreqlogfiles</Container>
          <DirectoryQuotaInMB>1024</DirectoryQuotaInMB>
        </DirectoryConfiguration>
        <DirectoryConfiguration>
          <Path>c:\dftemp\Resources\2cd3f044-03f6-481c-8868-b1b0ee2ca957\directory\DiagnosticStore\LogFiles</Path>
          <Container>wad-iis-logfiles</Container>
          <DirectoryQuotaInMB>1024</DirectoryQuotaInMB>
        </DirectoryConfiguration>
        <DirectoryConfiguration>
          <Path>c:\dftemp\Resources\2cd3f044-03f6-481c-8868-b1b0ee2ca957\directory\DiagnosticStore\CrashDumps</Path>
          <Container>wad-crash-dumps</Container>
          <DirectoryQuotaInMB>1024</DirectoryQuotaInMB>
        </DirectoryConfiguration>
      </Subscriptions>
    </Directories>
  </DataSources>
  <IsDefault>false</IsDefault>
</ConfigRequest>

You can use the ‘Azure Storage Explorer Tool’ from codeplex to see this blob file.

3. Change the default configuration file.

Consider that you want to change the diagnostic settings for ‘Windows Azure Infrastructure Logs’.In the configuration file the default settings for infrastructure log is

    <DiagnosticInfrastructureLogs>
      <BufferQuotaInMB>0</BufferQuotaInMB>
      <ScheduledTransferPeriodInMinutes>0</ScheduledTransferPeriodInMinutes>
      <ScheduledTransferLogLevelFilter>Undefined</ScheduledTransferLogLevelFilter>
    </DiagnosticInfrastructureLogs>
    

Now if you want to set the ScheduledTransferPeriod you can change this tag.Diagnostic Monitor will catch the configuration change

and apply new changes immediately(Diagnostic Monitor polls for the configuration changes).The same things can be done via code also.If we are using code to change the

default configuration we don’t need to directly edit the file in wad-control-container.The code will over write the config file.

var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString",config);

Posted in Azure | Tagged: , | Leave a Comment »

Windows Azure Diagnostics-Introduction

Posted by vivekcek on April 9, 2012

Windows azure diagnostic help you to collect diagnostic information from your deployed role instances. This diagnostic information will help you to debug your code after deployment.

Windows Azure Team provides a small program named Diagnostic Monitor (MonoAgentHost.exe).Which is responsible for collecting and transferring logs from your role instances.

Diagnostic Monitor collects Windows Event Logs, IIS Logs, and Performance Counter Logs etc…. And store them in local buffer. We can transfer these locally buffered logs to azure storage based on schedule or on demand.

Now you may think why we need to transfer the locally buffered logs to azure storage account. The answer is simple; you know that role instances are deployed on virtual machines. What will happen to you logs if the virtual machine is destroyed or re-imaged? .So for the safety of your data it is better to transfer logs to azure storage.

You don’t worry the smart Diagnostic Monitor will transfer your logs to azure storage account. These logs may be stored in azure blobs or tables based on the type of the log.

The below table give you an idea about the types of logs and their transfer locations.

Data Source

Default

Destination

Table/Container Name

Role Supported

Windows Azure Logs

ENABLED

TABLE

WADLogsTable

Web/Worker

IIS 7.0 Logs

ENABLED

BLOB

wad-iislogfiles

Web

Azure Diagnostic Infrastructure Logs

ENABLED

TABLE

WADDiagnosticInfrastructureLogsTable

Web/Worker

IIS Failed Request Logs

DISABLED

BLOB

wad-iisfailedreqlogfiles

Web

Windows Event Logs

DISABLED

TABLE

WADWindowsEventLogsTable

Web/Worker

Performance Counters

DISABLED

TABLE

WADPerformanceCountersTable

Web/Worker

Crash Dumps

DISABLED

BLOB

wad-crash-dumps

Web/Worker

Directory Logs

DISABLED

TABLE

WADDirectoriesTable

Web/Worker

Posted in Azure | Tagged: , , , , | Leave a Comment »

DevFC.exe Has Stopped Working Azure SDK 1.6

Posted by vivekcek on April 9, 2012

If you found an error like this after switching to 1.6 SDK.

Compute Emulator Shutdown.

In such a sitaution check your logs in “C:\Program Files\Windows Azure Emulator\emulator\devfabric\DFTemp\DevFCLogs

If you find an error like “Unrecognized element ‘webHttpBinding‘”.Then we can fix it so easily.

SOLUTION

1. Go to C:\WINDOWS\Microsoft.NET\Framework\v3.5
2. Run WFServicesReg.exe /c

Posted in Azure | Tagged: , , , | 1 Comment »