]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/monitor.c
Rework ac/socket.h for HAVE_WINSOCK:
[openldap] / servers / slapd / monitor.c
index 595095d86670f146ad9a61d6ebf5606010e8351b..658db39791a977e6a79b6b1016487a497a4c1900 100644 (file)
  * is provided ``as is'' without express or implied warranty.
  */
 
-/* Revision history
- *
- * 5-Jun-96    jeff.hodges@stanford.edu
- *     Added locking of new_conn_mutex when traversing the c[] array.
- *     Added locking of currenttime_mutex to protect call(s) to localtime().
- */
+#include "portable.h"
 
 #include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
-#include "ldapconfig.h"
 
-#if defined( SLAPD_MONITOR_DN )
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
 
-extern int             nbackends;
-extern Backend         *backends;
-extern int             active_threads;
-extern int             dtblsize;
-extern Connection      *c;
-extern long            ops_initiated;
-extern long            ops_completed;
-extern long            num_entries_sent;
-extern long            num_bytes_sent;
-extern time_t          currenttime;
-extern time_t          starttime;
-extern int             num_conns;
-
-extern pthread_mutex_t new_conn_mutex;
-extern pthread_mutex_t currenttime_mutex;
+#include "ldapconfig.h"
+#include "slap.h"
 
-extern char Versionstr[];
+#if defined( SLAPD_MONITOR_DN )
 
 void
 monitor_info( Connection *conn, Operation *op )
@@ -54,16 +32,19 @@ monitor_info( Connection *conn, Operation *op )
        struct berval   *vals[2];
        int             i, nconns, nwritewaiters, nreadwaiters;
        struct tm       *ltm;
-       char            *p, *tmpdn;
+       char            *p;
+       Connection *c;
+       time_t          currenttime;
 
        vals[0] = &val;
        vals[1] = NULL;
 
        e = (Entry *) ch_calloc( 1, sizeof(Entry) );
        /* initialize reader/writer lock */
-       entry_rdwr_init(e);
        e->e_attrs = NULL;
-       e->e_dn = strdup( SLAPD_MONITOR_DN );
+       e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
+       e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
+       e->e_private = NULL;
 
        val.bv_val = Versionstr;
        if (( p = strchr( Versionstr, '\n' )) == NULL ) {
@@ -73,7 +54,9 @@ monitor_info( Connection *conn, Operation *op )
        }
        attr_merge( e, "version", vals );
 
+       ldap_pvt_thread_mutex_lock( &active_threads_mutex );
        sprintf( buf, "%d", active_threads );
+       ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "threads", vals );
@@ -82,46 +65,49 @@ monitor_info( Connection *conn, Operation *op )
        nwritewaiters = 0;
        nreadwaiters = 0;
 
-       pthread_mutex_lock( &new_conn_mutex );
-       for ( i = 0; i < dtblsize; i++ ) {
-               if ( c[i].c_sb.sb_sd != -1 ) {
-                       nconns++;
-                       if ( c[i].c_writewaiter ) {
-                               nwritewaiters++;
-                       }
-                       if ( c[i].c_gettingber ) {
-                               nreadwaiters++;
-                       }
-                       pthread_mutex_lock( &currenttime_mutex );
+#ifdef LDAP_COUNTERS
+       /* loop through the connections */
+       for ( c = connection_first() ; c != NULL;  c = connection_next(c) ) {
+               nconns++;
+               if ( c->c_writewaiter ) {
+                       nwritewaiters++;
+               }
+               if ( c->c_currentber != NULL ) {
+                       nreadwaiters++;
+               }
+
+               ldap_pvt_thread_mutex_lock( &gmtime_mutex );
 #ifndef LDAP_LOCALTIME
-                       ltm = gmtime( &c[i].c_starttime );
-                       strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
+               ltm = gmtime( &c->c_starttime );
+               strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
 #else
-                       ltm = localtime( &c[i].c_starttime );
-                       strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
+               ltm = localtime( &c->.c_starttime );
+               strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
 #endif
-                       pthread_mutex_unlock( &currenttime_mutex );
-
-                       pthread_mutex_lock( &c[i].c_dnmutex );
-                       sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
-                           buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
-                           c[i].c_dn ? c[i].c_dn : "NULLDN",
-                           c[i].c_gettingber ? "r" : "",
-                           c[i].c_writewaiter ? "w" : "" );
-                       pthread_mutex_unlock( &c[i].c_dnmutex );
-                       val.bv_val = buf;
-                       val.bv_len = strlen( buf );
-                       attr_merge( e, "connection", vals );
-               }
+               ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
+
+               sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
+                   buf2, c[i].c_n_ops_received, c[i].c_n_ops_completed,
+                   c[i].c_cdn ? c[i].c_cdn : "NULLDN",
+                   c[i].c_currentber ? "r" : "",
+                   c[i].c_writewaiter ? "w" : "",
+                   c[i].c_ops != NULL ? "x" : "",
+                   c[i].c_pending_ops != NULL ? "p" : ""
+               );
+
+               val.bv_val = buf;
+               val.bv_len = strlen( buf );
+               attr_merge( e, "connection", vals );
        }
-       pthread_mutex_unlock( &new_conn_mutex );
+       connection_done(c);
+#endif
 
        sprintf( buf, "%d", nconns );
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "currentconnections", vals );
 
-       sprintf( buf, "%d", num_conns );
+       sprintf( buf, "%ld", connections_nextid() );
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "totalconnections", vals );
@@ -141,27 +127,39 @@ monitor_info( Connection *conn, Operation *op )
        val.bv_len = strlen( buf );
        attr_merge( e, "readwaiters", vals );
 
-       sprintf( buf, "%ld", ops_initiated );
+#ifdef LDAP_COUNTERS
+       ldap_pvt_thread_mutex_lock(&num_ops_mutex);
+       sprintf( buf, "%ld", num_ops_initiated );
+       ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "opsinitiated", vals );
 
-       sprintf( buf, "%ld", ops_completed );
+       ldap_pvt_thread_mutex_lock(&num_ops_mutex);
+       sprintf( buf, "%ld", num_ops_completed );
+       ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "opscompleted", vals );
 
+       ldap_pvt_thread_mutex_lock(&num_sent_mutex);
        sprintf( buf, "%ld", num_entries_sent );
+       ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "entriessent", vals );
 
+       ldap_pvt_thread_mutex_lock(&num_sent_mutex);
        sprintf( buf, "%ld", num_bytes_sent );
+       ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "bytessent", vals );
+#endif
 
-       pthread_mutex_lock( &currenttime_mutex );
+       currenttime = slap_get_time();
+
+       ldap_pvt_thread_mutex_lock( &gmtime_mutex );
 #ifndef LDAP_LOCALTIME
        ltm = gmtime( &currenttime );
        strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
@@ -169,12 +167,10 @@ monitor_info( Connection *conn, Operation *op )
        ltm = localtime( &currenttime );
        strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
 #endif
-       pthread_mutex_unlock( &currenttime_mutex );
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "currenttime", vals );
 
-       pthread_mutex_lock( &currenttime_mutex );
 #ifndef LDAP_LOCALTIME
        ltm = gmtime( &starttime );
        strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
@@ -182,7 +178,8 @@ monitor_info( Connection *conn, Operation *op )
        ltm = localtime( &starttime );
        strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
 #endif
-       pthread_mutex_unlock( &currenttime_mutex );
+       ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
+
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "starttime", vals );
@@ -192,8 +189,8 @@ monitor_info( Connection *conn, Operation *op )
        val.bv_len = strlen( buf );
        attr_merge( e, "nbackends", vals );
 
-#ifdef THREAD_SUNOS5_LWP
-       sprintf( buf, "%d", thr_getconcurrency() );
+#ifdef HAVE_THREAD_CONCURRENCY
+       sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
        val.bv_val = buf;
        val.bv_len = strlen( buf );
        attr_merge( e, "concurrency", vals );