Subject: Import this into a new agent. Use SendConsoleCommand to report ServerAvailabilityIndex
This code uses the SendConsoleCommand to tell you which of two named servers is the least loaded.
Don’t use it if your agent signer doesn’t have rights to run console commands.
Don’t use it before you distribute each document, because the act of sending console commands itself will slow the server, and your Notes Admins will not welcome a thousands of console messages in the server log.
Use it only once to choose the least loaded server for your document upload.
'Agent: “Which server is free?”:
’
’
’ Run as menu-triggered agent, target = None.
’
Option Public
Option Declare
%INCLUDE “lsxbeerr.lss”
Class ServerAvailabilityComparator
'
' Allows comparison of the relative availability of two servers, using SendConsoleCommand to return ServerAvailabilityIndex statistics from each.
'
'
' 20/03/07 Martin Audley Written. Released in Public Domain. No warranty.
Private m_Session As NotesSession
Private m_MaximumAvailableServer As String
Private m_MaxAvailabilityIndexPercent As Integer
Private m_sServerAvailabilityList List As Integer
Sub New(sServer1$,sServer2$)
'
' Constructor takes the names of two of your domains Notes servers.
'
Set m_session = New NotesSession
m_sServerAvailabilityList%(sServer1$)=0
m_sServerAvailabilityList%(sServer2$)=0
If Not Me.RefreshAvailability Then
Error Err,Error$ & " at line " & Erl & " in " & Getthreadinfo(2) ' Return Nothing from class object constructor
End If
End Sub
Public Function RefreshAvailability
'
' Force reload of server availability percentages
'
Const CONSOLE_COMMAND$ = "show stat server.AvailabilityIndex"
Dim sServerName$
Dim sConsoleReturn$
Dim sConsoleReturnFirstLine$
Dim vAvailabilityIndexPercent As Variant
Dim sAvailabilityIndexPercent$
Dim iAvailabilityIndexPercent%
On Error Goto ErrHandler
On Error 4000 Goto ErrHandler4000
m_MaximumAvailableServer$ = ""
m_MaxAvailabilityIndexPercent% = 0
Forall vServerEntry In m_sServerAvailabilityList
sServerName$ = Listtag(vServerEntry)
sConsoleReturn$ = Trim(m_session.SendConsoleCommand( sServerName$, CONSOLE_COMMAND$))
If Instr(sConsoleReturn$,Chr$(13))>0 Then
sConsoleReturnFirstLine$ = Left(sConsoleReturn$,Instr(sConsoleReturn$,Chr$(13))-1)
vAvailabilityIndexPercent = Split(sConsoleReturnFirstLine$," = ",2)
sAvailabilityIndexPercent$ = vAvailabilityIndexPercent(1)
iAvailabilityIndexPercent% = Cint(sAvailabilityIndexPercent$)
m_sServerAvailabilityList%(sServerName$)=iAvailabilityIndexPercent%
If iAvailabilityIndexPercent% > m_MaxAvailabilityIndexPercent% Then
m_MaxAvailabilityIndexPercent% = iAvailabilityIndexPercent%
m_MaximumAvailableServer$ = sServerName$
End If
End If
End Forall
RefreshAvailability = True
ExitPoint:
Exit Function
ErrHandler4000: ’ Error opening server
m_MaximumAvailableServer$ = ""
m_MaxAvailabilityIndexPercent% = 0
Error Err,Error$ & | (| & Err & |) at line | & Erl & | in | & Getthreadinfo(2) & | while examining server "| & sServerName$ & |"|
ErrHandler:
m_MaximumAvailableServer$ = ""
m_MaxAvailabilityIndexPercent% = 0
Error Err,Error$ & | (| & Err & |) at line | & Erl & | in | & Getthreadinfo(2)
End Function
Public Property Get MaximumAvailableServer As String
'
' Return the name of the most available of your two servers
'
MaximumAvailableServer$ = m_MaximumAvailableServer$
End Property
Public Property Get MaximumAvailablePercent As Integer
'
' Return the most available server's AvailabilityIndex
'
MaximumAvailablePercent% = m_MaxAvailabilityIndexPercent
End Property
End Class
Class TestHarness
'
' Test of ServerAvailabilityComparator
'
Sub New
Dim sServerName1$,sServerName2$
sServerName1$ = Inputbox("Enter first server name for availability comparison:")
sServerName2$ =Inputbox("Enter second server name for availability comparison:")
On Error Goto TrapErrorInTestHarness
Dim serveravailability As New ServerAvailabilityComparator(sServerName1$,sServerName2$) ' Compare two servers for availability
On Error Goto 0
If Not serveravailability Is Nothing Then
Messagebox serveravailability.MaximumAvailableServer$ & " (" & serveravailability.MaximumAvailablePercent% & "%)" ,0,"Your most available server"
End If
ExitPoint:
Exit Sub
TrapErrorInTestHarness:
Messagebox "No comparison possible",16,"Warning"
Resume ExitPoint
End Sub
End Class
Sub Initialize
Dim th As New TestHarness
End Sub