[Nagios-devel] Nagios 1.2 fast IO-patch

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Nagios 1.2 fast IO-patch

Post by Guest »

This is a multi-part message in MIME format.
--------------060302030702070702080105
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi all.

I wrote this patch the other day when I was juggling with automating
reports (avail.cgi), and I noticed that parsing the files alone took 8
seconds, even though it was less than 3MB of data.
The solution was to rewrite the read_line() function in cgiutils.c to
utilize larger read()-buffers and thus allow for IO bursting.
With this patch applied execution time went down to 0.7 seconds.

It also solves the problem with not-newline-terminated rows not being
read in the configuration files (discussed earlier).

The only drawback is that it will take forever to parse files that are
larger than you have physical RAM available (the kernel will utilize the
swap-space), and will fail completely (pretending the file is empty) if
the file is larger than the physical AND virtual RAM combined. However,
considering that it already takes forever even with relatively small
files, this shouldn't be a problem.

This patch is also available for 2.0a1, but I haven't had time to test
it to any extent with that release.

Tested on Openwall GNU/*/Linux, kernel 2.4.24-ow1 running on;
a) Celeron 2.0Ghz with 256MB RAM and a single 40GB IDE-disk.
b) Pentium 4 HT 2.8Ghz with 512MB RAM and dual 120GB IDE-disks with
software RAID-mirroring.
c) Dell Inspiron PIII 866Mhz with 256MB RAM and a single 20GB IDE-disk.

Cheers,
Sourcerer / Andreas Ericsson

--------------060302030702070702080105
Content-Type: text/x-patch;
name="nagios-1.2_fast-IO.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-1.2_fast-IO.diff"

diff -urN ../nagios-1.2/cgi/auth.c ./cgi/auth.c
--- ../nagios-1.2/cgi/auth.c 2002-04-27 07:44:07.000000000 +0200
+++ ./cgi/auth.c 2004-03-16 23:15:10.000000000 +0100
@@ -4,6 +4,10 @@
*
* Copyright (c) 1999-2002 Ethan Galstad ([email protected])
* Last Modified: 04-26-2002
+ * Lastest Modified: 2004-03-16 by Andreas Ericsson
+ *
+ * AE: Modified call to read_line() to match new function. Look in cgiutils.c
+ * AE: for details.
*
* License:
*
@@ -51,7 +55,7 @@
/* get current authentication information */
int get_authentication_information(authdata *authinfo){
FILE *fp;
- char input_buffer[MAX_INPUT_BUFFER];
+ char *input_buffer;
char *temp_ptr;
int needed_options;

@@ -107,85 +111,74 @@
}

/* read in authorization override vars from config file... */
- fp=fopen(DEFAULT_CGI_CONFIG_FILE,"r");
- if(fp!=NULL){
-
- while(read_line(input_buffer,MAX_INPUT_BUFFER,fp)){
-
- if(feof(fp))
- break;
-
- strip(input_buffer);
-
- /* we don't have a username yet, so fake the authentication if we find a default username defined */
- if(!strcmp(authinfo->username,"") && strstr(input_buffer,"default_user_name=")==input_buffer){
- temp_ptr=strtok(input_buffer,"=");
- temp_ptr=strtok(NULL,",");
- authinfo->username=(char *)malloc(strlen(temp_ptr)+1);
- if(authinfo->username==NULL)
- authinfo->username="";
- else
- strcpy(authinfo->username,temp_ptr);
- if(!strcmp(authinfo->username,""))
- authinfo->authenticated=FALSE;
- else
- authinfo->authenticated=TRUE;
- }
+ while((input_buffer = read_line(DEFAULT_CGI_CONFIG_FILE))){
+ /* we don't have a username yet, so fake the authentication if we find a default username defined */
+ if(!strcmp(authinfo->username,"") && strstr(input_buffer,"default_user_name=")==input_buffer){
+ temp_ptr=strtok(input_buffer,"=");
+ temp_ptr=strtok(NULL,",");
+ authinfo->username=(char *)malloc(strlen(temp_ptr)+1);
+ if(authinfo->username==NULL)
+ authinfo->username="";
+ else
+ strcpy(authinfo->username,temp_ptr);
+ if(!strcmp(authinfo->username,""))
+ authinfo->authenticated=FALSE;
+ else
+ authinfo->authenticated=TRUE;
+ }

- else if(strstr(input_buffer,"authorized_for_all_hosts=")==input_buffer){
- temp_ptr=strtok(input_buffer,"=");
- while((temp_ptr=strtok(NULL,","))){
- if(!strcmp(temp_ptr,authinfo->usernam

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked