Skip to content

Commit

Permalink
improve check results handling performance
Browse files Browse the repository at this point in the history
and add support for multiple result_workers
  • Loading branch information
sni committed Jan 11, 2022
1 parent 55f7f7b commit 8b60d1b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ This file documents the revision history for mod_gearman.

next:
- drop nagios 3, nagios 4 and icinga 1 support
- improve check results handling performance
- add support for multiple result_workers
- fix crash if gearmand is unreachable
- fix host acknowledgement notification author macros

Expand Down
1 change: 0 additions & 1 deletion common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
/* result worker */
else if ( !strcmp( key, "result_workers" ) ) {
opt->result_workers = atoi( value );
if(opt->result_workers > 1) { opt->result_workers = 1; }
if(opt->result_workers < 0) { opt->result_workers = 0; }
}

Expand Down
45 changes: 31 additions & 14 deletions neb_module_naemon/mod_gearman.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern int process_performance_data;
extern int log_notifications;

/* global variables */
static objectlist * mod_gm_result_list = 0;
static objectlist * mod_gm_result_list = NULL;
static pthread_mutex_t mod_gm_result_list_mutex = PTHREAD_MUTEX_INITIALIZER;
void *gearman_module_handle=NULL;
gearman_client_st client;
Expand Down Expand Up @@ -274,30 +274,47 @@ int nebmodule_deinit( int flags, int reason ) {

/* insert results list into naemon core */
static void move_results_to_core(struct nm_event_execution_properties *evprop) {
struct timeval tval_before, tval_after, tval_result;
objectlist *tmp_list = NULL;
if(evprop->execution_type == EVENT_EXEC_NORMAL) {
/* safely save off currently local list */
objectlist *cur = NULL;
int count = 0;
if(evprop->execution_type != EVENT_EXEC_NORMAL) {
return;
}

gettimeofday(&tval_before, NULL);
gm_log( GM_LOG_DEBUG, "move_results_to_core()\n" );

/* safely move result list aside */
pthread_mutex_lock(&mod_gm_result_list_mutex);
tmp_list = mod_gm_result_list;
mod_gm_result_list = NULL;
pthread_mutex_unlock(&mod_gm_result_list_mutex);

/* process result list */
while(tmp_list) {
cur = tmp_list;
tmp_list = tmp_list->next;

for( ; mod_gm_result_list; mod_gm_result_list = mod_gm_result_list->next) {
free(tmp_list);
process_check_result(mod_gm_result_list->object_ptr);
free_check_result(mod_gm_result_list->object_ptr);
free(mod_gm_result_list->object_ptr);
tmp_list = mod_gm_result_list;
process_check_result(cur->object_ptr);
free_check_result(cur->object_ptr);
free(cur->object_ptr);
free(cur);
count++;
}
mod_gm_result_list = 0;
free(tmp_list);

pthread_mutex_unlock(&mod_gm_result_list_mutex);
schedule_event(1, move_results_to_core, NULL);
}
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &tval_result);

gm_log( GM_LOG_DEBUG, "move_results_to_core processed %d results in %ld.%06lds\n", count, (long int)tval_result.tv_sec, (long int)tval_result.tv_usec );
schedule_event(1, move_results_to_core, NULL);
}

/* add list to gearman result list */
void mod_gm_add_result_to_list(check_result * newcr) {
pthread_mutex_lock(&mod_gm_result_list_mutex);
add_object_to_objectlist(&mod_gm_result_list, newcr);
prepend_object_to_objectlist(&mod_gm_result_list, newcr);
pthread_mutex_unlock(&mod_gm_result_list_mutex);
}

Expand Down

0 comments on commit 8b60d1b

Please sign in to comment.