[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Arkadiusz Miskiewicz] use /proc/meminfo instead of /proc/kcore (cor
From: |
Rory Toma |
Subject: |
Re: [Arkadiusz Miskiewicz] use /proc/meminfo instead of /proc/kcore (correct version of the patch) |
Date: |
Mon, 08 Sep 2003 13:55:33 -0700 |
We should wait on rewriting this till the next release. I believe that
much of the code can be made common by using sysconf and other portable
calls. I hope to be able to combine much of the sysdep stuff into one
file. (In between my day job, of course which has gotten annoyingly busy
8-))
On Mon, 2003-09-08 at 11:54, Jan-Henrik Haukeland wrote:
> What do you think Christian?
>
>
> ______________________________________________________________________
> From: Arkadiusz Miskiewicz <address@hidden>
> To: Jan-Henrik Haukeland <address@hidden>
> Subject: use /proc/meminfo instead of /proc/kcore (correct version of the
> patch)
> Date: Mon, 08 Sep 2003 20:03:55 +0200
>
>
> diff -urN monit-4.0.org/process/sysdep_LINUX.c
> monit-4.0/process/sysdep_LINUX.c
> --- monit-4.0.org/process/sysdep_LINUX.c 2003-09-08 19:20:44.000000000
> +0200
> +++ monit-4.0/process/sysdep_LINUX.c 2003-09-08 19:26:46.000000000 +0200
> @@ -84,24 +84,38 @@
> * @file
> */
>
> -#define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
> +#define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
> +#define FREEMEM "MemFree:"
> +#define FREESWAP "SwapFree:"
>
> int init_process_info_sysdep(void) {
>
> - struct stat buf;
> -
> + int memfd;
> + char buf[1024], *ptr1, *ptr2;
>
> - /* I hope this is okay hack to get the total memsize. (-: */
> + if ((memfd = open("/proc/meminfo", O_RDONLY)) == -1) {
> + return FALSE;
> + }
>
> - if ( stat("/proc/kcore", &buf) != 0 ) {
> + /* read the file */
> + if (read(memfd, buf, sizeof(buf)) < 0) {
> + close(memfd);
> + return FALSE;
> + }
>
> - return FALSE;
> + close(memfd);
> +
> + ptr1 = strstr(buf, FREEMEM);
> + ptr2 = strstr(buf, FREESWAP);
>
> + if (!ptr1 || !ptr2) {
> + return FALSE;
> }
>
> - num_cpus= sysconf(_SC_NPROCESSORS_CONF);
> + /* we only care about integer values */
> + mem_kbyte_max = atoi(ptr1+strlen(FREEMEM)) /* +
> atoi(ptr2+strlen(FREESWAP))
> */ ;
>
> - mem_kbyte_max = buf.st_size>>10;
> + num_cpus= sysconf(_SC_NPROCESSORS_CONF);
>
> return TRUE;
>
>
> --
> Arkadiusz MiĆkiewicz, Grupa BeeProvider - http://www.beep.pl/
>
>
>
> ______________________________________________________________________
--
Rory Toma address@hidden
VP of Run Level 9 http://www.trs80.net
Digeo Digital http://www.digeo.com
signature.asc
Description: This is a digitally signed message part