cb_monitor.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include "cb.h"
  42. extern cb_instance_config_info cb_the_instance_config[];
  43. /*
  44. ** Chaining backend instance monitor function
  45. ** This function wraps up backend specific monitoring information
  46. ** and return it to the client as an LDAP entry.
  47. ** This function is usually called upon receipt of the monitor
  48. ** dn for this backend
  49. **
  50. ** Monitor information:
  51. **
  52. ** Database misc
  53. ** database
  54. **
  55. ** Number of hits for each operation
  56. ** addopcount
  57. ** modifyopcount
  58. ** deleteopcount
  59. ** modrdnopcount
  60. ** compareopcount
  61. ** searchsubtreeopcount
  62. ** searchonelevelopcount
  63. ** searchbaseopcount
  64. ** bindopcount
  65. ** unbindopcount
  66. ** abandonopcount
  67. **
  68. ** Outgoing connections
  69. ** outgoingopconnections
  70. ** outgoingbindconnections
  71. **
  72. */
  73. int
  74. cb_search_monitor_callback(Slapi_PBlock * pb, Slapi_Entry * e, Slapi_Entry * entryAfter, int * returnCode, char * returnText, void * arg)
  75. {
  76. char buf[CB_BUFSIZE];
  77. struct berval val;
  78. struct berval *vals[2];
  79. unsigned long deletecount,addcount,modifycount,modrdncount,searchbasecount,searchonelevelcount;
  80. unsigned long searchsubtreecount,abandoncount,bindcount,unbindcount,comparecount;
  81. unsigned int outgoingconn, outgoingbindconn;
  82. cb_backend_instance *inst = (cb_backend_instance *)arg;
  83. /* First make sure the backend instance is configured */
  84. /* If not, don't return anything */
  85. slapi_rwlock_rdlock(inst->rwl_config_lock);
  86. if (!inst->isconfigured) {
  87. *returnCode= LDAP_NO_SUCH_OBJECT;
  88. slapi_rwlock_unlock(inst->rwl_config_lock);
  89. return SLAPI_DSE_CALLBACK_ERROR;
  90. }
  91. slapi_rwlock_unlock(inst->rwl_config_lock);
  92. vals[0] = &val;
  93. vals[1] = NULL;
  94. slapi_lock_mutex(inst->monitor.mutex);
  95. addcount =inst->monitor.addcount;
  96. deletecount =inst->monitor.deletecount;
  97. modifycount =inst->monitor.modifycount;
  98. modrdncount =inst->monitor.modrdncount;
  99. searchbasecount =inst->monitor.searchbasecount;
  100. searchonelevelcount =inst->monitor.searchonelevelcount;
  101. searchsubtreecount =inst->monitor.searchsubtreecount;
  102. abandoncount =inst->monitor.abandoncount;
  103. bindcount =inst->monitor.bindcount;
  104. unbindcount =inst->monitor.unbindcount;
  105. comparecount =inst->monitor.comparecount;
  106. slapi_unlock_mutex(inst->monitor.mutex);
  107. /*
  108. ** Get connection information
  109. */
  110. slapi_lock_mutex(inst->pool->conn.conn_list_mutex);
  111. outgoingconn= inst->pool->conn.conn_list_count;
  112. slapi_unlock_mutex(inst->pool->conn.conn_list_mutex);
  113. slapi_lock_mutex(inst->bind_pool->conn.conn_list_mutex);
  114. outgoingbindconn= inst->bind_pool->conn.conn_list_count;
  115. slapi_unlock_mutex(inst->bind_pool->conn.conn_list_mutex);
  116. sprintf( buf, "%lu", addcount );
  117. val.bv_val = buf;
  118. val.bv_len = strlen( buf );
  119. slapi_entry_attr_replace( e, CB_MONITOR_ADDCOUNT, ( struct berval **)vals );
  120. sprintf( buf, "%lu", deletecount );
  121. val.bv_val = buf;
  122. val.bv_len = strlen( buf );
  123. slapi_entry_attr_replace( e, CB_MONITOR_DELETECOUNT, ( struct berval **)vals );
  124. sprintf( buf, "%lu", modifycount );
  125. val.bv_val = buf;
  126. val.bv_len = strlen( buf );
  127. slapi_entry_attr_replace( e, CB_MONITOR_MODIFYCOUNT, ( struct berval **)vals );
  128. sprintf( buf, "%lu", modrdncount );
  129. val.bv_val = buf;
  130. val.bv_len = strlen( buf );
  131. slapi_entry_attr_replace( e, CB_MONITOR_MODRDNCOUNT, ( struct berval **)vals );
  132. sprintf( buf, "%lu", searchbasecount );
  133. val.bv_val = buf;
  134. val.bv_len = strlen( buf );
  135. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHBASECOUNT, ( struct berval **)vals );
  136. sprintf( buf, "%lu", searchonelevelcount );
  137. val.bv_val = buf;
  138. val.bv_len = strlen( buf );
  139. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHONELEVELCOUNT, ( struct berval **)vals );
  140. sprintf( buf, "%lu", searchsubtreecount );
  141. val.bv_val = buf;
  142. val.bv_len = strlen( buf );
  143. slapi_entry_attr_replace( e, CB_MONITOR_SEARCHSUBTREECOUNT, ( struct berval **)vals );
  144. sprintf( buf, "%lu", abandoncount );
  145. val.bv_val = buf;
  146. val.bv_len = strlen( buf );
  147. slapi_entry_attr_replace( e, CB_MONITOR_ABANDONCOUNT, ( struct berval **)vals );
  148. sprintf( buf, "%lu", bindcount );
  149. val.bv_val = buf;
  150. val.bv_len = strlen( buf );
  151. slapi_entry_attr_replace( e, CB_MONITOR_BINDCOUNT, ( struct berval **)vals );
  152. sprintf( buf, "%lu", unbindcount );
  153. val.bv_val = buf;
  154. val.bv_len = strlen( buf );
  155. slapi_entry_attr_replace( e, CB_MONITOR_UNBINDCOUNT, ( struct berval **)vals );
  156. sprintf( buf, "%lu", comparecount );
  157. val.bv_val = buf;
  158. val.bv_len = strlen( buf );
  159. slapi_entry_attr_replace( e, CB_MONITOR_COMPARECOUNT, ( struct berval **)vals );
  160. sprintf( buf, "%u", outgoingconn );
  161. val.bv_val = buf;
  162. val.bv_len = strlen( buf );
  163. slapi_entry_attr_replace( e, CB_MONITOR_OUTGOINGCONN, ( struct berval **)vals );
  164. sprintf( buf, "%u", outgoingbindconn );
  165. val.bv_val = buf;
  166. val.bv_len = strlen( buf );
  167. slapi_entry_attr_replace( e, CB_MONITOR_OUTGOINGBINDCOUNT, ( struct berval **)vals );
  168. *returnCode= LDAP_SUCCESS;
  169. return(SLAPI_DSE_CALLBACK_OK);
  170. }
  171. void
  172. cb_update_monitor_info(Slapi_PBlock * pb, cb_backend_instance * inst,int op)
  173. {
  174. int scope;
  175. slapi_lock_mutex(inst->monitor.mutex);
  176. switch (op) {
  177. case SLAPI_OPERATION_ADD:
  178. inst->monitor.addcount++;
  179. break;
  180. case SLAPI_OPERATION_MODIFY:
  181. inst->monitor.modifycount++;
  182. break;
  183. case SLAPI_OPERATION_DELETE:
  184. inst->monitor.deletecount++;
  185. break;
  186. case SLAPI_OPERATION_MODRDN:
  187. /** case SLAPI_OPERATION_MODDN: **/
  188. inst->monitor.modrdncount++;
  189. break;
  190. case SLAPI_OPERATION_COMPARE:
  191. inst->monitor.comparecount++;
  192. break;
  193. case SLAPI_OPERATION_ABANDON:
  194. inst->monitor.abandoncount++;
  195. break;
  196. case SLAPI_OPERATION_BIND:
  197. inst->monitor.bindcount++;
  198. break;
  199. case SLAPI_OPERATION_UNBIND:
  200. inst->monitor.unbindcount++;
  201. break;
  202. case SLAPI_OPERATION_SEARCH:
  203. slapi_pblock_get( pb, SLAPI_SEARCH_SCOPE, &scope );
  204. if ( LDAP_SCOPE_BASE == scope )
  205. inst->monitor.searchbasecount++;
  206. else
  207. if ( LDAP_SCOPE_ONELEVEL == scope )
  208. inst->monitor.searchonelevelcount++;
  209. else
  210. inst->monitor.searchsubtreecount++;
  211. break;
  212. default:
  213. slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,"cb_update_monitor_info: invalid op type <%d>\n",op);
  214. }
  215. slapi_unlock_mutex(inst->monitor.mutex);
  216. }
  217. int
  218. cb_delete_monitor_callback(Slapi_PBlock * pb, Slapi_Entry * e, Slapi_Entry * entryAfter, int * returnCode, char * returnText, void * arg)
  219. {
  220. cb_backend_instance *inst = (cb_backend_instance *)arg;
  221. slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  222. "(objectclass=*)", cb_search_monitor_callback);
  223. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  224. "(objectclass=*)", cb_dont_allow_that);
  225. slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, inst->monitorDn, LDAP_SCOPE_BASE,
  226. "(objectclass=*)", cb_delete_monitor_callback);
  227. *returnCode= LDAP_SUCCESS;
  228. return(SLAPI_DSE_CALLBACK_OK);
  229. }