X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemory.c;h=ecaa0c099b86e6e4959a19ba3674be53750ef779;hb=389bd16230471c130f36532096bb3c92ab8c3b0b;hp=e0e0cbb163eebab1441ef91e7ebf3b70496aab02;hpb=bb1db6bf6481a6e8ee48144860cb640b3bd2a36d;p=collectd.git diff --git a/src/memory.c b/src/memory.c index e0e0cbb1..ecaa0c09 100644 --- a/src/memory.c +++ b/src/memory.c @@ -2,6 +2,7 @@ * collectd - src/memory.c * Copyright (C) 2005-2008 Florian octo Forster * Copyright (C) 2009 Simon Kuhnle + * Copyright (C) 2009 Manuel Sanmartin * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -19,6 +20,7 @@ * Authors: * Florian octo Forster * Simon Kuhnle + * Manuel Sanmartin **/ #include "collectd.h" @@ -49,6 +51,11 @@ # include #endif +#if HAVE_PERFSTAT +# include +# include +#endif /* HAVE_PERFSTAT */ + /* vm_statistics_data_t */ #if HAVE_HOST_STATISTICS static mach_port_t port_host; @@ -75,7 +82,10 @@ static int pagesize; #elif HAVE_LIBSTATGRAB /* no global variables */ /* endif HAVE_LIBSTATGRAB */ - +#elif HAVE_PERFSTAT +static int pagesize; +static perfstat_memory_total_t pmemory; +/* endif HAVE_PERFSTAT */ #else # error "No applicable input method." #endif @@ -116,8 +126,11 @@ static int memory_init (void) #elif HAVE_LIBSTATGRAB /* no init stuff */ -#endif /* HAVE_LIBSTATGRAB */ +/* #endif HAVE_LIBSTATGRAB */ +#elif HAVE_PERFSTAT + pagesize = getpagesize (); +#endif /* HAVE_PERFSTAT */ return (0); } /* int memory_init */ @@ -364,7 +377,22 @@ static int memory_read (void) memory_submit ("cached", ios->cache); memory_submit ("free", ios->free); } -#endif /* HAVE_LIBSTATGRAB */ +/* #endif HAVE_LIBSTATGRAB */ + +#elif HAVE_PERFSTAT + if (perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1) < 0) + { + char errbuf[1024]; + WARNING ("memory plugin: perfstat_memory_total failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + memory_submit ("used", pmemory.real_inuse * pagesize); + memory_submit ("free", pmemory.real_free * pagesize); + memory_submit ("cached", pmemory.numperm * pagesize); + memory_submit ("system", pmemory.real_system * pagesize); + memory_submit ("user", pmemory.real_process * pagesize); +#endif /* HAVE_PERFSTAT */ return (0); }