ThisWillDoIt
ThisWillDoIt

Reputation: 509

How to measure memory usage of azure web/worker roles programmatically?

I want to log the memory usage of some web/worker roles which are hosted in windows azure instances.

Is there a way to programmatically check for the currently used memory so I can save this value somewhere for later use?

The only information I found was to get the current thread and then call a method which should return memory usage of the heap. But I don’t think this helps me much at my problem especially when there are some asynchronous calls.

Upvotes: 4

Views: 1165

Answers (2)

Milan
Milan

Reputation: 3325

I am using c# and this seems to be working for me. (Simplified): MS reference link: link

        try
        {
            long bytes = GC.GetTotalMemory(false);

            return "RAM used: " + (bytes/1024/1024).ToString() + " MB";
        }
        catch (Exception ex)
        {
          return "No RAM info available!";
        }

Upvotes: 0

Christian
Christian

Reputation: 4375

Azure Diagnostics is a good point to start. You can add any performance counter you like: Memory Consumption, CPU usage, etc.

  1. Rightclick your Role in the Azure Project and go to Properties.
  2. Under Configuration you will see "Diagnostics"
  3. Tick "Enable Diagnostics" and select "Custom Plan" -> "Edit"
  4. Under Performance Counters select what you want (be aware, it needs to be the english name of the counter, in case you have a different language on your machine)

Those Counters will be saved in Table Storage under the Table Name "WADPerformanceCounters"

enter image description here

This article may also be of help: http://msdn.microsoft.com/en-us/library/windowsazure/dn186185.aspx

Upvotes: 3

Related Questions