cb_monitor.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #include "cb.h"
  39. extern cb_instance_config_info cb_the_instance_config[];
  40. /*
  41. ** Chaining backend instance monitor function
  42. ** This function wraps up backend specific monitoring information
  43. ** and return it to the client as an LDAP entry.
  44. ** This function is usually called upon receipt of the monitor
  45. ** dn for this backend
  46. **
  47. ** Monitor information:
  48. **
  49. ** Database misc
  50. ** database
  51. **
  52. ** Number of hits for each operation
  53. ** addopcount
  54. ** modifyopcount
  55. ** deleteopcount
  56. ** modrdnopcount
  57. ** compareopcount
  58. ** searchsubtreeopcount
  59. ** searchonelevelopcount
  60. ** searchbaseopcount
  61. ** bindopcount
  62. ** unbindopcount
  63. ** abandonopcount
  64. **
  65. ** Outgoing connections
  66. ** outgoingopconnections
  67. ** outgoingbindconnections
  68. **
  69. */
  70. int
  71. cb_search_monitor_callback(Slapi_PBlock * pb, Slapi_Entry * e, Slapi_Entry * entryAfter, int * returnCode, char * returnText, void * arg)
  72. {
  73. char buf[CB_BUFSIZE];
  74. struct berval val;
  75. struct berval *vals[2];
  76. int deletecount,addcount,modifycount,modrdncount,searchbasecount,searchonelevelcount;
  77. int searchsubtreecount,abandoncount,bindcount,unbindcount,comparecount;
  78. int outgoingconn, outgoingbindconn;
  79. cb_backend_instance *inst = (cb_backend_instance *)arg;
  80. /* First make sure the backend instance is configured */
  81. /* If not, don't return anything */
  82. PR_RWLock_Rlock(inst->rwl_config_lock);
  83. if (!inst->isconfigured) {
  84. *returnCode= LDAP_NO_SUCH_OBJECT;
  85. PR_RWLock_Unlock(inst->rwl_config_lock);
  86. return SLAPI_DSE_CALLBACK_ERROR;
  87. }
  88. PR_RWLock_Unlock(inst->rwl_config_lock);
  89. vals[0] = &val;
  90. vals[1] = NULL;
  91. slapi_lock_mutex(inst->monitor.mutex);
  92. addcount =inst->monitor.addcount;
  93. deletecount =inst->monitor.deletecount;
  94. modifycount =inst->monitor.modifycount;
  95. modrdncount =inst->monitor.modrdncount;
  96. searchbasecount =inst->monitor.searchbasecount;
  97. searchonelevelcount =inst->monitor.searchonelevelcount;
  98. searchsubtreecount =inst->monitor.searchsubtreecount;
  99. abandoncount =inst->monitor.abandoncount;
  100. bindcount =inst->monitor.bindcount;
  101. unbindcount =inst->monitor.unbindcount;
  102. comparecount =inst->monitor.comparecount;
  103. slapi_unlock_mutex(inst->monitor.mutex);
  104. /*
  105. ** Get connection information
  106. */
  107. slapi_lock_mutex(inst->pool->conn.conn_list_mutex);
  108. outgoingconn= inst->pool->conn.conn_list_count;
  109. slapi_unlock_mutex(inst->pool->conn.conn_list_mutex);
  110. slapi_lock_mutex(inst->bind_pool->conn.conn_list_mutex);
  111. outgoingbindconn= inst->bind_pool->conn.conn_list_count;
  112. slapi_unlock_mutex(inst->bind_pool->conn.conn_list_mutex);
  113. sprintf( buf, "%lu", addcount );
  114. val.bv_val = buf;
  115. val.bv_len = strlen( buf );
  116. slapi_entry_attr_replace( e, CB_MONITOR_ADDCOUNT, ( struct berval **)vals );
  117. sprintf( buf, "%lu", deletecount );
  118. val.bv_val = buf;
  119. val.bv_len = strlen( buf );
  120. slapi_entry_attr_replace( e, CB_MONITOR_DELETECOUNT, ( struct berval **)vals );
  121. sprintf( buf, "%lu", modifycount );
  122. val.bv_val = buf;
  123. val.bv_len = strlen( buf );
  124. slapi_entry_attr_replace( e, CB_MONITOR_MODIFYCOUNT, ( struct berval **)vals );
  125. sprintf( buf, "%lu", modrdncount );
  126. val.bv_val = buf;
  127. val.bv_len = strlen( buf );
  128. slapi_entry_attr_replace( e, CB_MONITOR_MODRDNCOUNT, ( struct berval **)vals );
  129. sprintf( buf, "%lu", searchbasecount );
  130. val.bv_val = buf;
  131. val.bv_len = strlen( buf );
  132. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHBASECOUNT, ( struct berval **)vals );
  133. sprintf( buf, "%lu", searchonelevelcount );
  134. val.bv_val = buf;
  135. val.bv_len = strlen( buf );
  136. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHONELEVELCOUNT, ( struct berval **)vals );
  137. sprintf( buf, "%lu", searchsubtreecount );
  138. val.bv_val = buf;
  139. val.bv_len = strlen( buf );
  140. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHSUBTREECOUNT, ( struct berval **)vals );
  141. sprintf( buf, "%lu", abandoncount );
  142. val.bv_val = buf;
  143. val.bv_len = strlen( buf );
  144. slapi_entry_attr_replace( e, CB_MONITOR_ABANDONCOUNT, ( struct berval **)vals );
  145. sprintf( buf, "%lu", bindcount );
  146. val.bv_val = buf;
  147. val.bv_len = strlen( buf );
  148. slapi_entry_attr_replace( e, CB_MONITOR_BINDCOUNT, ( struct berval **)vals );
  149. sprintf( buf, "%lu", unbindcount );
  150. val.bv_val = buf;
  151. val.bv_len = strlen( buf );
  152. slapi_entry_attr_replace( e, CB_MONITOR_UNBINDCOUNT, ( struct berval **)vals );
  153. sprintf( buf, "%lu", comparecount );
  154. val.bv_val = buf;
  155. val.bv_len = strlen( buf );
  156. slapi_entry_attr_replace( e, CB_MONITOR_COMPARECOUNT, ( struct berval **)vals );
  157. sprintf( buf, "%d", outgoingconn );
  158. val.bv_val = buf;
  159. val.bv_len = strlen( buf );
  160. slapi_entry_attr_replace( e, CB_MONITOR_OUTGOINGCONN, ( struct berval **)vals );
  161. sprintf( buf, "%d", outgoingbindconn );
  162. val.bv_val = buf;
  163. val.bv_len = strlen( buf );
  164. slapi_entry_attr_replace( e, CB_MONITOR_OUTGOINGBINDCOUNT, ( struct berval **)vals );
  165. *returnCode= LDAP_SUCCESS;
  166. return(SLAPI_DSE_CALLBACK_OK);
  167. }
  168. void
  169. cb_update_monitor_info(Slapi_PBlock * pb, cb_backend_instance * inst,int op)
  170. {
  171. int scope;
  172. slapi_lock_mutex(inst->monitor.mutex);
  173. switch (op) {
  174. case SLAPI_OPERATION_ADD:
  175. inst->monitor.addcount++;
  176. break;
  177. case SLAPI_OPERATION_MODIFY:
  178. inst->monitor.modifycount++;
  179. break;
  180. case SLAPI_OPERATION_DELETE:
  181. inst->monitor.deletecount++;
  182. break;
  183. case SLAPI_OPERATION_MODRDN:
  184. /** case SLAPI_OPERATION_MODDN: **/
  185. inst->monitor.modrdncount++;
  186. break;
  187. case SLAPI_OPERATION_COMPARE:
  188. inst->monitor.comparecount++;
  189. break;
  190. case SLAPI_OPERATION_ABANDON:
  191. inst->monitor.abandoncount++;
  192. break;
  193. case SLAPI_OPERATION_BIND:
  194. inst->monitor.bindcount++;
  195. break;
  196. case SLAPI_OPERATION_UNBIND:
  197. inst->monitor.unbindcount++;
  198. break;
  199. case SLAPI_OPERATION_SEARCH:
  200. slapi_pblock_get( pb, SLAPI_SEARCH_SCOPE, &scope );
  201. if ( LDAP_SCOPE_BASE == scope )
  202. inst->monitor.searchbasecount++;
  203. else
  204. if ( LDAP_SCOPE_ONELEVEL == scope )
  205. inst->monitor.searchonelevelcount++;
  206. else
  207. inst->monitor.searchsubtreecount++;
  208. break;
  209. default:
  210. slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,"cb_update_monitor_info: invalid op type <%d>\n",op);
  211. }
  212. slapi_unlock_mutex(inst->monitor.mutex);
  213. }
  214. int
  215. cb_delete_monitor_callback(Slapi_PBlock * pb, Slapi_Entry * e, Slapi_Entry * entryAfter, int * returnCode, char * returnText, void * arg)
  216. {
  217. cb_backend_instance *inst = (cb_backend_instance *)arg;
  218. slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  219. "(objectclass=*)", cb_search_monitor_callback);
  220. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  221. "(objectclass=*)", cb_dont_allow_that);
  222. slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  223. "(objectclass=*)", cb_delete_monitor_callback);
  224. *returnCode= LDAP_SUCCESS;
  225. return(SLAPI_DSE_CALLBACK_OK);
  226. }