NRPE Memory Limit 2GB ??

Andreas Ericsson ae at op5.se
Thu Oct 7 15:15:38 CEST 2004


Wengrzik, Andreas wrote:
>>Wengrzik, Andreas wrote:
>>
>>>>That would be the check_swap or check_mem source-code file.
>>>>
>>>
>>>Hi!
>>>
>>>There are some files for the memload check:
>>>
>>>memload_nrpe_nt.cpp
>>>memload_nrpe_nt.dsp
>>>memload_nrpe_nt.dsw
>>>memload_nrpe_nt.ncb
>>>memload_nrpe_nt.opt
>>>memload_nrpe_nt.plg
>>>
>>>I searched for 'signed int' in these files but there was no 
>>
>>result :/
>>
>>Variables are signed by default. Search for 'int' and see how 
>>it's used. 
>>I'm sure you'll be able to deduce the variable name, and then you can 
>>simply change its declaration to be make it unsigned long long.
>>
> 
> 
> Sorry about maybe boring you... i´ve found these part of a file:
> 
> int main(int argc, char* argv[])
> {
> 	int freeswap_memory;
> 	int totalswap_memory;
> 	int freephys_memory;
> 	int totalphys_memory;
> 	int warning_threshold;
> 	int critical_threshold;	
> 	MEMORYSTATUS stat;
> 

Change the int's to unsigned long long. I expect that's how they're 
declared in the header files for the MEMORYSTATUS structure 
(MEMORYSTATUS is most likely a macro. The struct will be named something 
else).

> 	/* Get Values from command line */
> 	if (argc != 3) {
>       printf ("NRPE_NT Plugin, MEMORY Load, GX Networks, Stephen Strudwick\n");
>       printf ("usage: memload warning threshold(%%) critical threshold(%%)\n");
>       printf ("example: 70 90\n");
>       return Unknown;
> 	}
> 
>     warning_threshold = atoi(argv[1]);
> 	critical_threshold = atoi(argv[2]);
> 
>     GlobalMemoryStatus (&stat);
> 
> 	totalphys_memory = stat.dwTotalPhys/1048576;
> 	freephys_memory = stat.dwAvailPhys/1048576;
> 	totalswap_memory = stat.dwTotalPageFile/1048576;
> 	freeswap_memory = stat.dwAvailPageFile/1048576;
> 
> 	if (!totalswap_memory) {
>       return Unknown;
> 	}
>   
> 	if (!freephys_memory) {
>       return Unknown;
> 	}
>   
> 	if (!totalphys_memory) {
>       return Unknown;
> 	}
>   
> 	if (!freeswap_memory) {
>       return Unknown;
> 	}
> 
> 	double mean_used = ((double)((totalphys_memory)-(freephys_memory)) / (double)totalphys_memory) * 100;
> 	double mean_free = ((double)freephys_memory / (double)totalphys_memory) * 100;
> 
> 	double mean_pused = ((double)((totalswap_memory)-(freeswap_memory)) / (double)totalswap_memory) * 100;
> 	double mean_pfree = ((double)freeswap_memory / (double)totalswap_memory) * 100;
> 

Using double here seems wildly inappropriate, since binary division 
returns integer values. You might want to have a chat with the plugin 
author about that.

> 	printf("Mem: %d MB (%d%%) / %d MB (%d%%) ", ((totalphys_memory)-(freephys_memory)), (int)floor(mean_used), (totalphys_memory), (int)floor(mean_free));
> 

You'll also need to change the %d to %llu here to use the unsigned long 
long values. The compiler should be able to handle this by itself, but 
if it's a tacky one it won't, and you'll end up with very strange output.

> 	/* hack, on some systems the paged memory values are reversed !?? So dont print out anything if its fscked */
> 	if (mean_pused >= 0 && mean_pused <= 100) {
> 	  printf("Paged Mem: %d MB (%d%%) / %d MB (%d%%)\n", ((totalswap_memory)-(freeswap_memory)), (int)floor(mean_pused), (totalswap_memory), (int)floor(mean_pfree));
>     }
> 
> 



> 
> 
> There are a lot of information with int, is this the right way?

No. Signed int (int without 'unsigned' in front of it) can store values 
between -2G and 2G-1 on 32bit OS'es (32 bits wide, with one bit being 
the 'sign' bit (positive or negative number) makes 2^31 = 2G). unsigned 
long long is 64 bits wide on most 32bit OS'es (double the width, and 
unsigned means we don't care about negative numbers), so it holds a 
maximum of 2^64, or 4G*4G, which is more than the number of bytes of RAM 
available on this entire planet. It should suffice.

> I really don´t know which int i should change and which one should stay :(

Change them all. The OS should report them as 64 bit numbers, or provide 
a multiplier to use to get values above the 32 bit limitation. You'll 
know which one when you try to compile it.

> I think this is the last question to success.

I'd say so, yes.

> Thanks for all your help!!!

You're welcome.

> I´ve often look into the list and about 70% of the solutions comes from you :)
> 

He. I don't like TV, so I have to find other amusements, and there 
aren't enough new movies out at the cinema to keep me very busy.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list