This PowerShell application will illustrate how to pull out the rolled up Http Statistics taking from all of the Http Profiles.
I was digging through the iControl interfaces the other day and it's still amazing to me, after being around since the beginning of the API, to find new and cool stuff hiding in there. Today's find was lurking within the System.Statistics interface. There are literally dozens of method calls to pull out all sorts of useful statistics and the one I picked for today is the System HTTP Statistics which are a rollup of all HTTP Profiles' statistics. This application will build a report on everything you wanted to know from an HTTP level such as how many 5xx responses have been served to the number of bytes of compressed video and the RAM cache hits and misses.
Code :
# The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
# Software Development Kit for iControl"; you may not use this file except in
# compliance with the License. The License is included in the iControl
# Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2007 F5 Networks,
# Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above. If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#----------------------------------------------------------------------------
param (
$g_bigip = $null,
$g_uid = $null,
$g_pwd = $null,
$g_subset = $null
);
Set-PSDebug -strict;
#-------------------------------------------------------------------------
# function Write-Usage
#-------------------------------------------------------------------------
function Write-Usage()
{
Write-Host "Usage: GlobalHttpStats.ps1 host uid pwd [subset = all|http|compression|cache]";
exit;
}
#-------------------------------------------------------------------------
# function Get-TimeFromTimeStamp
#-------------------------------------------------------------------------
function Get-TimeFromTimeStamp()
{
param ($TimeStamp);
$dt = new-object -typename System.DateTime
$dt = $dt.AddYears($TimeStamp.year-1).AddMonths($TimeStamp.month-1).AddDays($TimeStamp.day-1)
$dt = $dt.AddHours($TimeStamp.hour).AddMinutes($TimeStamp.minute).AddSeconds($TimeStamp.second);
return $dt;
}
################################################################################
## Invoke-Inline.ps1 (originally from Lee Holmes)
## Library support for inline C#
##
## Modified by Joel Bennett to accept include statements, and return collections
##
## Usage
## 1) Define just the body of a C# method, and store it in a string. "Here
## strings" work great for this. The code can be simple:
##
## $codeToRun = "Console.WriteLine(Math.Sqrt(337));"
##
## or more complex, using result.Add():
##
## $codeToRun = @"
## string firstArg = (string) ((System.Collections.ArrayList) arg)[0];
## int secondArg = (int) ((System.Collections.ArrayList) arg)[1];
##
## Console.WriteLine("Hello {0} {1}", firstArg, secondArg );
##
## result.Add(secondArg * 3);
## "@
##
## 2) If you must pass arguments, you should make them strongly-typed,
## so that PowerShell doesn't wrap it as a PsObject.
##
## 3) Invoke the inline code, optionally retrieving the return value. You can
## set the return values in your inline code by assigning it to the
## "return" collection as shown above.
##
## $result = Invoke-Inline $usingStatements, $codeToRun $arguments
## $result = Invoke-Inline $codeToRun $arguments
##
##
## If your code is simple enough, you can even do this entirely inline:
##
## Invoke-Inline "Console.WriteLine(Math.Pow(337,2));"
##
################################################################################
function Invoke-Inline()
{
param(
[string[]] $code,
[object[]] $arguments,
[string[]] $reference = @()
)
## Stores a cache of generated inline objects. If this library is dot-sourced
## from a script, these objects go away when the script exits.
if(-not (Test-Path Variable:\inlineCode.Cache))
{
${GLOBAL:inlineCode.Cache} = @{}
}
$using = $null;
$source = $null;
if($code.length -eq 1) {
$source = $code[0]
} elseif($code.Length -eq 2){
$using = $code[0]
$source = $code[1]
} else {
Write-Error "You have to pass some code, or this won't do anything ..."
}
## un-nesting magic (why do I need this?)
$params = @()
foreach($arg in $arguments) { $params += $arg }
$arguments = $params
## The main function to execute inline C#.
## Pass the argument to the function as a strongly-typed variable. They will
## be available from C# code as the Object variable, "arg".
## Any values assigned to the "returnValue" object by the C# code will be
## returned to MSH as a return value.
## See if the code has already been compiled and cached
$cachedObject = ${inlineCode.Cache}[$source]
#Write-Verbose "Type: $($arguments[0].GetType())"
## The code has not been compiled or cached
if($cachedObject -eq $null)
{
$codeToCompile =
@"
using System;
using System.Collections.Generic;
$using
public class InlineRunner
{
public List