monitor.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. /*
  42. * Copyright (c) 1995 Regents of the University of Michigan.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms are permitted
  46. * provided that this notice is preserved and that due credit is given
  47. * to the University of Michigan at Ann Arbor. The name of the University
  48. * may not be used to endorse or promote products derived from this
  49. * software without specific prior written permission. This software
  50. * is provided ``as is'' without express or implied warranty.
  51. */
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <sys/types.h>
  55. #include <time.h>
  56. #ifndef _WIN32
  57. #include <sys/socket.h>
  58. #endif
  59. #include "slap.h"
  60. #include "fe.h"
  61. #if defined( SLAPD_MONITOR_DN )
  62. int
  63. monitor_info(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg)
  64. {
  65. char buf[BUFSIZ];
  66. struct berval val;
  67. struct berval *vals[2];
  68. time_t curtime = current_time();
  69. struct tm utm;
  70. Slapi_Backend *be;
  71. char *cookie;
  72. vals[0] = &val;
  73. vals[1] = NULL;
  74. /* "version" value */
  75. val.bv_val = slapd_get_version_value();
  76. val.bv_len = strlen( val.bv_val );
  77. attrlist_replace( &e->e_attrs, "version", vals );
  78. slapi_ch_free( (void **) &val.bv_val );
  79. val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", g_get_active_threadcnt() );
  80. val.bv_val = buf;
  81. attrlist_replace( &e->e_attrs, "threads", vals );
  82. connection_table_as_entry(the_connection_table, e);
  83. val.bv_len = PR_snprintf( buf, sizeof(buf), "%" NSPRIu64, slapi_counter_get_value(ops_initiated) );
  84. val.bv_val = buf;
  85. attrlist_replace( &e->e_attrs, "opsinitiated", vals );
  86. val.bv_len = PR_snprintf( buf, sizeof(buf), "%" NSPRIu64, slapi_counter_get_value(ops_completed) );
  87. val.bv_val = buf;
  88. attrlist_replace( &e->e_attrs, "opscompleted", vals );
  89. val.bv_len = PR_snprintf ( buf, sizeof(buf), "%" NSPRIu64, g_get_num_entries_sent() );
  90. val.bv_val = buf;
  91. attrlist_replace( &e->e_attrs, "entriessent", vals );
  92. val.bv_len = PR_snprintf ( buf, sizeof(buf), "%" NSPRIu64, g_get_num_bytes_sent() );
  93. val.bv_val = buf;
  94. attrlist_replace( &e->e_attrs, "bytessent", vals );
  95. #ifdef _WIN32
  96. {
  97. struct tm *pt;
  98. pt = gmtime( &curtime );
  99. memcpy(&utm, pt, sizeof(struct tm) );
  100. }
  101. #else
  102. gmtime_r( &curtime, &utm );
  103. #endif
  104. strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", &utm );
  105. val.bv_val = buf;
  106. val.bv_len = strlen( buf );
  107. attrlist_replace( &e->e_attrs, "currenttime", vals );
  108. #ifdef _WIN32
  109. {
  110. struct tm *pt;
  111. pt = gmtime( &starttime );
  112. memcpy(&utm, pt, sizeof(struct tm) );
  113. }
  114. #else
  115. gmtime_r( &starttime, &utm );
  116. #endif
  117. strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", &utm );
  118. val.bv_val = buf;
  119. val.bv_len = strlen( buf );
  120. attrlist_replace( &e->e_attrs, "starttime", vals );
  121. val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", be_nbackends_public() );
  122. val.bv_val = buf;
  123. attrlist_replace( &e->e_attrs, "nbackends", vals );
  124. #ifdef THREAD_SUNOS5_LWP
  125. val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", thr_getconcurrency() );
  126. val.bv_val = buf;
  127. attrlist_replace( &e->e_attrs, "concurrency", vals );
  128. #endif
  129. /*Loop through the backends, and stuff the monitordns
  130. into the entry we're sending back*/
  131. attrlist_delete( &e->e_attrs, "backendmonitordn");
  132. cookie = NULL;
  133. be = slapi_get_first_backend(&cookie);
  134. while (be)
  135. {
  136. if ( !be->be_private )
  137. {
  138. Slapi_DN dn;
  139. slapi_sdn_init(&dn);
  140. be_getmonitordn(be,&dn);
  141. val.bv_val = (char*)slapi_sdn_get_dn(&dn);
  142. val.bv_len = strlen( val.bv_val );
  143. attrlist_merge( &e->e_attrs, "backendmonitordn", vals );
  144. slapi_sdn_done(&dn);
  145. }
  146. be = slapi_get_next_backend(cookie);
  147. }
  148. slapi_ch_free((void **)&cookie);
  149. *returncode= LDAP_SUCCESS;
  150. return SLAPI_DSE_CALLBACK_OK;
  151. }
  152. #endif /* SLAPD_MONITOR_DN */
  153. /*
  154. * Return a malloc'd version value.
  155. * Used for the monitor entry's 'version' attribute.
  156. * Used for the root DSE's 'vendorVersion' attribute.
  157. */
  158. char *
  159. slapd_get_version_value( void )
  160. {
  161. char *versionstring, *buildnum, *vs;
  162. versionstring = config_get_versionstring();
  163. buildnum = config_get_buildnum();
  164. vs = slapi_ch_smprintf("%s B%s", versionstring, buildnum );
  165. slapi_ch_free( (void **) &buildnum);
  166. slapi_ch_free( (void **) &versionstring);
  167. return vs;
  168. }