Forum Discussion
Steffen_Beach_8
Feb 15, 2010Nimbostratus
Okay, now I've really have the problem knocked out. Apparently I was getting back no name pools (I believe for virtul servers with no default pool assigned) and when trying to fetch stats for and empty object the iControl method for get_statistics doesn't play nice. Anyway, I added in a quick method to prune out empty objects from the .get_default_pool_name method, and presto, the stats collection went from just over 3 minutes down to just under 2 seconds! Massive improvement!
Here is the final test (not super elegant, and still has some debugging info and a timer) code if anyone wants:
using System;
using System.Collections.Generic;
using System.Text;
using iControl;
using System.Diagnostics;
namespace iControlInterface
{
class Program
{
static void Main(string[] args)
{
Interfaces m_interfaces = new Interfaces();
string ipAddress = "*******";
string user = "*******";
string pass = "*******";
//Initalize the f5 interface
m_interfaces.initialize(ipAddress, user, pass);
//Check if inialized
if (!m_interfaces.initialized)
Environment.Exit(Environment.ExitCode);
//Get the partition list to drop into PROD
ManagementPartitionAuthZPartition[] partitionList = m_interfaces.ManagementPartition.get_partition_list();
for (int i = 0; i < partitionList.Length; i++)
{
if (partitionList[ i ].partition_name == "PROD")
m_interfaces.ManagementPartition.set_active_partition(partitionList[ i ].partition_name);
}
// TEST DATA
//string[] vsName = new string[1];
//vsName[0] = "vs_products_http";
//string[] localDefaultPools = m_interfaces.LocalLBVirtualServer.get_default_pool_name(vsName);
// END TEST DATA
//Get all virtual servers
string[] localVirtualServers = m_interfaces.LocalLBVirtualServer.get_list();
//PrintInfo(localVirtualServers);
//Get all the active default pools
string[] localDefaultPools = m_interfaces.LocalLBVirtualServer.get_default_pool_name(localVirtualServers);
//PrintInfo(localDefaultPools);
//Get the pool stats
LocalLBPoolPoolStatistics poolStats = new LocalLBPoolPoolStatistics();
//Get the pool stat entries
LocalLBPoolPoolStatisticEntry[] poolStatEntries;
//Load the localDefaultPools into a List object to prune and perform batch get_statistics with
List localDefaultPoolsList = RemoveNoNamePools(localDefaultPools);
string[] poolBatch;
int batchCount = 1;
Stopwatch timer = new Stopwatch();
timer.Start();
//Break the statistics rquests into batchs of XX
while(localDefaultPoolsList.Count > 0)
{
if(localDefaultPoolsList.Count >= 10)
{
poolBatch = localDefaultPoolsList.GetRange(localDefaultPoolsList.Count - 10, 10).ToArray();
localDefaultPoolsList.RemoveRange(localDefaultPoolsList.Count - 10, 10);
poolStats = m_interfaces.LocalLBPool.get_statistics(poolBatch);
poolStatEntries = poolStats.statistics;
PrintStatistics(poolStatEntries);
}
else
{
poolBatch = localDefaultPoolsList.ToArray();
localDefaultPoolsList.Clear();
poolStats = m_interfaces.LocalLBPool.get_statistics(poolBatch);
poolStatEntries = poolStats.statistics;
PrintStatistics(poolStatEntries);
}
Console.WriteLine("Batch {0} time elapsed: {1}", batchCount.ToString(), timer.Elapsed.ToString());
batchCount++;
}
Console.WriteLine("Total time elapsed: {1}", batchCount.ToString(), timer.Elapsed.ToString());
timer.Stop();
}
private static List RemoveNoNamePools(string[] localDefaultPools)
{
List localDefaultPoolsList = new List();
foreach (string poolName in localDefaultPools)
{
if (poolName != "")
localDefaultPoolsList.Add(poolName);
}
return localDefaultPoolsList;
}
public static void PrintInfo(string[] info)
{
for (int i = 0; i > info.Length; i++)
{
Console.WriteLine(info[ i ].ToString());
}
}
public static void PrintStatistics(LocalLBPoolPoolStatisticEntry[] poolStatEntries)
{
//Loop through each pool and print out the server side current connection stats
for (int i = 0; i < poolStatEntries.Length; i++)
{
CommonStatistic[] commonStats = poolStatEntries[ i ].statistics;
for (int x = 0; x < commonStats.Length; x++)
{
if (commonStats[x].type == CommonStatisticType.STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS && poolStatEntries[ i ].pool_name != "")
{
CommonULong64 commonValue = commonStats[x].value;
Console.WriteLine("Pool name: {0} Current connections: {1}", poolStatEntries[ i ].pool_name, commonValue.low.ToString());
}
}
}
}
}
}