views:

303

answers:

2

I have a number of databases on a Domino Server (version 8.5) which I need to find the counts of:

  • the number of documents in total per NSF
  • the number of documents in the "All Documents" view per NSF

Is there any simple way of getting Domino Server 8.5 to display this?

Many thanks Chris

+2  A: 

You can get the number of documents per NSF by enabling the Domain Catalog task on one of your domain's servers. That will create a domain catalog database (catalog.nsf) with information on all the databases in the domain. You can then create a custom view in that database to organize the databases by total documents, etc.

Unfortunately the cataloging process doesn't track how many documents are in each view. Furthermore, there's no guarantee each database even has an All Documents view. That view is part of many database design templates like Mail or Discussions, but it is really just a design element and not something fundamental to every notes database.

Here is some code you can run to fetch that information for you on a given server. Note, this code is pretty slow.

Sub CountDocuments()

'Handle database not open error
On Error Goto ProcessError
On Error 4060 Goto ProcessNotOpenError
On Error 4063 Goto ProcessNotOpenError
On Error 4185 Goto ProcessNotOpenError

'Constants
Const SERVERNAME = "SERVER/DOMAIN"
Const FILENAME = "C:\database_entry_counts.csv"

 'Initialize Objects
Dim s As New Notessession
Dim db As Notesdatabase
Dim dbDirectory As NotesDbDirectory
Dim docCollection As NotesDocumentCollection
Dim doc As NotesDocument
Dim strRow As String
Dim numDocs As Long, numAllDocs As Long
Dim viewAllDocs As NotesView
Dim vecAllDocs As NotesViewEntryCollection
Dim ve As NotesViewEntry
Dim docCount As Long

 'Get Database Directory
Set dbDirectory = s.GetDbDirectory(SERVERNAME)
Set db = dbDirectory.GetFirstDatabase(DATABASE)
flag = db.Open( "", "" )     
While flag = False  'Get next database if first can't be opened
    Set db = dbDirectory.GetNextDatabase
    flag = db.Open( "", "" )     
Wend

'Open output file   
Set stream = s.CreateStream
If Not stream.Open(FILENAME, "ASCII") Then
    Messagebox FILENAME,, "Open failed"
    Exit Sub
End If
If stream.Bytes <> 0 Then
    Messagebox FILENAME,, "File already exists and has content"
    Exit Sub
End If

'Output headers
Call stream.WriteText(|"Database Name","Total Documents","Count of All Documents"|, EOL_CRLF)


 'Main Loop
While Not (db Is Nothing)

    Print "Working on: " & db.Title

    docCount = 0
    strRow = ""

    'Get number of documents in database (easy)
    numDocs = db.AllDocuments.Count

    'Get number of documents in view (annoyingly difficult)
    Set viewAllDocs = db.GetView("($All)")
    If Not (viewAllDocs Is Nothing) Then
        Set vecAllDocs = viewAllDocs.AllEntries
        Set ve = vecAllDocs.GetFirstEntry
        While Not (ve Is Nothing)
            If ve.IsDocument Then docCount = docCount + 1           
            Set ve = vecAllDocs.GetNextEntry(ve)
        Wend
    Else
        docCount = 0
    End If

    'Output values to our comma delimited list
    strRow = |"| & db.Title & |","| & numDocs & |","| & docCount & |"|
    Call stream.WriteText(strRow, EOL_CRLF)

    'Get next database that can be opened
    Set db = dbDirectory.GetNextDatabase
    If Not (db Is Nothing) Then flag = db.Open( "", "" )
    While flag = False  
        Set db = dbDirectory.GetNextDatabase
        If Not (db Is Nothing) Then flag = db.Open( "", "" )     
    Wend

Wend

'Close file
Call stream.Close

Exit Sub

ProcessNotOpenError:

Resume Next

ProcessError:

Messagebox "Error " & Err() & ": " & Error()
If Not stream Is Nothing Then
    stream.Close
End If

Exit Sub

End Sub

This will output a CSV file with the database name, and the counts you're looking for, provided you run this with an account that has access to all the databases on your server.

Ken Pespisa
A: 

I would create my own "MyStats.nsf" database on the server. This db will contain an LotusScript Agent "UpdateAll" triggered each n hours.

The agent basically get a list of database paths. For each path open the database. The NotesDatabase.AllDocuments.Count gives you the total number of docs. Open the view "($All)" and retrive NotesView.AllEntries.Count the nr. of docs. for "All Documents". Take this information and create a new NotesDocument to save db name and the retrieved number info. Last but not least create a view in MyStat to display the result.

PeterMmm