From b664f9839df3b3c9f342de9ee0b7ba097bc1cba9 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Wed, 14 Aug 2024 19:51:24 +0800
Subject: [PATCH] Fix for meminfo on 32-bit darwin

---
 .../in_node_exporter_metrics/ne_meminfo_darwin.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git plugins/in_node_exporter_metrics/ne_meminfo_darwin.c plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
index 23d4a34bd..822846fbb 100644
--- plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
+++ plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
@@ -32,6 +32,8 @@
 #include <mach/mach_init.h>
 #include <mach/mach_host.h>
 
+#include <AvailabilityMacros.h>
+
 static int meminfo_configure(struct flb_ne *ctx)
 {
     struct cmt_counter *c;
@@ -140,7 +142,11 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
 {
     mach_port_t host_port;
     mach_msg_type_number_t host_size;
+#if defined(__i386__) || defined(__ppc__)
+    vm_statistics_data_t vm_stat;
+#else
     vm_statistics64_data_t vm_stat;
+#endif
     kern_return_t err;
     vm_size_t page_size;
     struct xsw_usage swap;
@@ -152,7 +158,11 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
     host_port = mach_host_self();
     host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
 
+#if defined(__i386__) || defined(__ppc__)
+    err = host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
+#else
     err = host_statistics64(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
+#endif
 
     if (err != KERN_SUCCESS) {
         flb_plg_error(ctx->ins, "host_statistics() is failed with error = %d", err);
@@ -177,8 +187,10 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
     cmt_gauge_set(ctx->darwin_free_bytes, ts,
                   ps * vm_stat.free_count, 0, NULL);
 
+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
     cmt_gauge_set(ctx->darwin_compressed_bytes, ts,
                   ps * vm_stat.compressor_page_count, 0, NULL);
+#endif
 
     cmt_gauge_set(ctx->darwin_active_bytes, ts,
                   ps * vm_stat.active_count, 0, NULL);
@@ -186,14 +198,18 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
     cmt_gauge_set(ctx->darwin_inactive_bytes, ts,
                   ps * vm_stat.inactive_count, 0, NULL);
 
+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
     cmt_gauge_set(ctx->darwin_internal_bytes, ts,
                   ps * vm_stat.internal_page_count, 0, NULL);
+#endif
 
     cmt_gauge_set(ctx->darwin_wired_bytes, ts,
                   ps * vm_stat.wire_count, 0, NULL);
 
+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
     cmt_gauge_set(ctx->darwin_purgeable_bytes, ts,
                   ps * vm_stat.purgeable_count, 0, NULL);
+#endif
 
     cmt_counter_set(ctx->darwin_pageins_bytes, ts,
                     ps * vm_stat.pageins, 0, NULL);
-- 
2.46.0

