diff options
author | Nathan Kinder <nkinder@redhat.com> | 2008-10-24 22:36:59 +0000 |
---|---|---|
committer | Nathan Kinder <nkinder@redhat.com> | 2008-10-24 22:36:59 +0000 |
commit | 9d6bd843ae9ed5d5173d7dc0d58902671ed9ab05 (patch) | |
tree | 2f6f89f7659715620fb0698c8b79faa6943a59c0 /ldap/servers/snmp | |
parent | fc29aef3cd18c9eb68dbb9a45474e0fea9f6b4d1 (diff) | |
download | ds-9d6bd843ae9ed5d5173d7dc0d58902671ed9ab05.tar.gz ds-9d6bd843ae9ed5d5173d7dc0d58902671ed9ab05.tar.xz ds-9d6bd843ae9ed5d5173d7dc0d58902671ed9ab05.zip |
Resolves: 207457
Summary: Convert counters to 64-bit capable Slapi_Counter type.
Diffstat (limited to 'ldap/servers/snmp')
-rw-r--r-- | ldap/servers/snmp/ldap-agent.c | 164 | ||||
-rw-r--r-- | ldap/servers/snmp/ldap-agent.h | 10 | ||||
-rw-r--r-- | ldap/servers/snmp/main.c | 13 | ||||
-rw-r--r-- | ldap/servers/snmp/redhat-directory.mib | 106 |
4 files changed, 164 insertions, 129 deletions
diff --git a/ldap/servers/snmp/ldap-agent.c b/ldap/servers/snmp/ldap-agent.c index a93e1f37..93cf80f8 100644 --- a/ldap/servers/snmp/ldap-agent.c +++ b/ldap/servers/snmp/ldap-agent.c @@ -277,6 +277,7 @@ load_stats_table(netsnmp_cache *cache, void *foo) time_t previous_start; int previous_state; int stats_hdl = -1; + sem_t *stats_sem = NULL; snmp_log(LOG_INFO, "Reloading stats.\n"); @@ -291,8 +292,39 @@ load_stats_table(netsnmp_cache *cache, void *foo) snmp_log(LOG_INFO, "Opening stats file (%s) for server: %d\n", serv_p->stats_file, serv_p->port); + /* Open and acquire semaphore */ + if ((stats_sem = sem_open(serv_p->stats_sem_name, 0)) == SEM_FAILED) { + stats_sem = NULL; + snmp_log(LOG_INFO, "Unable to open semaphore for server: %d\n", serv_p->port); + } else { + int i = 0; + int got_sem = 0; + + for (i=0; i < SNMP_NUM_SEM_WAITS; i++) { + if (sem_trywait(stats_sem) == 0) { + got_sem = 1; + break; + } + PR_Sleep(PR_SecondsToInterval(1)); + } + + if (!got_sem) { + /* We're unable to get the semaphore. Assume + * that the server is down. */ + snmp_log(LOG_INFO, "Unable to acquire semaphore for server: %d\n", serv_p->port); + sem_close(stats_sem); + stats_sem = NULL; + } + } + /* Open the stats file */ - if ( agt_mopen_stats(serv_p->stats_file, O_RDONLY, &stats_hdl) != 0 ) { + if ((stats_sem == NULL) || (agt_mopen_stats(serv_p->stats_file, O_RDONLY, &stats_hdl) != 0)) { + if (stats_sem) { + /* Release and close semaphore */ + sem_post(stats_sem); + sem_close(stats_sem); + } + /* Server must be down */ serv_p->server_state = SERVER_DOWN; /* Zero out the ops and entries tables */ @@ -313,6 +345,10 @@ load_stats_table(netsnmp_cache *cache, void *foo) snmp_log(LOG_ERR, "Error closing stats file: %s\n", serv_p->stats_file); + /* Release and close semaphore */ + sem_post(stats_sem); + sem_close(stats_sem); + /* Server must be down if the stats file hasn't been * updated in a while */ if (difftime(time(NULL), ctx->hdr_tbl.updateTime) >= UPDATE_THRESHOLD) { @@ -382,135 +418,108 @@ dsOpsTable_get_value(netsnmp_request_info *request, netsnmp_index * item, netsnmp_table_request_info *table_info) { + PRUint64 *the_stat = NULL; + integer64 new_val; netsnmp_variable_list *var = request->requestvb; stats_table_context *context = (stats_table_context *) item; switch (table_info->colnum) { case COLUMN_DSANONYMOUSBINDS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsAnonymousBinds, - sizeof(context->ops_tbl.dsAnonymousBinds)); + the_stat = &context->ops_tbl.dsAnonymousBinds; break; case COLUMN_DSUNAUTHBINDS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsUnAuthBinds, - sizeof(context->ops_tbl.dsUnAuthBinds)); + the_stat = &context->ops_tbl.dsUnAuthBinds; break; case COLUMN_DSSIMPLEAUTHBINDS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsSimpleAuthBinds, - sizeof(context->ops_tbl.dsSimpleAuthBinds)); + the_stat = &context->ops_tbl.dsSimpleAuthBinds; break; case COLUMN_DSSTRONGAUTHBINDS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsStrongAuthBinds, - sizeof(context->ops_tbl.dsStrongAuthBinds)); + the_stat = &context->ops_tbl.dsStrongAuthBinds; break; case COLUMN_DSBINDSECURITYERRORS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsBindSecurityErrors, - sizeof(context->ops_tbl.dsBindSecurityErrors)); + the_stat = &context->ops_tbl.dsBindSecurityErrors; break; case COLUMN_DSINOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsInOps, - sizeof(context->ops_tbl.dsInOps)); + the_stat = &context->ops_tbl.dsInOps; break; case COLUMN_DSREADOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsReadOps, - sizeof(context->ops_tbl.dsReadOps)); + the_stat = &context->ops_tbl.dsReadOps; break; case COLUMN_DSCOMPAREOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsCompareOps, - sizeof(context->ops_tbl.dsCompareOps)); + the_stat = &context->ops_tbl.dsCompareOps; break; case COLUMN_DSADDENTRYOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsAddEntryOps, - sizeof(context->ops_tbl.dsAddEntryOps)); + the_stat = &context->ops_tbl.dsAddEntryOps; break; case COLUMN_DSREMOVEENTRYOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsRemoveEntryOps, - sizeof(context->ops_tbl.dsRemoveEntryOps)); + the_stat = &context->ops_tbl.dsRemoveEntryOps; break; case COLUMN_DSMODIFYENTRYOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsModifyEntryOps, - sizeof(context->ops_tbl.dsModifyEntryOps)); + the_stat = &context->ops_tbl.dsModifyEntryOps; break; case COLUMN_DSMODIFYRDNOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsModifyRDNOps, - sizeof(context->ops_tbl.dsModifyRDNOps)); + the_stat = &context->ops_tbl.dsModifyRDNOps; break; case COLUMN_DSLISTOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsListOps, - sizeof(context->ops_tbl.dsListOps)); + the_stat = &context->ops_tbl.dsListOps; break; case COLUMN_DSSEARCHOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsSearchOps, - sizeof(context->ops_tbl.dsSearchOps)); + the_stat = &context->ops_tbl.dsSearchOps; break; case COLUMN_DSONELEVELSEARCHOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsOneLevelSearchOps, - sizeof(context->ops_tbl.dsOneLevelSearchOps)); + the_stat = &context->ops_tbl.dsOneLevelSearchOps; break; case COLUMN_DSWHOLESUBTREESEARCHOPS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsWholeSubtreeSearchOps, - sizeof(context->ops_tbl.dsWholeSubtreeSearchOps)); + the_stat = &context->ops_tbl.dsWholeSubtreeSearchOps; break; case COLUMN_DSREFERRALS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsReferrals, - sizeof(context->ops_tbl.dsReferrals)); + the_stat = &context->ops_tbl.dsReferrals; break; case COLUMN_DSCHAININGS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsChainings, - sizeof(context->ops_tbl.dsChainings)); + the_stat = &context->ops_tbl.dsChainings; break; case COLUMN_DSSECURITYERRORS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsSecurityErrors, - sizeof(context->ops_tbl.dsSecurityErrors)); + the_stat = &context->ops_tbl.dsSecurityErrors; break; case COLUMN_DSERRORS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->ops_tbl.dsErrors, - sizeof(context->ops_tbl.dsErrors)); + the_stat = &context->ops_tbl.dsErrors; break; default:/* We shouldn't get here */ snmp_log(LOG_ERR, "Unknown column in dsOpsTable_get_value\n"); return SNMP_ERR_GENERR; } + + /* The Net-SNMP integer64 type isn't a true 64-bit value, but instead + * a structure containing the high and low bits separately. We need + * to split our value appropriately. */ + new_val.low = *the_stat & 0x00000000ffffffff; + new_val.high = (*the_stat >> 32) & 0x00000000ffffffff; + + snmp_set_var_typed_value(var, ASN_COUNTER64, + (u_char *) &new_val, + sizeof(new_val)); + return SNMP_ERR_NOERROR; } @@ -527,45 +536,48 @@ dsEntriesTable_get_value(netsnmp_request_info *request, netsnmp_index * item, netsnmp_table_request_info *table_info) { + PRUint64 *the_stat = NULL; + integer64 new_val; netsnmp_variable_list *var = request->requestvb; stats_table_context *context = (stats_table_context *) item; switch (table_info->colnum) { case COLUMN_DSMASTERENTRIES: - snmp_set_var_typed_value(var, ASN_GAUGE, - (u_char *) &context->entries_tbl.dsMasterEntries, - sizeof(context->entries_tbl.dsMasterEntries)); + the_stat = &context->entries_tbl.dsMasterEntries; break; case COLUMN_DSCOPYENTRIES: - snmp_set_var_typed_value(var, ASN_GAUGE, - (u_char *) &context->entries_tbl.dsCopyEntries, - sizeof(context->entries_tbl.dsCopyEntries)); + the_stat = &context->entries_tbl.dsCopyEntries; break; case COLUMN_DSCACHEENTRIES: - snmp_set_var_typed_value(var, ASN_GAUGE, - (u_char *) &context->entries_tbl.dsCacheEntries, - sizeof(context->entries_tbl.dsCacheEntries)); + the_stat = &context->entries_tbl.dsCacheEntries; break; case COLUMN_DSCACHEHITS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->entries_tbl.dsCacheHits, - sizeof(context->entries_tbl.dsCacheHits)); + the_stat = &context->entries_tbl.dsCacheHits; break; case COLUMN_DSSLAVEHITS: - snmp_set_var_typed_value(var, ASN_COUNTER, - (u_char *) &context->entries_tbl.dsSlaveHits, - sizeof(context->entries_tbl.dsSlaveHits)); + the_stat = &context->entries_tbl.dsSlaveHits; break; default:/* We shouldn't get here */ snmp_log(LOG_ERR, "Unknown column in dsEntriesTable_get_value\n"); return SNMP_ERR_GENERR; } + + /* The Net-SNMP integer64 type isn't a true 64-bit value, but instead + * a structure containing the high and low bits separately. We need + * to split our value appropriately. */ + new_val.low = *the_stat & 0x00000000ffffffff; + new_val.high = (*the_stat >> 32) & 0x00000000ffffffff; + + snmp_set_var_typed_value(var, ASN_COUNTER64, + (u_char *) &new_val, + sizeof(new_val)); + return SNMP_ERR_NOERROR; } diff --git a/ldap/servers/snmp/ldap-agent.h b/ldap/servers/snmp/ldap-agent.h index 28f3cc2a..cb7a395d 100644 --- a/ldap/servers/snmp/ldap-agent.h +++ b/ldap/servers/snmp/ldap-agent.h @@ -74,10 +74,19 @@ extern "C" { #include <net-snmp/library/container.h> #include <net-snmp/agent/table_array.h> #include "../slapd/agtmmap.h" +#include <semaphore.h> +#include <fcntl.h> + +#ifdef HPUX +/* HP-UX doesn't define SEM_FAILED like other platforms, so + * * we define it ourselves. */ +#define SEM_FAILED ((sem_t *)(-1)) +#endif #define MAXLINE 4096 #define CACHE_REFRESH_INTERVAL 15 #define UPDATE_THRESHOLD 20 +#define SNMP_NUM_SEM_WAITS 10 #define LDAP_AGENT_PIDFILE ".ldap-agent.pid" #define LDAP_AGENT_LOGFILE "ldap-agent.log" @@ -95,6 +104,7 @@ typedef struct server_instance_s { PRUint32 port; int server_state; char *stats_file; + char *stats_sem_name; char *dse_ldif; struct server_instance_s *next; } server_instance; diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c index 1331b1fc..4e249f53 100644 --- a/ldap/servers/snmp/main.c +++ b/ldap/servers/snmp/main.c @@ -355,6 +355,19 @@ load_config(char *conf_path) instancename = NULL; goto close_and_exit; } + + /* set the semaphore name */ + /* ".stats" + \0 = 7 */ + serv_p->stats_sem_name = malloc(strlen(p) + 7); + if (serv_p->stats_sem_name != NULL) { + snprintf(serv_p->stats_sem_name, strlen(p) + 7, "%s.stats", p); + } else { + printf("ldap-agent: malloc error processing config file\n"); + error = 1; + free(instancename); + instancename = NULL; + goto close_and_exit; + } } /* Open dse.ldif */ diff --git a/ldap/servers/snmp/redhat-directory.mib b/ldap/servers/snmp/redhat-directory.mib index a483cc32..56d4f9a6 100644 --- a/ldap/servers/snmp/redhat-directory.mib +++ b/ldap/servers/snmp/redhat-directory.mib @@ -46,7 +46,7 @@ RHDS-MIB DEFINITIONS ::= BEGIN IMPORTS - MODULE-IDENTITY, Counter32, Gauge32, OBJECT-TYPE + MODULE-IDENTITY, Counter64, Counter32, Gauge32, OBJECT-TYPE FROM SNMPv2-SMI DisplayString, TimeStamp, TEXTUAL-CONVENTION FROM SNMPv2-TC @@ -68,7 +68,7 @@ IMPORTS SYNTAX DisplayString rhds MODULE-IDENTITY - LAST-UPDATED "200503020000Z" + LAST-UPDATED "200810230000Z" ORGANIZATION "Red Hat, Inc." CONTACT-INFO "Red Hat, Inc. @@ -103,54 +103,54 @@ IMPORTS -- Bindings dsAnonymousBinds - Counter32, + Counter64, dsUnAuthBinds - Counter32, + Counter64, dsSimpleAuthBinds - Counter32, + Counter64, dsStrongAuthBinds - Counter32, + Counter64 dsBindSecurityErrors - Counter32, + Counter64, -- In-coming operations dsInOps - Counter32, + Counter64, dsReadOps - Counter32, + Counter64, dsCompareOps - Counter32, + Counter64, dsAddEntryOps - Counter32, + Counter64, dsRemoveEntryOps - Counter32, + Counter64, dsModifyEntryOps - Counter32, + Counter64, dsModifyRDNOps - Counter32, + Counter64, dsListOps - Counter32, + Counter64, dsSearchOps - Counter32, + Counter64, dsOneLevelSearchOps - Counter32, + Counter64, dsWholeSubtreeSearchOps - Counter32, + Counter64, -- Out going operations dsReferrals - Counter32, + Counter64, dsChainings - Counter32, + Counter64, -- Errors dsSecurityErrors - Counter32, + Counter64, dsErrors - Counter32 + Counter64 } -- CLDAP does not use binds; for A CLDAP DS the bind @@ -172,7 +172,7 @@ IMPORTS -- CLDAP and LDAP DSs: dsReferrals. dsAnonymousBinds OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -181,7 +181,7 @@ IMPORTS ::= {dsOpsEntry 1} dsUnAuthBinds OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -190,7 +190,7 @@ IMPORTS ::= {dsOpsEntry 2} dsSimpleAuthBinds OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -203,7 +203,7 @@ IMPORTS ::= {dsOpsEntry 3} dsStrongAuthBinds OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -217,7 +217,7 @@ IMPORTS ::= {dsOpsEntry 4} dsBindSecurityErrors OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -230,7 +230,7 @@ IMPORTS ::= {dsOpsEntry 5} dsInOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -240,7 +240,7 @@ IMPORTS ::= {dsOpsEntry 6} dsReadOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -252,7 +252,7 @@ IMPORTS ::= {dsOpsEntry 7} dsCompareOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -264,7 +264,7 @@ IMPORTS ::= {dsOpsEntry 8} dsAddEntryOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -276,7 +276,7 @@ IMPORTS ::= {dsOpsEntry 9} dsRemoveEntryOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -288,7 +288,7 @@ IMPORTS ::= {dsOpsEntry 10} dsModifyEntryOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -300,7 +300,7 @@ IMPORTS ::= {dsOpsEntry 11} dsModifyRDNOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -312,7 +312,7 @@ IMPORTS ::= {dsOpsEntry 12} dsListOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -324,7 +324,7 @@ IMPORTS ::= {dsOpsEntry 13} dsSearchOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -337,7 +337,7 @@ IMPORTS ::= {dsOpsEntry 14} dsOneLevelSearchOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -349,7 +349,7 @@ IMPORTS ::= {dsOpsEntry 15} dsWholeSubtreeSearchOps OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -361,7 +361,7 @@ IMPORTS ::= {dsOpsEntry 16} dsReferrals OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -373,7 +373,7 @@ IMPORTS ::= {dsOpsEntry 17} dsChainings OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -385,7 +385,7 @@ IMPORTS ::= {dsOpsEntry 18} dsSecurityErrors OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -397,7 +397,7 @@ IMPORTS ::= {dsOpsEntry 19} dsErrors OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -437,15 +437,15 @@ IMPORTS DsEntriesEntry ::= SEQUENCE { dsMasterEntries - Gauge32, + Counter64, dsCopyEntries - Gauge32, + Counter64, dsCacheEntries - Gauge32, + Counter64, dsCacheHits - Counter32, + Counter64, dsSlaveHits - Counter32 + Counter64 } -- A (C)LDAP frontend to the X.500 Directory will not have @@ -454,7 +454,7 @@ IMPORTS -- directory: dsMasterEntries, dsCopyEntries, dsSlaveHits. dsMasterEntries OBJECT-TYPE - SYNTAX Gauge32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -462,7 +462,7 @@ IMPORTS ::= {dsEntriesEntry 1} dsCopyEntries OBJECT-TYPE - SYNTAX Gauge32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -471,7 +471,7 @@ IMPORTS ::= {dsEntriesEntry 2} dsCacheEntries OBJECT-TYPE - SYNTAX Gauge32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -480,8 +480,8 @@ IMPORTS cached partially. The negative cache is not counted." ::= {dsEntriesEntry 3} - dsCacheHits OBJECT-TYPE - SYNTAX Counter32 + dsCacheHits OBJECT-TYPE + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION @@ -491,7 +491,7 @@ IMPORTS ::= {dsEntriesEntry 4} dsSlaveHits OBJECT-TYPE - SYNTAX Counter32 + SYNTAX Counter64 MAX-ACCESS read-only STATUS current DESCRIPTION |