A day with .Net

My day to day experince in .net

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);
            }

        }
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s