Azure Bulut Hizmetiniz için performans sayaçlarını toplama (klasik)

Önemli

Cloud Services (klasik) artık yeni müşteriler için kullanımdan kaldırılmıştır ve tüm müşteriler için 31 Ağustos 2024'te kullanımdan kaldırılacaktır. Yeni dağıtımlarda yeni Azure Resource Manager tabanlı dağıtım modeli Azure Cloud Services (genişletilmiş destek) kullanılmalıdır.

Performans sayaçları, uygulamanızın ve konağın performansını izlemeniz için bir yol sağlar. Windows Server, donanım, uygulamalar, işletim sistemi ve daha fazlası ile ilgili birçok farklı performans sayacı sağlar. Performans sayaçlarını toplayıp Azure'a göndererek, daha iyi kararlar almaya yardımcı olmak için bu bilgileri analiz edebilirsiniz.

Kullanılabilir sayaçları bulma

Performans sayacı, bir küme adı (kategori olarak da bilinir) ve bir veya daha fazla sayaç olmak üzere iki bölümden oluşur. Kullanılabilir performans sayaçlarının listesini almak için PowerShell'i kullanabilirsiniz:

Get-Counter -ListSet * | Select-Object CounterSetName, Paths | Sort-Object CounterSetName

CounterSetName                                  Paths
--------------                                  -----
.NET CLR Data                                   {\.NET CLR Data(*)\SqlClient...
.NET CLR Exceptions                             {\.NET CLR Exceptions(*)\# o...
.NET CLR Interop                                {\.NET CLR Interop(*)\# of C...
.NET CLR Jit                                    {\.NET CLR Jit(*)\# of Metho...
.NET Data Provider for Oracle                   {\.NET Data Provider for Ora...
.NET Data Provider for SqlServer                {\.NET Data Provider for Sql...
.NET Memory Cache 4.0                           {\.NET Memory Cache 4.0(*)\C...
AppV Client Streamed Data Percentage            {\AppV Client Streamed Data ...
ASP.NET                                         {\ASP.NET\Application Restar...
ASP.NET Apps v4.0.30319                         {\ASP.NET Apps v4.0.30319(*)...
ASP.NET State Service                           {\ASP.NET State Service\Stat...
ASP.NET v2.0.50727                              {\ASP.NET v2.0.50727\Applica...
ASP.NET v4.0.30319                              {\ASP.NET v4.0.30319\Applica...
Authorization Manager Applications              {\Authorization Manager Appl...

#... results cut to save space ...

CounterSetName özelliği bir kümeyi (veya kategoriyi) temsil eder ve performans sayaçlarının neyle ilişkili olduğunu iyi bir göstergedir. özelliği, Paths bir küme için sayaç koleksiyonunu temsil eder. Sayaç kümesi hakkında daha fazla bilgi için özelliğini de alabilirsiniz Description .

Bir kümenin tüm sayaçlarını almak için değerini kullanın CounterSetName ve koleksiyonu genişletin Paths . Her yol öğesi sorgulayabileceğiniz bir sayaçtır. Örneğin, kümeyle ilgili kullanılabilir sayaçları almak için Processor koleksiyonu genişletin Paths :

Get-Counter -ListSet * | Where-Object CounterSetName -eq "Processor" | Select -ExpandProperty Paths

\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec

Bu tek tek sayaç yolları, bulut hizmetinizin kullandığı tanılama çerçevesine eklenebilir. Performans sayacı yolunun nasıl oluşturulur hakkında daha fazla bilgi için bkz. Sayaç Yolu Belirtme.

Performans sayacı toplama

Azure Tanılama veya Application Insights için bulut hizmetinize bir performans sayacı eklenebilir.

Application Insights

Cloud Services için Azure Uygulaması İçgörüler, hangi performans sayaçlarını toplamak istediğinizi belirtmenize olanak tanır. Application Insights'ı projenize ekledikten sonra Visual Studio projenize ApplicationInsights.config adlı bir yapılandırma dosyası eklenir. Bu yapılandırma dosyası, Application Insights'ın hangi tür bilgileri toplayıp Azure'a gönderdiğini tanımlar.

ApplicationInsights.config dosyasını açın ve ApplicationInsights>TelemetryModules öğesini bulun. Her <Add> alt öğe, yapılandırmasıyla birlikte toplayacak bir telemetri türünü tanımlar. Performans sayacı telemetri modülü türü şeklindedir Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector. Bu öğe zaten tanımlanmışsa, ikinci kez eklemeyin. Toplayacak her performans sayacı adlı <Counters>bir düğüm altında tanımlanır. Aşağıda, sürücü performans sayaçlarını toplayan bir örnek verilmiştir:

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">

  <TelemetryModules>

    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
      <Counters>
        <Add PerformanceCounter="\LogicalDisk(C:)\Disk Write Bytes/sec" ReportAs="Disk write (C:)" />
        <Add PerformanceCounter="\LogicalDisk(C:)\Disk Read Bytes/sec" ReportAs="Disk read (C:)" />
      </Counters>
    </Add>

  </TelemetryModules>

<!-- ... cut to save space ... -->

Her performans sayacı altında <Counters>bir <Add> öğe olarak temsil edilir. PerformanceCounter özniteliği, hangi performans sayacının toplayacağını tanımlar. ReportAs özniteliği, performans sayacının Azure portal görüntülenecek başlıktır. Topladığınız tüm performans sayaçları portalda Özel adlı bir kategoriye konur. Azure Tanılama farklı olarak, bu performans sayaçlarının toplanıp Azure'a gönderileceği aralığı ayarlayamazsınız. Application Insights ile performans sayaçları dakikada bir toplanır ve gönderilir.

Application Insights aşağıdaki performans sayaçlarını otomatik olarak toplar:

  • \Process(?? APP_WIN32_PROC??) İşlemci Süresi Yüzdesi
  • \Memory\Available Bytes
  • .NET CLR Özel Durumları(?? APP_CLR_PROC??) # of Exceps Thrown / sec
  • \Process(??APP_WIN32_PROC??)\Private Bytes
  • \Process(??APP_WIN32_PROC??)\IO Data Bytes/sec
  • \İşlemci(_Total)% İşlemci Süresi

Daha fazla bilgi için bkz. Azure Cloud Services içinApplication Insights ve Application Insights'ta sistem performans sayaçları.

Azure Tanılama

Önemli

Tüm bu veriler depolama hesabında toplanmış olsa da portal verileri grafiği oluşturmak için yerel bir yol sağlamaz . Application Insights gibi başka bir tanılama hizmetini uygulamanızla tümleştirmeniz kesinlikle önerilir.

Cloud Services için Azure Tanılama uzantısı, hangi performans sayaçlarını toplamak istediğinizi belirtmenize olanak tanır. Azure Tanılama ayarlamak için bkz. Bulut Hizmeti İzlemeye Genel Bakış.

Toplamak istediğiniz performans sayaçları diagnostics.wadcfgx dosyasında tanımlanır. Visual Studio'da bu dosyayı açın (rol başına tanımlanır) ve DiagnosticsConfiguration>PublicConfig>WadCfg>DiagnosticMonitorConfiguration>PerformanceCounters öğesini bulun. Alt öğe olarak yeni bir PerformanceCounterConfiguration öğesi ekleyin. Bu öğenin iki özniteliği vardır: counterSpecifier ve sampleRate. counterSpecifier özniteliği, hangi sistem performans sayacı kümesinin (önceki bölümde özetlenmiştir) toplandığını tanımlar. değeri, sampleRate bu değerin ne sıklıkta yoklandığını gösterir. Bir bütün olarak, tüm performans sayaçları üst PerformanceCounters öğenin öznitelik değerine göre Azure'a scheduledTransferPeriod aktarılır.

Şema öğesi hakkında PerformanceCounters daha fazla bilgi için bkz. Azure Tanılama Şeması.

Özniteliği tarafından tanımlanan dönem, performans sayacının sampleRate ne sıklıkta yoklandığını belirtmek için XML süresi veri türünü kullanır. Aşağıdaki örnekte, oran olarak ayarlanmıştır PT3M. Bu, üç dakikada bir anlamına gelir [P]eriod[T]ime[3][M]inutes.

ve scheduledTransferPeriod değerlerinin sampleRate nasıl tanımlandığı hakkında daha fazla bilgi için W3 XML Tarih ve Saat Tarih Türleri öğreticisinin Süre Veri Türü bölümüne bakın.

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration  xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <PublicConfig>
    <WadCfg>
      <DiagnosticMonitorConfiguration overallQuotaInMB="4096">

        <!-- ... cut to save space ... -->

        <PerformanceCounters scheduledTransferPeriod="PT1M">
          <PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />

          <!-- This is a new perf counter which will track the C: disk read activity in bytes per second, every minute -->
          <PerformanceCounterConfiguration counterSpecifier="\LogicalDisk(C:)\Disk Read Bytes/sec" sampleRate="PT1M" />

        </PerformanceCounters>
      </DiagnosticMonitorConfiguration>
    </WadCfg>
    
    <!-- ... cut to save space ... -->

  </PublicConfig>
</DiagnosticsConfiguration>

Yeni performans sayacı oluşturma

Kodunuz tarafından yeni bir performans sayacı oluşturulabilir ve kullanılabilir. Yeni bir performans sayacı oluşturan kodunuz yükseltilmiş olarak çalışıyor olmalıdır, aksi takdirde başarısız olur. Bulut hizmeti OnStart başlangıç kodunuz performans sayacını oluşturabilir ve rolü yükseltilmiş bir bağlamda çalıştırmanızı gerektirebilir. İsterseniz, yükseltilmiş olarak çalışan ve performans sayacını oluşturan bir başlangıç görevi de oluşturabilirsiniz. Başlangıç görevleri hakkında daha fazla bilgi için bkz. Bulut hizmeti için başlangıç görevlerini yapılandırma ve çalıştırma.

Rolünüzü yükseltilmiş olarak çalışacak şekilde yapılandırmak için .csdef dosyasına bir <Runtime> öğesi ekleyin.

<ServiceDefinition name="CloudServiceLoadTesting" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
  <WorkerRole name="WorkerRoleWithSBQueue1" vmsize="Large">

    <!-- ... cut to save space ... -->

    <Runtime executionContext="elevated">
      
    </Runtime>

    <!-- ... cut to save space ... -->

  </WorkerRole>
</ServiceDefinition>

Birkaç kod satırıyla yeni bir performans sayacı oluşturup kaydedebilirsiniz. Hem kategoriyi System.Diagnostics.PerformanceCounterCategory.Create hem de sayacı oluşturan yöntem aşırı yüklemesini kullanın. Aşağıdaki kod önce kategorinin var olup olmadığını denetler ve eksikse hem kategoriyi hem de sayacı oluşturur.

using System.Diagnostics;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace WorkerRoleWithSBQueue1
{
    public class WorkerRole : RoleEntryPoint
    {
        // Perf counter variable representing times service was used.
        private PerformanceCounter counterServiceUsed;

        public override bool OnStart()
        {
            // ... Other startup code here ...

            // Define the category and counter names.
            string perfCounterCatName = "MyService";
            string perfCounterName = "Times Used";

            // Create the counter if needed. Our counter category only has a single counter.
            // Both the category and counter are created in the same method call.
            if (!PerformanceCounterCategory.Exists(perfCounterCatName))
            {
                PerformanceCounterCategory.Create(perfCounterCatName, "Collects information about the cloud service.", 
                                                  PerformanceCounterCategoryType.SingleInstance, 
                                                  perfCounterName, "How many times the cloud service was used.");
            }

            // Get reference to our counter
            counterServiceUsed = new PerformanceCounter(perfCounterCatName, perfCounterName);
            counterServiceUsed.ReadOnly = false;
            
            return base.OnStart();
        }

        // ... cut class code to save space
    }
}

Sayacı kullanmak istediğinizde veya IncrementBy yöntemini çağırınIncrement.

// Increase the counter by 1
counterServiceUsed.Increment();

Uygulamanız özel sayacınızı kullandığına göre, sayacı izlemek için Azure Tanılama veya Application Insights'ı yapılandırmanız gerekir.

Application Insights

Daha önce belirtildiği gibi, Application Insights için performans sayaçları ApplicationInsights.config dosyasında tanımlanır. ApplicationInsights.config açın ve ApplicationInsights>TelemetryModulesAdd Counters>> öğesini bulun. Bir <Add> alt öğe oluşturun ve özniteliğini PerformanceCounter kodunuzda oluşturduğunuz performans sayacının kategorisine ve adına ayarlayın. Özniteliği portalda ReportAs görmek istediğiniz kolay bir ad olarak ayarlayın.

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">

  <TelemetryModules>

    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
      <Counters>
        <!-- ... cut other perf counters to save space ... -->

        <!-- This new perf counter matches the [category name]\[counter name] defined in your code -->
        <Add PerformanceCounter="\MyService\Times Used" ReportAs="Service used counter" />
      </Counters>
    </Add>

  </TelemetryModules>

<!-- ... cut to save space ... -->

Azure Tanılama

Daha önce belirtildiği gibi, toplamak istediğiniz performans sayaçları diagnostics.wadcfgx dosyasında tanımlanır. Visual Studio'da bu dosyayı açın (rol başına tanımlanır) ve DiagnosticsConfiguration>PublicConfig>WadCfg>DiagnosticMonitorConfiguration>PerformanceCounters öğesini bulun. Alt öğe olarak yeni bir PerformanceCounterConfiguration öğesi ekleyin. Özniteliğini counterSpecifier , kodunuzda oluşturduğunuz performans sayacının kategorisine ve adına ayarlayın.

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration  xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <PublicConfig>
    <WadCfg>
      <DiagnosticMonitorConfiguration overallQuotaInMB="4096">

        <!-- ... cut to save space ... -->

        <PerformanceCounters scheduledTransferPeriod="PT1M">
          <!-- ... cut other perf counters to save space ... -->
          
          <!-- This new perf counter matches the [category name]\[counter name] defined in your code -->
          <PerformanceCounterConfiguration counterSpecifier="\MyService\Times Used" sampleRate="PT1M" />

        </PerformanceCounters>
      </DiagnosticMonitorConfiguration>
    </WadCfg>
    
    <!-- ... cut to save space ... -->

  </PublicConfig>
</DiagnosticsConfiguration>

Daha fazla bilgi