Manage Learn to apply best practices and optimize your operations.

Retrieve Server Statistics Individually

This LotusScript function takes a Domino server name and statistic name (e.g.,
Server.Version.OS) and returns the stat's value (access permitting). It is
similar to the "show stat &LTstat name>" console command, except that it does not
echo the stat name (only it's value).

For example, the following button code returns the string "Windows NT 4.0" on a
Domino server with NT 4.0 running on it:

Sub Click(Source As Button)
Dim ret$, stat$

ret$=GetServerStat("MyServer", stat$)
Msgbox stat$ & " = " & ret$, 0, "Server Stats Demo"
End Sub

As it calls a Win32 API function, it will only run on the Win32 platform.
Declare Function NSFGetServerStats% Lib "nnotes" (Byval ServerName$, Byval
Facility$, Byval StatName$, rethTable%, retTableSize&)
Declare Function OSMemFree% Lib "nnotes" (Byval Handle%)
Declare Function OSLockObject& Lib "nnotes" (Byval nHandle%)
Declare Function OSUnlockObject% Lib "nnotes" (Byval nHandle%)

' Win32 API
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Byval pDest$,
Byval pSource&, Byval dwLength&)

Function GetServerStat(sServer$, sArg$) As String
Dim nOffset%, hTable% , nPos%
Dim cbSize&, hLock&
Dim sHold$, sReturn$, sFacility$, sStat$
Dim vLoop

' parse out facility and stat
sFacility$=Left(sArg$, Instr(1, sArg$, ".") - 1)
sStat$=Right(sArg$, Len(sArg$) - Len(sFacility) - 1)

' retrieve the stat
NSFGetServerStats sServer$, sFacility$, sStat$, hTable%, cbSize&

If cbSize& > 0 Then
' lock down the handle to the stat

' locate offset where the stat begins
hOffset%=Len(sFacility$ & "." & sStat$) + 1

' advance to offset and init some vars
hLock&=hLock& + hOffset%
sHold$=String(1, 0)

Do While vLoop
' copy the stat one char at a time
CopyMemory sHold$, hLock&, 1

' loop 'til we find the end of the stat value
If sHold$=Chr$(10) Then
sReturn$ = sReturn$ & sHold$
hLock& = hLock& + 1
End If

' unlock and free the handle
OSUnlockObject hTable%
OSMemFree hTable%

' return the stat
GetServerStat="Not found"
End If
End Function

Dig Deeper on Domino Resources - Part 5

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...