[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: event profiler with config option

git at icinga.org git at icinga.org
Mon May 24 21:59:43 CEST 2010


Module: icinga-core
Branch: mfriedrich/core
Commit: f53ab049f3f88ffd3f21a8444d5b1593dc90e925
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=f53ab049f3f88ffd3f21a8444d5b1593dc90e925

Author: hirenp <hirenp at firebird.(none)>
Date:   Fri May 21 16:30:24 2010 +0200

event profiler with config option

---

 base/Makefile.in            |    4 +-
 base/config.c               |    6 +++++
 base/events.c               |   19 +++++++++++++++-
 base/icinga.c               |    3 ++
 base/icingastats.c          |   48 +++++++++++++++++++++++++++++++++++++++++++
 sample-config/icinga.cfg.in |    3 +-
 xdata/xsddefault.c          |    9 ++++++++
 7 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/base/Makefile.in b/base/Makefile.in
index b7cbaa3..2b07809 100644
--- a/base/Makefile.in
+++ b/base/Makefile.in
@@ -122,7 +122,7 @@ DDATAHDRS=
 DDATADEPS=$(DDATALIBS)
 
 
-OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o skiplist.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) $(PERLXSI_O)
+OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o skiplist.o utils.o profiler.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) $(PERLXSI_O)
 OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(DDATADEPS) $(BROKER_H)
 
 all: icinga icingastats
@@ -182,7 +182,7 @@ icinga: icinga.c $(OBJS) $(OBJDEPS) $(SRC_INCLUDE)/icinga.h $(SRC_INCLUDE)/locat
 	$(CC) $(CFLAGS) -o $@ icinga.c $(OBJS) $(BROKER_LDFLAGS) $(LDFLAGS) $(PERLLIBS) $(MATHLIBS) $(SOCKETLIBS) $(THREADLIBS) $(BROKERLIBS) $(LIBS)
 
 icingastats: icingastats.c $(SRC_INCLUDE)/locations.h
-	$(CC) $(CFLAGS) -o $@ icingastats.c $(LDFLAGS) $(MATHLIBS) $(LIBS)
+	$(CC) $(CFLAGS) -o $@ statsprofiler.c icingastats.c $(LDFLAGS) $(MATHLIBS) $(LIBS)
 
 $(OBJS): $(SRC_INCLUDE)/locations.h
 
diff --git a/base/config.c b/base/config.c
index e750f82..6f6bf5a 100644
--- a/base/config.c
+++ b/base/config.c
@@ -216,6 +216,7 @@ extern char             *debug_file;
 extern int              debug_level;
 extern int              debug_verbosity;
 extern unsigned long    max_debug_file_size;
+extern int              event_profiling_enabled;
 
 
 
@@ -1334,6 +1335,11 @@ int read_main_config_file(char *main_config_file){
 		else if(!strcmp(variable,"bare_update_check"))
 			bare_update_check=(atoi(value)>0)?TRUE:FALSE;
 
+               else if(!strcmp(variable,"event_profiling_enabled"))
+                       event_profiling_enabled=(atoi(value)>0)?TRUE:FALSE;
+
+
+
 		/*** AUTH_FILE VARIABLE USED BY EMBEDDED PERL INTERPRETER ***/
 		else if(!strcmp(variable,"auth_file")){
 
diff --git a/base/events.c b/base/events.c
index faf5442..724ed26 100644
--- a/base/events.c
+++ b/base/events.c
@@ -31,6 +31,7 @@
 #include "../include/broker.h"
 #include "../include/sretention.h"
 
+#include "../include/profiler.h"
 
 extern char	*config_file;
 
@@ -85,6 +86,8 @@ extern int      child_processes_fork_twice;
 
 extern int      time_change_threshold;
 
+extern int 	event_profiling_enabled;
+
 timed_event *event_list_low=NULL;
 timed_event *event_list_low_tail=NULL;
 timed_event *event_list_high=NULL;
@@ -1069,6 +1072,7 @@ int event_execution_loop(void){
 	struct timespec delay;
 	pid_t wait_result;
 
+	struct timeval start;
 
 	log_debug_info(DEBUGL_FUNCTIONS,0,"event_execution_loop() start\n");
 
@@ -1087,7 +1091,10 @@ int event_execution_loop(void){
 	sleep_event.next=NULL;
 	sleep_event.prev=NULL;
 
-	while(1){
+	while(1)
+	{
+		if(event_profiling_enabled)
+        		gettimeofday(&start,NULL);
 
 		/* see if we should exit or restart (a signal was encountered) */
 		if(sigshutdown==TRUE || sigrestart==TRUE)
@@ -1326,6 +1333,10 @@ int event_execution_loop(void){
 			last_status_update=current_time;
 			update_program_status(FALSE);
 			}
+
+		if(event_profiling_enabled)
+            		profiler_update(EVENT_LOOP_COMPLETION, start);
+
 	        }
 
 	log_debug_info(DEBUGL_FUNCTIONS,0,"event_execution_loop() end\n");
@@ -1342,7 +1353,8 @@ int handle_timed_event(timed_event *event){
 	void (*userfunc)(void *);
 	struct timeval tv;
 	double latency=0.0;
-
+	struct timeval start;
+	gettimeofday(&start,NULL);
 
 	log_debug_info(DEBUGL_FUNCTIONS,0,"handle_timed_event() start\n");
 
@@ -1537,6 +1549,9 @@ int handle_timed_event(timed_event *event){
 
 	log_debug_info(DEBUGL_FUNCTIONS,0,"handle_timed_event() end\n");
 
+	if(event_profiling_enabled)
+		profiler_update(event->event_type,start);
+
 	return OK;
         }
 
diff --git a/base/icinga.c b/base/icinga.c
index 98b7a44..afb33e3 100644
--- a/base/icinga.c
+++ b/base/icinga.c
@@ -48,6 +48,7 @@
 #include "../include/broker.h"
 #include "../include/nebmods.h"
 #include "../include/nebmodules.h"
+#include "../include/profiler.h"
 
 /*#define DEBUG_MEMORY 1*/
 #ifdef DEBUG_MEMORY
@@ -245,6 +246,7 @@ int             command_file_fd;
 FILE            *command_file_fp;
 int             command_file_created=FALSE;
 
+int             event_profiling_enabled=FALSE;
 
 extern contact	       *contact_list;
 extern contactgroup    *contactgroup_list;
@@ -387,6 +389,7 @@ int main(int argc, char **argv, char **env){
 #ifdef DEBUG_MEMORY
 	mtrace();
 #endif
+	profiler_init();
 
 	if(daemon_mode==FALSE){
 		printf("\n%s %s\n", PROGRAM_NAME ,PROGRAM_VERSION);
diff --git a/base/icingastats.c b/base/icingastats.c
index 694a539..2b28300 100644
--- a/base/icingastats.c
+++ b/base/icingastats.c
@@ -31,12 +31,15 @@
 #include "../include/icinga.h"
 #include "../include/locations.h"
 
+#include "../include/statsprofiler.h"
+
 #define STATUS_NO_DATA             0
 #define STATUS_INFO_DATA           1
 #define STATUS_PROGRAM_DATA        2
 #define STATUS_HOST_DATA           3
 #define STATUS_SERVICE_DATA        4
 
+profile_object* profiled_data = NULL;
 
 char *main_config_file=NULL;
 char *status_file=NULL;
@@ -197,6 +200,7 @@ int external_commands_last_15min=0;
 int total_external_command_buffer_slots=0;
 int used_external_command_buffer_slots=0;
 int high_external_command_buffer_slots=0;
+int event_profiling_enabled=0;
 
 
 
@@ -391,6 +395,29 @@ int main(int argc, char **argv){
 		printf(" NUMPSVSVCCHECKSxM    number of passive service checks occuring in last 1/5/15 minutes.\n");
 		printf(" NUMEXTCMDSxM         number of external commands processed in last 1/5/15 minutes.\n");
 
+       		 /* read main config file */
+        	result=read_config_file();
+        	if(result==ERROR && mrtg_mode==FALSE)
+        	{
+            		printf("Error processing config file '%s'\n",main_config_file);
+            		return ERROR;
+        	}
+
+        	/* read the status file */
+        	result=read_status_file();
+        	if(result==ERROR && mrtg_mode==FALSE)
+        	{
+            		printf("Error reading status file '%s'\n",status_file);
+            		return ERROR;
+        	}
+
+        	profile_object* p = profiled_data;
+        	while(p)
+        	{
+            		printf("PROFILE_(COUNTER/ELAPSED/EVENTPS)_%s\t\tdynamically generated profile data.\n",p->name);
+            		p = p->next;
+        	}
+
 		printf("\n");
 		printf(" Note: Replace x's in MRTG variable names with 'MIN', 'MAX', 'AVG', or the\n");
 		printf("       the appropriate number (i.e. '1', '5', '15', or '60').\n");
@@ -760,6 +787,8 @@ int display_mrtg_values(void){
 		else if(!strcmp(temp_ptr,"NUMHSTDOWNTIME"))
 			printf("%d%s",hosts_in_downtime,mrtg_delimiter);
 
+        	else if(strstr(temp_ptr,"PROFILE_") && event_profiling_enabled)
+            		profile_data_output_mrtg(temp_ptr+strlen("PROFILE_"),mrtg_delimiter);
 		else
 			printf("%s%s",temp_ptr,mrtg_delimiter);
 	        }
@@ -849,6 +878,14 @@ int display_stats(void){
 	printf("\n");
 
 
+	if(event_profiling_enabled){
+		printf("\n\nEVENT PROFILE DATA:\t\ttotal seconds spent / number of events / avg time per event / events per second \n");
+		printf("----------------------------------------------------\n");
+
+		profile_data_print();
+	}
+
+
 	/*
 	printf("CURRENT COMMENT DATA\n");
 	printf("----------------------------------------------------\n");
@@ -1317,6 +1354,17 @@ int read_status_file(void){
 					if((temp_ptr=strtok(NULL,",")))
 						serial_host_checks_last_15min=atoi(temp_ptr);
 					}
+				else if(!strcmp(var,"event_profiling_enabled")){
+					event_profiling_enabled=atoi(val);
+					}
+                		else if(strstr(var,"PROFILE_") && !strstr(var,"null"))
+                		{
+                    			if(strstr(var,"COUNTER"))
+                        		profile_object_update_count(var+strlen("PROFILE_COUNTER_"),strtod(val,NULL));
+
+                    			if(strstr(var,"ELAPSED"))
+                        			profile_object_update_elapsed(var+strlen("PROFILE_ELAPSED_"),atoi(val));
+                		}
 				break;
 
 			case STATUS_HOST_DATA:
diff --git a/sample-config/icinga.cfg.in b/sample-config/icinga.cfg.in
index 17812d6..3ab57fd 100644
--- a/sample-config/icinga.cfg.in
+++ b/sample-config/icinga.cfg.in
@@ -1377,4 +1377,5 @@ debug_file=@localstatedir@/icinga.debug
 
 max_debug_file_size=1000000
 
-
+# this option enables or disables event profiling for stats of event counts and time taken for events
+event_profiling_enabled=1
diff --git a/xdata/xsddefault.c b/xdata/xsddefault.c
index 317a22e..6bd7d08 100644
--- a/xdata/xsddefault.c
+++ b/xdata/xsddefault.c
@@ -35,6 +35,8 @@
 #include "../include/macros.h"
 #include "../include/skiplist.h"
 
+#include "../include/profiler.h"
+
 #ifdef NSCORE
 #include "../include/icinga.h"
 #endif
@@ -125,6 +127,7 @@ extern char           *global_host_event_handler;
 extern char           *global_service_event_handler;
 
 extern check_stats    check_statistics[MAX_CHECK_STATS_TYPES];
+extern	event_profiling_enabled;
 #endif
 
 
@@ -455,6 +458,12 @@ int xsddefault_save_status_data(void){
 
 	fprintf(fp,"\tparallel_host_check_stats=%d,%d,%d\n",check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[0],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[1],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[2]);
 	fprintf(fp,"\tserial_host_check_stats=%d,%d,%d\n",check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[0],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[1],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[2]);
+
+	fprintf(fp,"\tevent_profiling_enabled=%d\n",event_profiling_enabled);
+
+	if(event_profiling_enabled)
+    		profiler_output(fp);
+
 	fprintf(fp,"\t}\n\n");
 
 





More information about the icinga-checkins mailing list