This is Part 8 in a series of posts described here: https://blogs.technet.microsoft.com/kevinholman/2016/06/04/authoring-management-packs-the-fast-and-easy-way-using-visual-studio/
In our next example fragment – we will create Monitor for Windows Performance for our MP.
Step 1: Download and extract the sample MP fragments. These are available here: https://gallery.technet.microsoft.com/SCOM-Management-Pack-VSAE-2c506737
I will update these often as I enhance and add new ones, so check back often for new versions.
Step 2: Open your newly created MP solution, and open Solution Explorer. This solution was created in Part 1, and the class was created in Part 2.
Step 3: Create a folder and add the fragment to it.
Create a folder called “Monitors” in your MP, if you don’t already have this folder.
Right click Monitors, and Add > Existing item.
Find the fragment named “Generic.Monitor.Performance.ConsecSamples.TwoState.Fragment.mpx” and add it.
Select Generic.Monitor.Performance.ConsecSamples.TwoState.Fragment.mpx in solution explorer to display the XML.
Step 4: Find and Replace
Replace ##CompanyID## with our company ID which is “Fab”
Replace ##AppName## with our App ID, which is “DemoApp”
Replace ##ClassID## with the custom class we created in Part 2 of the series. This was “Fab.DemoApp.Class” from our previous class fragment.
Replace ##ObjectName## with a valid perfmon object. I will use “Print Queue”
Replace ##CounterName## with a valid perfmon counter. I will use “Total Jobs Printed”
Replace ##CounterNameWithoutSpaces## with your counter, but remove any spaces. I will use “TotalJobsPrinted”
Replace ##InstanceName## with a valid perfmon instance. I will use “_Total”
Replace ##Threshold## with a valid threshold for the monitor. I will use “5”
That took all of 2 minutes. Take another few minutes to review the XML we have in this fragment. It is a simple monitor definition, it checks every minute, and when 5 consecutive samples are over a threshold value of “5”, it will change state and alert.
Step 5: Build the MP. BUILD > Build Solution.
Step 6: Import or Deploy the management pack.
Step 7: Test the MP.
Open the Monitoring pane of the console – and find your folder you created in Part 6.
Open the state view.
Open Health Explorer for an instance of your class.
To test this perf counter, you can print dummy jobs from Notepad to the Microsoft XPS document writer, to get the value over the threshold.
After 5 consecutive samples, based on our interval (every 60 seconds) I should see a statechange after 5 minutes.
Boom: