Forum Discussion
OTS02
Cirrus
Feb 02, 2009show current connections with VB
Could someone provide me with a example of how to show current connections for a particular pool member in VB?
Thanks
- I don't have an example handy in VB, but I just wrote this on in C this morning querying stats for virtual servers and pools. The PoolMember.get_statistics method behaves the same way. It should get you going in the right direction.
public iControl.CommonULong64 FindStatistic( iControl.CommonStatistic [] stats, iControl.CommonStatisticType type ) { iControl.CommonULong64 ul64Value = null; for(int i=0; i { if ( stats[ i ].type == type ) { ul64Value = stats[ i ].value; break; } } return ul64Value; } public void GetMetrics( string[] vsList, string[] poolList ) { if ((0 != vsList.Length) || (0 != poolList.Length)) { WriteHeader(); while (true) { System.DateTime now = DateTime.Now; if (vsList.Length > 0) { iControl.LocalLBVirtualServerVirtualServerStatistics stats = m_interfaces.LocalLBVirtualServer.get_statistics(vsList); for (int i = 0; i < stats.statistics.Length; i++) { iControl.CommonULong64 bytesIn = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_IN); iControl.CommonULong64 bytesOut = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_OUT); iControl.CommonULong64 currConn = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_CLIENT_SIDE_CURRENT_CONNECTIONS); WriteLine(now, "vs", stats.statistics[ i ].virtual_server.name, bytesIn, bytesOut, currConn); } } if (poolList.Length > 0) { iControl.LocalLBPoolPoolStatistics stats = m_interfaces.LocalLBPool.get_statistics(poolList); for(int i=0; i { iControl.CommonULong64 bytesIn = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_SERVER_SIDE_BYTES_IN); iControl.CommonULong64 bytesOut = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_SERVER_SIDE_BYTES_OUT); iControl.CommonULong64 currConn = FindStatistic(stats.statistics[ i ].statistics, iControl.CommonStatisticType.STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS); WriteLine(now, "pool", stats.statistics[ i ].pool_name, bytesIn, bytesOut, currConn); } } System.Threading.Thread.Sleep(m_delay); } } }
- OTS02
Cirrus
I cannot make the call properly. I have variables for address, port & pool name (member_ip, member_port, pool_name). I can't seem to put anything together that works. - OTS02
Cirrus
Here is the latest thing I've tried: - You'll need to allocate the first entry in the 2-d array to be contain the second level array.
Dim memdef()() As iControl.CommonIPPortDefinition = _ New iControl.CommonIPPortDefinition(0)() {} memdef(0) = New iControl.CommonIPPortDefinition(0) memdef(0)(0) = New iControl.CommonIPPortDefinition memdef(0)(0).address = member_ip ...
- OTS02
Cirrus
Thanks Joe, - This should do it for you. This is a VB console app that takes as input a pool name and a single member ip/port and displays the statistics for it. You should be able to extend this by adding more values to the arrays. You could also use the LocalLBPool.get_member() method to return the members for the supplied pool name and use that as the array values.
Module Module1 Dim m_interfaces As iControl.Interfaces = New iControl.Interfaces() Public Class CApp Public Sub Run() Dim args As String() = System.Environment.GetCommandLineArgs() If (args.Length < 7) Then Usage() Else If (m_interfaces.initialize(args(1), args(2), args(3))) Then GetPoolMemberStats(args(4), args(5), Convert.ToInt32(args(6))) End If End If End Sub Public Sub Usage() Console.WriteLine("VBTest.exe bigip username password pool member port") End Sub Public Sub GetPoolMemberStats(ByVal pool As String, ByVal member_addr As String, ByVal member_port As Integer) Dim poolNameA() As String = New String() {pool} ' Declare jagged (2-d) array for member definitions Dim memberDefAofA()() As iControl.CommonIPPortDefinition memberDefAofA = New iControl.CommonIPPortDefinition(0)() {} ' Allocate the first dimesion memberDefAofA(0) = New iControl.CommonIPPortDefinition(0) {} ' allocate the second dimension memberDefAofA(0)(0) = New iControl.CommonIPPortDefinition() memberDefAofA(0)(0).address = member_addr memberDefAofA(0)(0).port = member_port Dim memberStatsA() As iControl.LocalLBPoolMemberMemberStatistics memberStatsA = m_interfaces.LocalLBPoolMember.get_statistics(poolNameA, memberDefAofA) Dim memberAddr As String Dim memberPort As Integer Dim type As iControl.CommonStatisticType Dim Value As iControl.CommonULong64 ' Loop over all the pools For i As Integer = 0 To poolNameA.Length - 1 ' Loop over all the pool members for each pool For j As Integer = 0 To memberStatsA(i).statistics.Length - 1 memberAddr = memberStatsA(i).statistics(j).member.address memberPort = memberStatsA(i).statistics(j).member.port Console.WriteLine("Stats for Pool " & poolNameA(i) & " member " & _ memberAddr & ":" & memberPort.ToString()) ' Loop over all the metrics for each pool member For k As Integer = 0 To memberStatsA(i).statistics(j).statistics.Length - 1 type = memberStatsA(i).statistics(j).statistics(k).type Value = memberStatsA(i).statistics(j).statistics(k).value Console.WriteLine(" " & type.ToString() & " = (" & Value.high.ToString() & ", " & Value.low.ToString() & ")") Next Next Next End Sub End Class Sub Main() Dim theApp As CApp theApp = New CApp theApp.Run() End Sub End Module
- OTS02
Cirrus
Thank you Joe! Thanks for your patience with a coding newbie. Thanks for richly commenting the code. - Hopefully this works for you. C seems very intuitive to me but when it gets to VB and arrays, it always takes me a while to figure it out.
- OTS02
Cirrus
Yes I got what I needed, thanks again. - OTS02
Cirrus
I am giving up on VB, and am attempting c. I am having trouble making this work:
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