+#if HAVE_HOST_STATISTICS
+ kern_return_t status;
+ 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;
+
+ if (!port_host || !pagesize)
+ return (-1);
+
+ vm_data_len = sizeof (vm_data) / sizeof (natural_t);
+ if ((status = host_statistics (port_host, HOST_VM_INFO,
+ (host_info_t) &vm_data,
+ &vm_data_len)) != KERN_SUCCESS)
+ {
+ ERROR ("memory-plugin: host_statistics failed and returned the value %i", (int) status);
+ return (-1);
+ }
+
+ /*
+ * From <http://docs.info.apple.com/article.html?artnum=107918>:
+ *
+ * Wired memory
+ * This information can't be cached to disk, so it must stay in RAM.
+ * The amount depends on what applications you are using.
+ *
+ * Active memory
+ * This information is currently in RAM and actively being used.
+ *
+ * Inactive memory
+ * This information is no longer being used and has been cached to
+ * disk, but it will remain in RAM until another application needs
+ * the space. Leaving this information in RAM is to your advantage if
+ * you (or a client of your computer) come back to it later.
+ *
+ * Free memory
+ * 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;
+
+ memory_submit ("wired", wired);
+ memory_submit ("active", active);
+ memory_submit ("inactive", inactive);
+ memory_submit ("free", free);
+/* #endif HAVE_HOST_STATISTICS */
+
+#elif HAVE_SYSCTLBYNAME
+ /*
+ * vm.stats.vm.v_page_size: 4096
+ * vm.stats.vm.v_page_count: 246178
+ * vm.stats.vm.v_free_count: 28760
+ * vm.stats.vm.v_wire_count: 37526
+ * vm.stats.vm.v_active_count: 55239
+ * vm.stats.vm.v_inactive_count: 113730
+ * vm.stats.vm.v_cache_count: 10809
+ */
+ char *sysctl_keys[8] =
+ {
+ "vm.stats.vm.v_page_size",
+ "vm.stats.vm.v_page_count",
+ "vm.stats.vm.v_free_count",
+ "vm.stats.vm.v_wire_count",
+ "vm.stats.vm.v_active_count",
+ "vm.stats.vm.v_inactive_count",
+ "vm.stats.vm.v_cache_count",
+ NULL
+ };
+ double sysctl_vals[8];
+
+ int i;
+
+ for (i = 0; sysctl_keys[i] != NULL; i++)
+ {
+ int value;
+ size_t value_len = sizeof (value);
+
+ if (sysctlbyname (sysctl_keys[i], (void *) &value, &value_len,
+ NULL, 0) == 0)
+ {
+ sysctl_vals[i] = value;
+ DEBUG ("memory plugin: %26s: %6i", sysctl_keys[i], sysctl_vals[i]);
+ }
+ else
+ {
+ sysctl_vals[i] = NAN;
+ }
+ } /* for (sysctl_keys) */
+
+ /* multiply all all page counts with the pagesize */
+ for (i = 1; sysctl_keys[i] != NULL; i++)
+ if (!isnan (sysctl_vals[i]))
+ sysctl_vals[i] *= sysctl_vals[0];
+
+ memory_submit ("free", sysctl_vals[2]);
+ memory_submit ("wired", sysctl_vals[3]);
+ memory_submit ("active", sysctl_vals[4]);
+ memory_submit ("inactive", sysctl_vals[5]);
+ memory_submit ("cache", sysctl_vals[6]);
+/* #endif HAVE_SYSCTLBYNAME */
+
+#elif KERNEL_LINUX