I have written the below Powershell function to call an F5 unit. It loops round for each server and gets each individual stat and then executes a SQL SMO call.
The code is running really slowly and i think i have discounted the SQL call as the cause.
How can the powershell be improved?
function Print-VServerStats()
{
param($virtual_server);
$VirtualServerStatistics = (Get-F5.iControl).LocalLBVirtualServer.get_statistics( (, $virtual_server) );
$VirtualServerStatisticEntry = $VirtualServerStatistics.statistics[0];
$Statistics = $VirtualServerStatisticEntry.statistics | ? {$_.type -eq "STATISTIC_CLIENT_SIDE_CURRENT_CONNECTIONS" -or
$_.type -eq "STATISTIC_CLIENT_SIDE_MAXIMUM_CONNECTIONS" -or
$_.type -eq "STATISTIC_CLIENT_SIDE_TOTAL_CONNECTIONS"};
foreach ($Statistic in $Statistics)
{
$val = Convert-To64Bit $Statistic.value.high $Statistic.value.low;
switch ($Statistic.type) {
"STATISTIC_CLIENT_SIDE_CURRENT_CONNECTIONS" {
$label = "Current Connections";
}
"STATISTIC_CLIENT_SIDE_MAXIMUM_CONNECTIONS" {
$label = "Max Connections";
}
"STATISTIC_CLIENT_SIDE_TOTAL_CONNECTIONS" {
$label = "Total Connections";
}
}
$profcmd.Parameters["@property"].Value = $SrceName
$profcmd.Parameters["@propertyDesc"].Value = $label
$profcmd.Parameters["@ValDim1"].Value = $virtual_server
$profcmd.Parameters["@value"].Value = $val
$profcmd.Parameters["@Timestamp"].Value = $t
[void]$profcmd.ExecuteNonQuery()
}
}