X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fmemory.c;h=faf7092c8a329b7211473804509128ee5e6f8669;hb=2139f51939cc70f5668ab68a16fefdb3d52bd663;hp=799a80c31684c963172fa89363e9f931c24f4886;hpb=0ebe3efc7b797546bcae87a946cff1c4cf472919;p=collectd.git diff --git a/src/memory.c b/src/memory.c index 799a80c3..faf7092c 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,15 +126,18 @@ 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 */ static void memory_submit (const char *type_instance, gauge_t value) { value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; + value_list_t vl = VALUE_LIST_INIT (plugin_interval); values[0].gauge = value; @@ -145,10 +158,10 @@ static int memory_read (void) vm_statistics_data_t vm_data; mach_msg_type_number_t vm_data_len; - long long wired; - long long active; - long long inactive; - long long free; + gauge_t wired; + gauge_t active; + gauge_t inactive; + gauge_t free; if (!port_host || !pagesize) return (-1); @@ -182,10 +195,10 @@ static int memory_read (void) * This memory is not being used. */ - wired = vm_data.wire_count * pagesize; - active = vm_data.active_count * pagesize; - inactive = vm_data.inactive_count * pagesize; - free = vm_data.free_count * pagesize; + wired = (gauge_t) (((uint64_t) vm_data.wire_count) * ((uint64_t) pagesize)); + active = (gauge_t) (((uint64_t) vm_data.active_count) * ((uint64_t) pagesize)); + inactive = (gauge_t) (((uint64_t) vm_data.inactive_count) * ((uint64_t) pagesize)); + free = (gauge_t) (((uint64_t) vm_data.free_count) * ((uint64_t) pagesize)); memory_submit ("wired", wired); memory_submit ("active", active); @@ -250,7 +263,7 @@ static int memory_read (void) #elif KERNEL_LINUX FILE *fh; char buffer[1024]; - + char *fields[8]; int numfields; @@ -364,13 +377,30 @@ 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); } -void module_register (void) +void module_register (plugin_loaddata_t *data) { + PLUGIN_INIT_INTERVAL (data); + plugin_register_init ("memory", memory_init); - plugin_register_read ("memory", memory_read); + plugin_register_read ("memory", memory_read, plugin_interval); } /* void module_register */