Retrieve Server Statistics Individually

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 <stat 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$

stat$="Server.Version.OS"
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.
'(Declarations)
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$,

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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
hLock&=OSLockObject(hTable%)

' 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)
sReturn$=""
vLoop=True

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
vLoop=False
Else
sReturn$ = sReturn$ & sHold$
hLock& = hLock& + 1
End If
Loop

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

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

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.