Alıştırma - Boş alan istatistiklerini bilgisayara göre özetleme

Tamamlandı

Burada, Log Analytics çalışma alanınızda verileri günlüğe kaydeden makinelerin Perf boş alanını analiz etmek için KQL sorgularını kullanarak tablodan veri alıp dönüştüreceksiniz.

1. Hedefleri belirleme

BT ekibinizin sanal makinelerde yeterli boş alan olmamasıyla ilgili yinelenen sorunlar fark ettiğini hatırlayın.

BT ortamınızda çalışan makinelerin boş alan kullanımını analiz etmek için aşağıdakiler hakkında bilgi almanız gerekir:

  • Her makinede kullanılabilir toplam boş alan.
  • Her makinede kullanılan alan yüzdesi.

2. Günlükleri değerlendirme

Önceki alıştırmada gördüğümüz gibi, tabloda donanım bileşenlerinin Perf , işletim sistemlerinin ve uygulamaların performansı hakkında bilgi sağlanmaktadır.

Perf Tablonun ObjectName sütununda izlenen tüm nesnelerin adlarının listelendiğini ve sütunun CounterName Azure İzleyici'nin topladığı çeşitli performans sayaçlarının adlarını barındırdığını not ettik. Ayrıca bu sütunların her ikisinin de çok sayıda değer barındırdığını ve bunların çoğunun birden çok kez göründüğünü gördük.

Şimdi tabloda farklı ObjectName değerleri listelemek için bir sorgu Perf çalıştıralım:

Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

Perf // The table you’re querying
| distinct ObjectName // Lists distinct ObjectName values

Bu sorgunun sonuç kümesi şu anda tabloda bulunan tüm ObjectName değerleri içerir:

Screenshot that shows the results of the Distinct Object Name query on the Perf table with the Logical Disk values highlighted.

Senaryomuzda sanal makineleri analiz etmek istiyoruz, dolayısıyla bakmak istediğimiz nesneler ve Logical Disk (LogicalDiskfiziksel bir makinedeki belleği izlemek için nesneye memory bakarsınız). Benzer şekilde adlandırılmış iki nesnenin LogicalDisk olmasının nedeni, Linux kayıtlarında kullanılırken Logical Disk Windows kayıtlarındaki nesne adıdır.

Azure İzleyici'nin ve Logical Disk nesneleri için topladığı sayaçların benzersiz adlarını listelemek için LogicalDisk şunu çalıştırın:

Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

Perf // The table you’re querying  
| where ObjectName == "LogicalDisk" or // The object name used in Windows records
ObjectName == "Logical Disk" // The object name used in Linux records
| distinct CounterName // Lists distinct CounterName values

Bu sorgunun sonuç kümesi ve Logical Disk nesneleri için LogicalDisk toplanan tüm performans sayaçlarını içerir:

Screenshot that shows the results of a query that lists the distinct names of the counters Azure Monitor collects for the LogicalDisk (written as one word) and Logical Disk (written as two words) objects.

Kullanılan ve boş alan hakkında bilgi sağlayan performans sayaçları , % Free Spaceve Free Megabytes'tir% Used Space. Sırasıyla Windows ve % Used Space Linux kayıtlarından toplanan iki benzer sayacımız % Free Space var.

Şimdi bu verileri nasıl kullanabileceğimizi ve hangi KQL işlemlerinin verileri ayıklamaya ve dönüştürmeye yardımcı olabileceğini değerlendirelim:

Sütun Açıklama Analiz hedefi İlgili KQL işlemleri
TimeGenerated Sanal makinenin her bir günlüğü ne zaman ürettiğini gösterir. Analizin zaman kapsamını tanımlayın. where TimeGenerated > ago(1d)
Daha fazla bilgi için bkz . ago(), where işleci ve Sayısal işleçler.
Computer Olayın toplandığı bilgisayar. CPU kullanımını belirli bir bilgisayarla ilişkilendirin. summarize... by Computer
Daha fazla bilgi için bkz . summarize işleci.
ObjectName Tablonun performans verilerini barındırdığı tüm nesnelerin adlarını tutar. Analiziniz için ve Logical Disk nesneleriyle LogicalDisk ilgileniyorsunuz. Sanal makinelerdeki mantıksal diskleri izleme. where ObjectName == "LogicalDisk" or ObjectName == "Logical Disk"
Daha fazla bilgi için bkz . where işleci ve == (eşittir) işleci.
CounterName Tablodaki tüm performans sayaçlarının adlarını tutar.
  • Boş alanla ilgili sayaçları izleyin.
  • % Free Space olarak yeniden adlandırın % Used Space (paralel olarak, ilgiliyi CounterValuedönüştürün)
.
where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space"
Sonuçları basitleştirmek ve daha fazla analiz yapmak için:
  • (CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName)) olarak % Free Space değiştirin% Used Space.
  • (CounterName= iff(CounterName=="Free Megabytes", "OverallFreeSpaceInGB", CounterName)) olarak OverallFreeSpaceInGB değiştir Free Megabytes
Daha fazla bilgi için bkz . where işleci ve == (eşittir) işleci.
InstanceName İzlenen nesnenin izlenen örneklerini listeler. Sanal makinedeki tüm sürücüleri izleyin. InstanceName == "_Total"
Daha fazla bilgi için bkz . where işleci ve == (eşittir) işleci.
CounterValue Sayaç için toplanan ölçüm. , % Free Spaceve Free Megabytes performans sayaçları için % Used Spaceperformans ölçümlerini alın.
  • CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue)
  • CounterValue = iff(CounterName=="Free Megabytes", (CounterValue)*0.001, CounterValue)
Daha fazla bilgi için bkz . where işleci ve == (eşittir) işleci.

3. Sorgunuzu yazın

  1. ve nesneleri için Logical DiskLogicalDisk , % Free Spaceve Free Megabytes performans sayaçlarını bildiren% Used Space, geçen gün oluşturulan tüm günlükleri alın:

    Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

    Perf
    | where TimeGenerated > ago(1d)
    | where ObjectName == "LogicalDisk" or // The object name used in Windows records
    ObjectName == "Logical Disk" // The object name used in Linux records
    | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
    | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual machine  
    

    Bu sorgunun sonuç kümesi büyük olasılıkla boş alanla ilgili performans sayaçlarını topladığınız her makine için birden çok kayıt içerir.

    Screenshot that shows the results of a query for logs generated in the past day that report on virtual machine free space.

  2. Her sanal makine tarafından bildirilen her sayaç için toplanan son sayaç değerini filtreleyin:

    Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

    Perf
    | where TimeGenerated > ago(1d)
    | where ObjectName == "LogicalDisk" or // The object name used in Windows records
    ObjectName == "Logical Disk" // The object name used in Linux records
    | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
    | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual disk  
    | summarize arg_max(TimeGenerated, CounterValue) by Computer, CounterName // Retrieves the last counter value collected for each counter for every virtual machine
    

    Artık her makinenin boş alanla ilgili her sayacı için son bildirilen sayaç değerine sahipsiniz.

    Screenshot that shows the results of a query that filters for the last counter value collected for each counter every virtual machine.

  3. Analizi kolaylaştırmak için:

    1. Sayaç değerini % Free Space değerine dönüştürün % Used Space (değeri %100'den çıkararak% Used Space) ve sütunun % Used Space% Free Spaceadını olarak değiştirin:

      Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

      Perf
      | where TimeGenerated > ago(1d)
      | where ObjectName == "LogicalDisk" or // The object name used in Windows records
      ObjectName == "Logical Disk" // The object name used in Linux records
      | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
      | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual disk  
      | summarize arg_max(TimeGenerated, CounterValue) by Computer, CounterName // Retrieves the last counter value collected for each counter for every virtual machine
      | extend CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue) // Converts % Used Space to % Free Space
      | extend CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName) // Changes the column name from % Used Space to % Free Space
      

      Bu sorgunun sonuç kümesi, Windows ve Linux makinelerindeki boş alan yüzdesini aynı şekilde sunar ve bu da daha fazla çözümlemeyi daha net ve kolay hale getirir.

      Screenshot that shows the results of a query that converts the Percentage Used Space counter value to Percentage Free Space.

    2. Gigabayt'a (Free Megabytesdeğer * 0,001 = Ücretsiz Gigabayt) dönüştürün Free Megabytes ve öğesine yeniden etiketleOverallFreeSpaceInGBFree Megabytes:

      Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

      Perf
      | where TimeGenerated > ago(1d)
      | where ObjectName == "LogicalDisk" or // The object name used in Windows records
      ObjectName == "Logical Disk" // The object name used in Linux records
      | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
      | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual disk  
      | summarize arg_max(TimeGenerated, CounterValue) by Computer, CounterName // Retrieves the last counter value collected for each counter for every virtual machine
      | extend CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue) // Converts % Used Space to % Free Space
      | extend CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName) // Changes the column name from % Used Space to % Free Space
      | extend CounterValue = iff(CounterName=="Free Megabytes", (CounterValue)*0.001, CounterValue) // Converts megabytes to gigabytes
      | extend CounterName= iff(CounterName=="Free Megabytes", "OverallFreeSpaceInGB", CounterName) // Changes the column name fromFree Megabytes to OverallFreeSpaceInGB
      

      Artık her makinedeki toplam boş alanın gigabayt cinsinden ve makinenin toplam belleğinin yüzdesi olarak net bir şekilde görüntüleyebilirsiniz.

      Screenshot that shows the results of a query that converts the Free Megabytes column to Overall Free Space In Gigabytes.

Sınama: Her bilgisayar için boş alan istatistiklerini birlikte paketleme

Sorgumuzun şu ana kadarki sonuç kümesi her bilgisayar için iki satır içerir; bir satır Gigabayt cinsinden genel boş alanı gösterirken, diğeri kullanılabilir boş alan yüzdesini gösterir.

Her sanal makine için bu iki boş alan istatistiğini bir araya getiren bir sözlük oluşturabilir misiniz?

İpucu:

Çözüm:

  1. Anahtar-değer çiftlerini birlikte CounterName, CounterValue gruplandırma:

    Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

    Perf
    | where TimeGenerated > ago(1d)
    | where ObjectName == "LogicalDisk" or // The object name used in Windows records
    ObjectName == "Logical Disk" // The object name used in Linux records
    | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
    | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual disk  
    | summarize arg_max(TimeGenerated, CounterValue) by Computer, CounterName // Retrieves the last counter value collected for each counter for every virtual machine
    | extend CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue) // Converts % Used Space to % Free Space
    | extend CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName) // Changes the column name from % Used Space to % Free Space
    | extend CounterValue = iff(CounterName=="Free Megabytes", (CounterValue)*0.001, CounterValue) // Converts megabytes to gigabytes
    | extend CounterName= iff(CounterName=="Free Megabytes", "OverallFreeSpaceInGB", CounterName) // Changes the column name fromFree Megabytes to OverallFreeSpaceInGB
    | extend packed = pack(CounterName, CounterValue) // Groups together CounterName-CounterValue key-value pairs
    

    Anahtar-değer çiftlerini birlikte CounterName, CounterValue gruplandırma, sonraki adımda her bilgisayar için boş alan istatistikleri sözlüğü oluşturmanıza olanak tanır.

    Screenshot that shows the results of a query that groups together Counter Name and Counter Value key-value pairs.

  2. Her makine için toplanan tüm boş alan istatistiklerini içeren SpaceStats adlı bir özellik paketi (sözlük) oluşturun, bilgisayara göre özetleyin ve %50'den az boş alanı olan makineler için filtreleyin:

    Log Analytics tanıtım ortamında sorgu çalıştırmak için tıklayın

    Perf
    | where TimeGenerated > ago(1d)
    | where ObjectName == "LogicalDisk" or // The object name used in Windows records
    ObjectName == "Logical Disk" // The object name used in Linux records
    | where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" // Filters for the performance counters Free Megabytes, % Free Space, and % Used Space performance counters
    | where InstanceName == "_Total"  // Retrieves data related to free space for all drives on a virtual disk  
    | summarize arg_max(TimeGenerated, CounterValue) by Computer, CounterName // Retrieves the last counter value collected for each counter for every virtual machine
    | extend CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue) // Converts % Used Space to % Free Space
    | extend CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName) // Changes the column name from % Used Space to % Free Space
    | extend CounterValue = iff(CounterName=="Free Megabytes", (CounterValue)*0.001, CounterValue) // Converts megabytes to gigabytes
    | extend CounterName= iff(CounterName=="Free Megabytes", "OverallFreeSpaceInGB", CounterName) // Changes the column name fromFree Megabytes to OverallFreeSpaceInGB
    | extend packed = pack(CounterName, CounterValue) // Groups together CounterName-CounterValue key-value pairs
    | summarize SpaceStats = make_bag(packed) by Computer // Summarizes free space statstics by computer
    | where SpaceStats.["% Free Space"]<= 50
    

    Bu sorgunun sonuç kümesi, boş alan analizinizin hedefi olan makineye göre boş alan istatistiklerini özetler!

    Sorgunun son satırı, %50'den az boş alanı olan makineler için filtreler. Daha yakından izlemek veya analiz etmek ya da yerlerinin yetersiz olmadığından emin olmak için bunları yeniden yapılandırmak isteyebilirsiniz.

    Screenshot that shows the results of a query that summarizes free space statistics by machine.