Forum Discussion
Steffen_Beach_8
Nimbostratus
Feb 15, 2010Polling all current connections from all default pools
So I've been playing around with iControl in preparation of building a custom web interface for my NOC and deployment tool for us engineers. While doing what I would think would be a simple query (sni...
Steffen_Beach_8
Nimbostratus
Feb 16, 2010Thanks Joe. Instead of storing the CommonStat value in an object, I'm just converting the .low value directly to a string and outputting that.
Here's a more polished version:
using System;
using System.Collections.Generic;
using System.Text;
using iControl;
using System.Diagnostics;
namespace PRVD.iControl.GetAllPoolCurrentConnections
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 3 || string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || string.IsNullOrEmpty(args[2]))
{
Console.WriteLine(
"Usage: f5GetAllPoolCurrentConnections [username] [password] [hostname or ip address] optional [partition]");
return;
}
string user = args[0];
string pass = args[1];
string ipAddress = args[2];
string partition = "";
if (args.Length > 3 && !string.IsNullOrEmpty(args[3]))
partition = args[3];
Interfaces m_interfaces = new Interfaces();
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
bool partitionFound = false;
ManagementPartitionAuthZPartition[] partitionList = m_interfaces.ManagementPartition.get_partition_list();
for (int i = 0; i < partitionList.Length; i++)
{
Console.WriteLine("Partition found: {0}", partitionList[ i ].partition_name);
if (partitionList[ i ].partition_name == partition)
{
m_interfaces.ManagementPartition.set_active_partition(partitionList[ i ].partition_name);
partitionFound = true;
}
}
if (!partitionFound)
{
Console.WriteLine("The partition '{0}' specified was not found.", partition);
return;
}
//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 != "")
{
Console.WriteLine("Pool name: {0} Current connections: {1}", poolStatEntries[ i ].pool_name, commonStats[x].value.low.ToString());
}
}
}
}
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects