Monitor Everything with Monitis – And do it easily with PowerShell – Part 3

Mining External Monitor Results with Monitis and PowerShell

In the last article, we walked thru some of the other commands related to external monitors.  Today, we’ll focus on the one you’ll probably use the most:  Get-MonitisMonitorResult.

Before we get started, please remember to download the Monitis module from Monitis’ github open source repository.  Download it to Documents\WindowsPowerShell\modules, and import it in PowerShell by running Import-Module Monitis.

Get-MonitisMonitorResult gives you results from any type of Monitor.  You use it by piping in the monitors you want.


For instance, this will show todays results from the current monitor:

Get-MonitisExternalMonitor | Select-Object -First 1 | Get-MonitisMonitorResult

for example:

Like everything else in the Monitis module, you have a few  different options when you get results.  Instead of just getting results for today, you can use the –Last parameter to get results for the last number 3 days:

Get-MonitisExternalMonitor |
    Select-Object -First 1 |
    Get-MonitisMonitorResult -Last (New-TimeSpan -Days 3)

You can also get results since a date

Get-MonitisExternalMonitor |
    Select-Object -First 1 |
    Get-MonitisMonitorResult -Since 9/1/2011

Or for a range of dates

Get-MonitisExternalMonitor |
    Select-Object -First 1 |
    Get-MonitisMonitorResult -Start 9/1/2011 –End 9/10/2011

By default you see a summary object from each location.  This tells you the location, and a number of different subproperties tell you what’s going on.

  • Data contains each result
  • Trend contains trends from the day.
  • LocationName is where it was run.

You might notice that Select-Object in the middle of the pipeline.  We’re using it to pick the first of your monitors, but you can use it for a lot more.  For instance, if you just want to see a summary of how things are on each day, you could use:

Get-MonitisExternalMonitor |
    Select-Object -First 1 |
    Get-MonitisMonitorResult -Since 9/1/2011 |
    Select-Object -ExpandProperty Trend

like: Trend gives you an OK or not ok count.  If you can’t ping the box, or if a complex external monitor fails, you can use another built in PowerShell command to figure it out:  Where-Object.  Where-Object takes a filter, and, if the item in that filter returns an object which isn’t zero or a blank string, then Where-Object will output the original item.  This lets you filter anything in any way you’d like.  To find only the things in the last month that had trouble, use:

Get-MonitisExternalMonitor |
    Select-Object -First 1 |
    Get-MonitisMonitorResult -Since 9/1/2011 |
    Where-Object {
        $_.Trend.NotOkCount
    }

If that filter works, and your servers are working well, you should see nothing.    To prove it to yourself, go ahead and change NotOkCount to OkCount, and see only the locations with working results.  This is a good thing to be aware of.  In PowerShell, unless you’re getting data, no results are good results.  Meaning that if you see no output and no errors and it’s not a command that should return information to you, then your command just worked.

Now you know how make mincemeat of your results.  Next time, we’ll show you how generate a lot more results to manage, by monitoring web applications with Monitis.

See also

Monitor Everything with Monitis – And do it easily with PowerShell – Part 1

Monitor Everything with Monitis – And do it easily with PowerShell – Part 2

You might also like