X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemory.c;h=b79a74b7cb42a307916eef911dbba3a968ac456a;hb=f1b5b8611d87a7904c31ae4b28ea47f11f3c38b9;hp=d6c3c88837d2ca408440ee56d6bba2bf8f9b9d1c;hpb=427d99e60f2a9b3b1e6b62b1d5fd36d6512f991b;p=collectd.git diff --git a/src/memory.c b/src/memory.c index d6c3c888..b79a74b7 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,6 +1,8 @@ /** * 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 @@ -17,6 +19,8 @@ * * Authors: * Florian octo Forster + * Simon Kuhnle + * Manuel Sanmartin **/ #include "collectd.h" @@ -47,16 +51,17 @@ # include #endif +#if HAVE_PERFSTAT +# include +# include +#endif /* HAVE_PERFSTAT */ + /* vm_statistics_data_t */ #if HAVE_HOST_STATISTICS static mach_port_t port_host; static vm_size_t pagesize; /* #endif HAVE_HOST_STATISTICS */ -#elif HAVE_SYSCTL -static int pagesize; -/* #endif HAVE_SYSCTL */ - #elif HAVE_SYSCTLBYNAME /* no global variables */ /* #endif HAVE_SYSCTLBYNAME */ @@ -70,10 +75,17 @@ static int pagesize; static kstat_t *ksp; /* #endif HAVE_LIBKSTAT */ +#elif HAVE_SYSCTL +static int pagesize; +/* #endif HAVE_SYSCTL */ + #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 @@ -85,15 +97,6 @@ static int memory_init (void) host_page_size (port_host, &pagesize); /* #endif HAVE_HOST_STATISTICS */ -#elif HAVE_SYSCTL - pagesize = getpagesize (); - if (pagesize <= 0) - { - ERROR ("memory plugin: Invalid pagesize: %i", pagesize); - return (-1); - } -/* #endif HAVE_SYSCTL */ - #elif HAVE_SYSCTLBYNAME /* no init stuff */ /* #endif HAVE_SYSCTLBYNAME */ @@ -110,8 +113,24 @@ static int memory_init (void) ksp = NULL; return (-1); } -#endif /* HAVE_LIBKSTAT */ +/* #endif HAVE_LIBKSTAT */ + +#elif HAVE_SYSCTL + pagesize = getpagesize (); + if (pagesize <= 0) + { + ERROR ("memory plugin: Invalid pagesize: %i", pagesize); + return (-1); + } +/* #endif HAVE_SYSCTL */ +#elif HAVE_LIBSTATGRAB +/* no init stuff */ +/* #endif HAVE_LIBSTATGRAB */ + +#elif HAVE_PERFSTAT + pagesize = getpagesize (); +#endif /* HAVE_PERFSTAT */ return (0); } /* int memory_init */ @@ -139,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); @@ -176,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); @@ -187,27 +206,6 @@ static int memory_read (void) memory_submit ("free", free); /* #endif HAVE_HOST_STATISTICS */ -#elif HAVE_SYSCTL - int mib[] = {CTL_VM, VM_METER}; - struct vmtotal vmtotal; - size_t size; - - memset (&vmtotal, 0, sizeof (vmtotal)); - size = sizeof (vmtotal); - - if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0) { - char errbuf[1024]; - WARNING ("memory plugin: sysctl failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); - return (-1); - } - - assert (pagesize > 0); - memory_submit ("active", vmtotal.t_arm * pagesize); - memory_submit ("inactive", (vmtotal.t_rm - vmtotal.t_arm) * pagesize); - memory_submit ("free", vmtotal.t_free * pagesize); -/* #endif HAVE_SYSCTL */ - #elif HAVE_SYSCTLBYNAME /* * vm.stats.vm.v_page_size: 4096 @@ -242,7 +240,7 @@ static int memory_read (void) NULL, 0) == 0) { sysctl_vals[i] = value; - DEBUG ("memory plugin: %26s: %6i", sysctl_keys[i], sysctl_vals[i]); + DEBUG ("memory plugin: %26s: %g", sysctl_keys[i], sysctl_vals[i]); } else { @@ -265,7 +263,7 @@ static int memory_read (void) #elif KERNEL_LINUX FILE *fh; char buffer[1024]; - + char *fields[8]; int numfields; @@ -349,6 +347,27 @@ static int memory_read (void) memory_submit ("locked", mem_lock); /* #endif HAVE_LIBKSTAT */ +#elif HAVE_SYSCTL + int mib[] = {CTL_VM, VM_METER}; + struct vmtotal vmtotal; + size_t size; + + memset (&vmtotal, 0, sizeof (vmtotal)); + size = sizeof (vmtotal); + + if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0) { + char errbuf[1024]; + WARNING ("memory plugin: sysctl failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + assert (pagesize > 0); + memory_submit ("active", vmtotal.t_arm * pagesize); + memory_submit ("inactive", (vmtotal.t_rm - vmtotal.t_arm) * pagesize); + memory_submit ("free", vmtotal.t_free * pagesize); +/* #endif HAVE_SYSCTL */ + #elif HAVE_LIBSTATGRAB sg_mem_stats *ios; @@ -358,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); }