From 05e35e96d043f7ac2715aebb60351335693bb4b9 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Mon, 30 Jul 2012 08:43:32 +0000
Subject: [PATCH] OPENDJ-554: Record stats for one-level and whole-subtree searches

---
 opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
index edd2bfc..28ab04d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
@@ -23,6 +23,8 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2012 ForgeRock AS
+ *
  */
 package org.opends.server.protocols.ldap;
 
@@ -99,6 +101,8 @@
   private AtomicLong operationsCompleted = new AtomicLong(0);
   private AtomicLong operationsInitiated = new AtomicLong(0);
   private AtomicLong searchRequests = new AtomicLong(0);
+  private AtomicLong searchOneRequests = new AtomicLong(0);
+  private AtomicLong searchSubRequests = new AtomicLong(0);
   private AtomicLong searchResultEntries = new AtomicLong(0);
   private AtomicLong searchResultReferences = new AtomicLong(0);
   private AtomicLong searchResultsDone = new AtomicLong(0);
@@ -218,6 +222,8 @@
       long tmpOperationsCompleted = operationsCompleted.get();
       long tmpOperationsInitiated = operationsInitiated.get();
       long tmpSearchRequests = searchRequests.get();
+      long tmpSearchOneRequests = searchOneRequests.get();
+      long tmpSearchSubRequests = searchSubRequests.get();
       long tmpSearchEntries = searchResultEntries.get();
       long tmpSearchReferences = searchResultReferences.get();
       long tmpSearchResultsDone = searchResultsDone.get();
@@ -295,6 +301,10 @@
         .valueOf(tmpModifyDNResponses)));
     attrs.add(createAttribute("searchRequests", String
         .valueOf(tmpSearchRequests)));
+    attrs.add(createAttribute("searchOneRequests", String
+            .valueOf(tmpSearchOneRequests)));
+    attrs.add(createAttribute("searchSubRequests", String
+            .valueOf(tmpSearchSubRequests)));
     attrs.add(createAttribute("searchResultEntries", String
         .valueOf(tmpSearchEntries)));
     attrs.add(createAttribute("searchResultReferences", String
@@ -412,6 +422,8 @@
       operationsCompleted.set(0);
       operationsInitiated.set(0);
       searchRequests.set(0);
+      searchOneRequests.set(0);
+      searchSubRequests.set(0);
       searchResultEntries.set(0);
       searchResultReferences.set(0);
       searchResultsDone.set(0);
@@ -518,6 +530,23 @@
         break;
       case OP_TYPE_SEARCH_REQUEST:
         searchRequests.getAndIncrement();
+        SearchRequestProtocolOp s = (SearchRequestProtocolOp)message
+            .getProtocolOp();
+        switch (s.getScope())
+        {
+        case BASE_OBJECT:
+            // we don't count base object searches as
+            // this value can be derived from the others
+            break;
+        case SINGLE_LEVEL:
+            searchOneRequests.getAndIncrement();
+            break;
+        case WHOLE_SUBTREE:
+            searchSubRequests.getAndIncrement();
+            break;
+        default:
+            break;
+        }
         break;
       case OP_TYPE_UNBIND_REQUEST:
         unbindRequests.getAndIncrement();
@@ -940,6 +969,30 @@
 
 
   /**
+   * Retrieves the number of one-level search requests that have been received.
+   *
+   * @return The number of one-level search requests that have been received.
+   */
+  public long getSearchOneRequests()
+  {
+      return searchOneRequests.get();
+  }
+
+
+
+  /**
+   * Retrieves the number of subtree search requests that have been received.
+   *
+   * @return The number of subtree search requests that have been received.
+   */
+  public long getSearchSubRequests()
+  {
+      return searchSubRequests.get();
+  }
+
+
+
+  /**
    * Retrieves the number of search result entries that have been sent.
    *
    * @return The number of search result entries that have been sent.

--
Gitblit v1.10.0