تمرين - تلخيص إحصائيات المساحة الحرة حسب الكمبيوتر
هنا، ستقوم باسترداد البيانات وتحويلها من 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
القيم الموجودة حاليا في الجدول:
في السيناريو لدينا، نحن مهتمون بتحليل الأجهزة الظاهرية، لذلك الكائنات التي نريد أن ننظر إليها هي 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
:
عدادات الأداء التي توفر معلومات حول المساحة المستخدمة والخالية هي % 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 |
يحمل أسماء جميع عدادات الأداء في الجدول. |
|
where CounterName == "Free Megabytes" or CounterName =="% Free Space" or CounterName == "% Used Space" لتبسيط النتائج وتسهيل المزيد من التحليل:
|
InstanceName |
يسرد المثيلات المراقبة للكائن المراقب. | مراقبة جميع محركات الأقراص على الجهاز الظاهري. | InstanceName == "_Total" لمزيد من المعلومات، راجع مكان عامل التشغيل وعامل التشغيل == (يساوي). |
CounterValue |
القياس الذي تم جمعه للعداد. | استرداد قياسات الأداء لعدادات % Used Space % Free Space الأداء و وFree Megabytes . |
|
3. كتابة الاستعلام
استرداد جميع السجلات التي تم إنشاؤها في اليوم الماضي التي أبلغت عن
% 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
من المحتمل أن تتضمن مجموعة نتائج هذا الاستعلام سجلات متعددة لكل جهاز تجمع منه عدادات الأداء المتعلقة بمساحة حرة.
تصفية لآخر قيمة عداد تم جمعها لكل عداد تم الإبلاغ عنه بواسطة كل جهاز ظاهري:
انقر لتشغيل الاستعلام في بيئة العرض التوضيحي ل 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
لديك الآن آخر قيمة عداد تم الإبلاغ عنها لكل عداد مجاني متعلق بالفضاء لكل جهاز.
لتسهيل التحليل:
تحويل قيمة العداد
% 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 بنفس الطريقة، ما يجعل المزيد من التحليل أكثر وضوحا وأسهل.
التحويل
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
يمكنك الآن الحصول على صورة واضحة لإجمالي المساحة الفارغة على كل جهاز بالجيجابايت وكنسبة مئوية من إجمالي ذاكرة الجهاز.
التحدي: تجميع إحصائيات المساحة الحرة معا لكل كمبيوتر
تتضمن مجموعة نتائج استعلامنا حتى الآن سطرين لكل كمبيوتر - يظهر سطر واحد المساحة الحرة الإجمالية بالجيجابايت والآخر يعرض النسبة المئوية للمساحة الفارغة المتاحة.
هل يمكنك إنشاء قاموس يجمع إحصائيتي المساحة الحرة معا لكل جهاز ظاهري؟
تلميح:
- استخدم الدالة bag_pack() لإنشاء أزواج قيم المفاتيح لكل عداد من عدادي الأداء.
- استخدم دالة التجميع make_bag() لتجميع قيم قيم المفاتيح لكل كمبيوتر.
الحل:
تجميع أزواج قيم المفاتيح معا
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
إنشاء قاموس لإحصائيات المساحة الحرة لكل كمبيوتر في الخطوة التالية.إنشاء حقيبة خصائص (قاموس)، تسمى 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٪. قد ترغب في مراقبتها أو تحليلها عن كثب، أو إعادة تكوينها للتأكد من عدم نفاد المساحة.