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
13 Replies
- 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); } } }
Hope this helps...
-Joe - 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:
Private Sub WatchCurCons(ByVal pool_name As String, ByVal member_ip As String, ByVal member_port As Long)
Dim interfaces As iControl.Interfaces = New iControl.Interfaces
interfaces.initialize(activeunit, "admin", pword) 'change before publishing
Dim pool_names(0) As String
Dim statslist As System.Array
'Dim curcons
Dim memdef()() As iControl.CommonIPPortDefinition = _
New iControl.CommonIPPortDefinition(0)() {}
Dim MemberStatisticsA As iControl.LocalLBPoolMember
memdef(0)(0) = New iControl.CommonIPPortDefinition
memdef(0)(0).address = member_ip
memdef(0)(0).port = member_port
pool_names(0) = pool_name
statslist = MemberStatisticsA.get_statistics(pool_names, memdef)
End Sub
the error is:
memdef (0) (0) = NEW iControl.CommonIPPortDefinition
Object reference not set to an instance of an object.
troubleshootin tips:
Use "new" keywork to create an object instance.
Check to determine if the object is null before calling the method.
I thought that was what I was doing with "memdef(0)(0) = New iControl.CommonIPPortDefinition"
I may not have the background needed to do this kind of thing. I'm but a simple network dude. - You'll need to allocate the first entry in the 2-d array to be contain the second level array.
Something like this: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 ...
You might need to allocate those arrays to size one instead of zero though. I'm away from my dev box right now so I can't test it.
Hope this helps.
-Joe - OTS02
Cirrus
Thanks Joe,
Still not able to instantiate memdef(0). I will keep dorking around with it. - 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
Hope this helps..
-Joe - 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.
Keep at it, it gets easier!
-Joe - OTS02
Cirrus
Yes I got what I needed, thanks again.
I've already been thinking about C. I think that this app will prove the worth of icontrol to the headshed, and I can then justify the time to pick up C. - OTS02
Cirrus
I am giving up on VB, and am attempting c. I am having trouble making this work:
private void WatchCurCons2()
{
string mem_address = "10.189.101.163";
long mem_port = 193;
iControl.CommonIPPortDefinition MemberStatisticEntry = new iControl.CommonIPPortDefinition();
MemberStatisticEntry(0)(0) = New iControl.CommonIPPortDefinition();
MemberStatisticEntry(0)(0).address = iControl.CommonIPPortDefinition(mem_address);
MemberStatisticEntry(0)(0).port = iControl.CommonIPPortDefinition(mem_port);
iControl.LocalLBPoolMemberMemberStatistics MemberStatistics = new iControl.LocalLBPoolMemberMemberStatistics();
iControl.CommonStatisticType type;
iControl.CommonULong64 value;
MemberStatistics = iControl.LocalLBPoolMember.get_statistics(pool_name, MemberStatisticEntry);
}
On the line,
MemberStatisticEntry(0)(0) = New iControl.CommonIPPortDefinition();
.net expects a ";" afer = "New iControl".
Could someone show me a sample bit of code to show current connections for a given pool member?
Thanks
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