Tip

Record live view index size information

This tip records the index size of all views in a given database by issuing a console command and parsing the response. The same information is available in the Notes log, but it is not "live."

There may be easier/better ways to do it, but this works. Paste the code into an agent/button, then add the call to the main sub in the initialize event of the agent or the click event of the button. Note that the signer/user should have access to issue the "show database" console command on the server where the target database resides. The results are written to a file in the temporary directory of the current workstation.

dgg 
  
  Sub main()
 On Error Goto errorHandler
 
 Dim nsess As NotesSession
 Dim ndbTarget As NotesDatabase
 Dim intHdrLocation As Integer
 Dim strServerName As String
 Dim strReplicaID As String
 Dim varResults As Variant
 
 Set nsess = New NotesSession
 Set ndbTarget = New NotesDatabase("", "")
 
'// Get the server name on which the 
target database resides.
 strServerName$ = Trim$(Inputbox
("Please enter the server name.", "Enter 
server name . . .", 
nsess.CurrentDatabase.Server))
 If Len(strServerName$) = 0 Then
  Print "Action cancelled . . ."
  Goto subExit
 End If
 
'// Get the replica ID of the target database.
 strReplicaID$ = Trim$(Inputbox
("Please enter the replica ID of the target 
database.", "Enter the replica ID . . .", ""))
 strReplicaID$ = Replace(strReplicaID$, ":", "")
 If Len(strReplicaID$) = 0 Then
  Print "Action cancelled . . ."
  Goto subExit
 End If
 
'// Attempt to open the database using the 
information provided.
 If Not(ndbTarget.OpenByReplicaID
(strServerName$, strReplicaID$)) Then
  Msgbox "Failed to open a database on "
 & strServerName$ & " using replica 
id " & strReplicaID$ & " - unable to proceed.", , 
"Failed to open a 
database . . ."
  Goto subExit
 End If
 
'// Issue the command to the server.
 varResults = 
nSess.SendConsoleCommand(ndbTarget.Server,
 "show database " & 
ndbTarget.FilePath)
 varResults = Replace(varResults, Chr(10), "") 
'// remove line feeds
 
'// Write results to an array for processing.
 varResults = Split(varResults, Chr(13))
 If Not(trimConsoleResponse(varResults)) Then
  Goto subExit
 End If
 
'// Get the location of the "header" for the
 view information.
 If Not(locateViewHeader(intHdrLocation%, 
varResults)) Then
  Goto subExit
 End If
 
'// Now record the results.
 Call recordData(nsess, ndbTarget,
 intHdrLocation%, varResults)
 
subExit:
 Exit Sub
 
errorHandler:
 Msgbox "Error " & Err & ": " & Error$ & 
" encountered at line " & Erl & " 
of " & Getthreadinfo(1) & ".", , 
"Error encountered . . ."
 Print "Error " & Err & ": " & Error$ & 
" encountered at line " & Erl & " of " 
& Getthreadinfo(1) & " . . ."
 Resume subExit
End Sub

Function trimConsoleResponse
(pvarResults As Variant) As Boolean
 On Error Goto errorHandler
 
 trimConsoleResponse = False
 If Isarray(pvarResults) Then
  Forall rez In pvarResults
   rez = Ltrim$(Rtrim$(rez))
  End Forall
  trimConsoleResponse = True
 End If
 
functionExit:
 Exit Function
 
errorHandler:
 Msgbox "Error " & Err & ": " & Error$ 
& " encountered at line " & Erl & " 
of " & Getthreadinfo(1) & ".", , 
"Error encountered . . ."
 Print "Error " & Err & ": " & Error$ 
& " encountered at line " & Erl & " of " 
& Getthreadinfo(1) & " . . ."
 Resume functionExit
End Function

Function locateViewHeader
(pintPositionOut As Integer, pvarResults 
As Variant) 
As Boolean
 On Error Goto errorHandler
 
 Const VIEW_HEADER = "VIEW SIZES"
 Dim i As Integer
 
 locateViewHeader = False
 i = - 1
 Forall rez In pvarResults
  i = i + 1
  If Instr(1, rez, VIEW_HEADER, 5) > 0 
Then
   pintPositionOut% = i
   locateViewHeader = True
   Goto functionExit
  End If
 End Forall
 
functionExit:
 Exit Function
 
errorHandler:
 Msgbox "Error " & Err & ": " & Error$ 
& " encountered at line " & Erl & " 
of " & Getthreadinfo(1) & ".", , 
"Error encountered . . ."
 Print "Error " & Err & ": " & Error$ & 
" encountered at line " & Erl & " of " 
& Getthreadinfo(1) & " . . ."
 Resume functionExit
End Function

Sub recordData(pnsess As NotesSession, 
pndbTarget As NotesDatabase, 
pintHdrLocation As Integer, 
pvarResults As Variant)
 On Error Goto errorHandler
 
 Const EOL_PLATFORM = 3
 Dim streamOut As NotesStream
 Dim i As Integer
 Dim j As Integer
 Dim strFilePath As String
 Dim strThisValue As String
 Dim strThisChar As String
 Dim strViewSize As String
 Dim strViewName As String * 64
 Dim strBuff As String * 32
 
 Set streamOut = pnsess.
CreateStream()
 strFilePath$ = Environ$("Temp") 
& "view_detail.txt"
 If Not(streamOut.Open(strFilePath$, 
"UTF-8")) Then
  Msgbox "Unable to open file (" & 
strFilePath$ & ") for recording 
results.", , "Unable to open file . . ."
  Goto subExit
 End If
 
 Call streamOut.WriteText
("Date recorded:   " & Format(Now ,"mm/dd/yyyy 
hh:nn:ss"), EOL_PLATFORM)
 Call streamOut.WriteText("Database title: 
 " & pndbTarget.Title, EOL_PLATFORM)
 Call streamOut.WriteText("Database server:
 " & pndbTarget.Server, 
EOL_PLATFORM)
 Call streamOut.WriteText("Database path: 
  " & pndbTarget.FilePath, 
EOL_PLATFORM)
 Call streamOut.WriteText("", EOL_PLATFORM)
 
'// Add the header for each "column" in the file.
 strViewName$ = "View name:"
 Call streamOut.WriteText(strViewName$)
 
 Rset strBuff$ = "Size in bytes:"
 Call streamOut.WriteText(strBuff$,
 EOL_PLATFORM)
 
'// Start at the next value following the 
offset (ie, the location of the 
header).
 For i = (pintHdrLocation% + 1) To 
Ubound(pvarResults)
  strThisValue$ = pvarResults(i)
  If Len(Trim$(strThisValue$)) > 0 Then
   strViewSize$ = ""
   For j = Len(strThisValue$) To 1 Step -1
    strThisChar$ = Right(Left
(strThisValue$, j), 1)
    If Isnumeric(strThisChar$) Then
     strViewSize$ = strThisChar$ & 
strViewSize$
    Elseif strThisChar$ = "," Then
     strViewSize$ = strThisChar$ & 
strViewSize$
    Else
     Exit For
    End If
   Next j
   
   strViewName$ = Rtrim(Strleft
(strThisValue$, strViewSize$))
   Rset strBuff$ = strViewSize$
   Call streamOut.WriteText(strViewName$ 
& strBuff$, EOL_PLATFORM)
  End If
 Next i
 
 Call streamOut.WriteText("----", 
EOL_PLATFORM)
 Print "Results saved to " 
& strFilePath$ & " . . ."
 
subExit:
 If Not(streamOut Is Nothing) Then
  Call streamOut.Close()
  Set streamOut = Nothing
 End If
 Exit Sub
 
errorHandler:
 Msgbox "Error " & Err & ": " 
& Error$ & " encountered at line " & Erl & " 
of " & Getthreadinfo(1) & ".", ,
 "Error encountered . . ."
 Print "Error " & Err & ": " & Error$ 
& " encountered at line " & Erl & " of " 
& Getthreadinfo(1) & " . . ."
 Resume subExit 
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Dallas Gimpel. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in October 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.