Collect database statistics using database directory

Using the database directory class is a great way to collect database statistics for a given server. By using getFirstDatabase and getNextDatabase, a subset of the database information can be retrieved without actually opening the database. This information includes database title, type, path, name, size and other various properties. The java class works very quickly and can collect data for all databases on a server within seconds. You could use this class to write statistics using a JDBC connection, and/or to collect data periodically for statistical growth charts or monitoring.

  
  import lotus.domino.*;
public class JavaAgent extends AgentBase {
 public String serverName = null;
 public DbDirectory dir = null;
 public double totalsize = 0;
 public double size = 0;
 
 public void NotesMain() 
 {
  
      try 
  {
        Session session = getSession();
        AgentContext agentContext = 
session.getAgentContext();
   serverName = "DSTALPHA";
        dir = session.getDbDirectory(serverName);
        serverName = dir.getName();

       if (serverName.equals("")) 
serverName = "Local";
       System.out.println ("Database 
directory list on server " + serverName 
+ "n");
       Database db = dir.getFirstDatabase
(DbDirectory.DATABASE);
       while (db != null) 
   {
    try
    {
            String fn = db.getFileName();
            String title = db.getTitle();
        size = db.getSize();
            totalsize = totalsize + size;
            System.out.println(fn.toUpperCase() 
+ " - " + title + " is " + 
Long.toString((long) size) + " bytes");
            db = dir.getNextDatabase(); 
           }
           catch (NotesException e)
     {
      db = dir.getNextDatabase(); 
      System.out.println("Unable to open 
database.");
     }
      } //end while
  dir.recycle();
  } 
  catch (NotesException e)
  {
   e.printStackTrace();
  }
  catch(Exception e) 
  {
        e.printStackTrace();
      }
  finally 
  {
       
       System.out.println("The total size 
of all databases on "+ serverName 
+ ": " + Long.toString((long) totalsize) + " bytes");
      }
    }
}

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

This tip was submitted to the SearchDomino.com tip exchange by member Darren Wright. Please let others know how useful it is via the rating scale at the end of the tip. 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 November 2004

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.