تمرين - تلخيص إحصائيات المساحة الحرة حسب الكمبيوتر

مكتمل

هنا، ستقوم باسترداد البيانات وتحويلها من Perf الجدول، باستخدام استعلامات KQL، لتحليل المساحة الحرة لبيانات تسجيل الأجهزة إلى مساحة عمل Log Analytics.

1. تعيين الأهداف

تذكر أن فريق تكنولوجيا المعلومات لديك لاحظ مشكلات متكررة تتعلق بمسافة حرة غير كافية على الأجهزة الظاهرية.

لتحليل استخدام المساحة الحرة للأجهزة التي تعمل في بيئة تكنولوجيا المعلومات الخاصة بك، تحتاج إلى معلومات حول:

  • إجمالي المساحة الفارغة المتوفرة على كل جهاز.
  • النسبة المئوية للمساحة المستخدمة على كل جهاز.

2. تقييم السجلات

كما رأينا التمرين السابق، Perf يوفر الجدول معلومات حول أداء مكونات الأجهزة وأنظمة التشغيل والتطبيقات.

لاحظنا أن Perf عمود الجدول ObjectName يسرد أسماء جميع الكائنات التي تتم مراقبتها ويحمل CounterName العمود أسماء عدادات الأداء المختلفة التي يجمعها Azure Monitor. كما رأينا أن كلا العمودين يحتويان على الكثير من القيم، والتي يظهر العديد منها عدة مرات.

لنقم بتشغيل استعلام على الجدول لسرد القيم المميزة Perf ObjectName :

انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

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

تتضمن مجموعة نتائج هذا الاستعلام كافة ObjectName القيم الموجودة حاليا في الجدول:

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

في السيناريو لدينا، نحن مهتمون بتحليل الأجهزة الظاهرية، لذلك الكائنات التي نريد أن ننظر إليها هي LogicalDisk و Logical Disk (لمراقبة الذاكرة في جهاز فعلي، ستنظر إلى memory العنصر). السبب في وجود كائنين مسميين بشكل مماثل هو LogicalDisk اسم الكائن في سجلات Windows أثناء Logical Disk استخدامه في سجلات Linux.

لسرد الأسماء المميزة للعدادات التي يجمعها Azure Monitor للكائنات LogicalDisk و Logical Disk ، قم بتشغيل:

انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

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

تتضمن مجموعة نتائج هذا الاستعلام جميع عدادات الأداء التي تم جمعها لكائنات LogicalDisk و Logical Disk :

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.

عدادات الأداء التي توفر معلومات حول المساحة المستخدمة والخالية هي % Used Spaceو % Free Spaceو Free Megabytes. لدينا عدادان متشابهان - % Free Space و % Used Space - تم جمعهما من سجلات Windows وLinux، على التوالي.

دعونا نقيم كيف يمكننا استخدام هذه البيانات وعمليات KQL التي يمكن أن تساعد في استخراج البيانات وتحويلها:

العمود ‏‏الوصف هدف التحليل عمليات KQL ذات الصلة
TimeGenerated يشير إلى وقت إنشاء الجهاز الظاهري لكل سجل. حدد النطاق الزمني للتحليل. where TimeGenerated > ago(1d)
لمزيد من المعلومات، راجع ago()، حيث عامل التشغيل، وعوامل التشغيل الرقمية.
Computer الكمبيوتر الذي تم جمع الحدث منه. إقران استخدام وحدة المعالجة المركزية بجهاز كمبيوتر معين. summarize... by Computer
لمزيد من المعلومات، راجع تلخيص عامل التشغيل.
ObjectName يحمل أسماء كافة الكائنات التي يحتوي الجدول على بيانات الأداء لها. لتحليلك، أنت مهتم بالكائنات LogicalDisk و Logical Disk . مراقبة الأقراص المنطقية في الأجهزة الظاهرية. where ObjectName == "LogicalDisk" or ObjectName == "Logical Disk"
لمزيد من المعلومات، راجع مكان عامل التشغيل وعامل التشغيل == (يساوي).
CounterName يحمل أسماء جميع عدادات الأداء في الجدول.
  • مراقبة العدادات المتعلقة بالمساحة الحرة.
  • إعادة التسمية % Used Space إلى % Free Space (بالتوازي، تحويل ذات الصلة CounterValue)
.
where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space"
لتبسيط النتائج وتسهيل المزيد من التحليل:
  • تغيير % Used Space إلى % Free Space (CounterName = iff(CounterName=="% Used Space", "% Free Space", CounterName)).
  • تغيير Free Megabytes إلى OverallFreeSpaceInGB (CounterName= iff(CounterName=="Free Megabytes", "OverallFreeSpaceInGB", CounterName))
لمزيد من المعلومات، راجع مكان عامل التشغيل وعامل التشغيل == (يساوي).
InstanceName يسرد المثيلات المراقبة للكائن المراقب. مراقبة جميع محركات الأقراص على الجهاز الظاهري. InstanceName == "_Total"
لمزيد من المعلومات، راجع مكان عامل التشغيل وعامل التشغيل == (يساوي).
CounterValue القياس الذي تم جمعه للعداد. استرداد قياسات الأداء لعدادات % Used Space% Free Spaceالأداء و وFree Megabytes.
  • CounterValue = iff(CounterName=="% Used Space", 100-CounterValue, CounterValue)
  • CounterValue = iff(CounterName=="Free Megabytes", (CounterValue)*0.001, CounterValue)
لمزيد من المعلومات، راجع مكان عامل التشغيل وعامل التشغيل == (يساوي).

3. كتابة الاستعلام

  1. استرداد جميع السجلات التي تم إنشاؤها في اليوم الماضي التي أبلغت عن % Used Space% Free Spaceعدادات الأداء و و Free Megabytes للكائنات LogicalDisk وLogical Disk:

    انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

    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  
    

    من المحتمل أن تتضمن مجموعة نتائج هذا الاستعلام سجلات متعددة لكل جهاز تجمع منه عدادات الأداء المتعلقة بمساحة حرة.

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

  2. تصفية لآخر قيمة عداد تم جمعها لكل عداد تم الإبلاغ عنه بواسطة كل جهاز ظاهري:

    انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

    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
    

    لديك الآن آخر قيمة عداد تم الإبلاغ عنها لكل عداد مجاني متعلق بالفضاء لكل جهاز.

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

  3. لتسهيل التحليل:

    1. تحويل قيمة العداد % Used Space إلى % Free Space (عن طريق طرح % Used Space القيمة من 100٪) وتغيير اسم % Used Space العمود إلى % Free Space:

      انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

      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
      

      تقدم مجموعة نتائج هذا الاستعلام النسبة المئوية للمساحة الفارغة على أجهزة Windows وLinux بنفس الطريقة، ما يجعل المزيد من التحليل أكثر وضوحا وأسهل.

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

    2. التحويل Free Megabytes إلى غيغابايت (Free Megabytes القيمة * 0.001 = غيغابايت مجانية) وإعادة تسمية Free Megabytes إلى OverallFreeSpaceInGB:

      انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

      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
      

      يمكنك الآن الحصول على صورة واضحة لإجمالي المساحة الفارغة على كل جهاز بالجيجابايت وكنسبة مئوية من إجمالي ذاكرة الجهاز.

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

التحدي: تجميع إحصائيات المساحة الحرة معا لكل كمبيوتر

تتضمن مجموعة نتائج استعلامنا حتى الآن سطرين لكل كمبيوتر - يظهر سطر واحد المساحة الحرة الإجمالية بالجيجابايت والآخر يعرض النسبة المئوية للمساحة الفارغة المتاحة.

هل يمكنك إنشاء قاموس يجمع إحصائيتي المساحة الحرة معا لكل جهاز ظاهري؟

تلميح:

  • استخدم الدالة bag_pack() لإنشاء أزواج قيم المفاتيح لكل عداد من عدادي الأداء.
  • استخدم دالة التجميع make_bag() لتجميع قيم قيم المفاتيح لكل كمبيوتر.

الحل:

  1. تجميع أزواج قيم المفاتيح معا CounterName, CounterValue :

    انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

    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
    

    يتيح لك تجميع أزواج قيم المفاتيح معا CounterName, CounterValue إنشاء قاموس لإحصائيات المساحة الحرة لكل كمبيوتر في الخطوة التالية.

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

  2. إنشاء حقيبة خصائص (قاموس)، تسمى SpaceStats، من جميع إحصائيات المساحة الحرة التي تم جمعها لكل جهاز، والتلخيص حسب الكمبيوتر، وتصفية الأجهزة التي تحتوي على مساحة خالية أقل من 50٪:

    انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل Log Analytics

    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
    

    تلخص مجموعة نتائج هذا الاستعلام إحصائيات المساحة الحرة حسب الجهاز، والذي كان الهدف من تحليل المساحة الحرة!

    يقوم السطر الأخير من الاستعلام بتصفية الأجهزة التي بها مساحة خالية أقل من 50٪. قد ترغب في مراقبتها أو تحليلها عن كثب، أو إعادة تكوينها للتأكد من عدم نفاد المساحة.

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