[icinga-checkins] icinga.org: icinga-core/test/core: core: increase performance on host-> service relation counter (config reading, flapping)

git at icinga.org git at icinga.org
Sun Mar 10 20:50:27 CET 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sun Mar 10 20:24:40 2013 +0100

core: increase performance on host->service relation counter (config reading, flapping)

when a service is checked against its host association we can already
update the relation counter as well as total check interval.

the first is required for the config pre flight check while the second
is used within flapping detection.

original patch by Andreas Ericsson, fixed for usage in Icinga.

refs #3820

---

 Changelog        |    1 +
 base/config.c    |   36 +++---------------------------------
 common/objects.c |    5 +++++
 3 files changed, 9 insertions(+), 33 deletions(-)

diff --git a/Changelog b/Changelog
index f5e1c03..89e2307 100644
--- a/Changelog
+++ b/Changelog
@@ -25,6 +25,7 @@ ENHANCEMENTS
 * core: add the notification type by string to debug logs; set CUSTOM=8, STALKING=9 (Andreas Ericsson) #3818 - MF
 * core: skip writing status.dat if explicitely set to /dev/null (e.g. when using alternate data retrieval methods like IDOUtils) (Andreas Ericsson) #3819 - MF
 * core: avoid writing objects.cache if set to /dev/null (Andreas Ericsson) #3819 - MF
+* core: increase performance on host->service relation counter (config reading, flapping) #3820 - MF
 
 * classic ui: Add "set_expire_ack_by_default" to cgi configuration #3476 - CF
 * classic ui: Add "send_ack_notifications" to cgi configuration (TheCry) #3467 - CF
diff --git a/base/config.c b/base/config.c
index e4ebd7d..a6928d6 100644
--- a/base/config.c
+++ b/base/config.c
@@ -1838,14 +1838,6 @@ int pre_flight_check(void) {
 		}
 	}
 
-	/* count number of services associated with each host (we need this for flap detection)... */
-	for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
-		if ((temp_host = find_host(temp_service->host_name))) {
-			temp_host->total_services++;
-			temp_host->total_service_check_interval += temp_service->check_interval;
-		}
-	}
-
 	if (verify_config) {
 		printf("\n");
 		printf("Total Warnings: %d\n", warnings);
@@ -1912,7 +1904,6 @@ int pre_flight_object_check(int *w, int *e) {
 	module *temp_module = NULL;
 	char *buf = NULL;
 	char *temp_command_name = "";
-	int found = FALSE;
 	int total_objects = 0;
 	int warnings = 0;
 	int errors = 0;
@@ -1950,7 +1941,6 @@ int pre_flight_object_check(int *w, int *e) {
 	for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
 
 		total_objects++;
-		found = FALSE;
 
 		/* check for a valid host */
 		temp_host = find_host(temp_service->host_name);
@@ -2011,9 +2001,6 @@ int pre_flight_object_check(int *w, int *e) {
 			warnings++;
 		}
 
-		/* reset the found flag */
-		found = FALSE;
-
 		/* check for valid contacts */
 		for (temp_contactsmember = temp_service->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
 
@@ -2115,26 +2102,11 @@ int pre_flight_object_check(int *w, int *e) {
 	for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
 
 		total_objects++;
-		found = FALSE;
 
 		/* make sure each host has at least one service associated with it */
-		/* 02/21/08 NOTE: this is extremely inefficient */
-		if (use_precached_objects == FALSE && use_large_installation_tweaks == FALSE) {
-
-			for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
-				if (!strcmp(temp_service->host_name, temp_host->name)) {
-					found = TRUE;
-					break;
-				}
-			}
-
-			/* we couldn't find a service associated with this host! */
-			if (found == FALSE && verify_config >= 2) {
-				logit(NSLOG_VERIFICATION_WARNING, TRUE, "Warning: Host '%s' has no services associated with it!", temp_host->name);
-				warnings++;
-			}
-
-			found = FALSE;
+		if(temp_host->total_services == 0 && verify_config >= 2) {
+			logit(NSLOG_VERIFICATION_WARNING, TRUE, "Warning: Host '%s' has no services associated with it!", temp_host->name);
+			warnings++;
 		}
 
 		/* check the event handler command */
@@ -2473,8 +2445,6 @@ int pre_flight_object_check(int *w, int *e) {
 		printf("Checking contact groups...\n");
 	for (temp_contactgroup = contactgroup_list, total_objects = 0; temp_contactgroup != NULL; temp_contactgroup = temp_contactgroup->next, total_objects++) {
 
-		found = FALSE;
-
 		/* check all the group members */
 		for (temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
 
diff --git a/common/objects.c b/common/objects.c
index dafbb46..a513529 100644
--- a/common/objects.c
+++ b/common/objects.c
@@ -961,6 +961,11 @@ servicesmember *add_service_link_to_host(host *hst, service *service_ptr) {
 	/* initialize values */
 #ifdef NSCORE
 	new_servicesmember->service_ptr = service_ptr;
+
+	/* increment host->service counter for later processing */
+	hst->total_services++;
+	/* calculate check interval total for flapping */
+	hst->total_service_check_interval += service_ptr->check_interval;
 #endif
 
 	/* add the child entry to the host definition */





More information about the icinga-checkins mailing list