File collectd-memory-plugin-Add-slab-memory-stats-linux.patch of Package collectd

From 002fec64b13f6618d5588d0590998a4b3b82bc57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20CISS=C3=89?= <manuel_cisse@yahoo.fr>
Date: Thu, 20 Feb 2014 16:06:56 +0100
Subject: [PATCH] memory plugin: Add slab memory stats (linux)

Pull-Request: #560
---
 src/memory.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Index: collectd-5.4.1/src/memory.c
===================================================================
--- collectd-5.4.1.orig/src/memory.c
+++ collectd-5.4.1/src/memory.c
@@ -271,6 +271,8 @@ static int memory_read (void)
 	long long mem_buffered = 0;
 	long long mem_cached = 0;
 	long long mem_free = 0;
+	long long mem_slab_reclaimable = 0;
+	long long mem_slab_unreclaimable = 0;
 
 	if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
 	{
@@ -292,6 +294,10 @@ static int memory_read (void)
 			val = &mem_buffered;
 		else if (strncasecmp (buffer, "Cached:", 7) == 0)
 			val = &mem_cached;
+		else if (strncasecmp (buffer, "SReclaimable:", 13) == 0)
+			val = &mem_slab_reclaimable;
+		else if (strncasecmp (buffer, "SUnreclaim:", 11) == 0)
+			val = &mem_slab_unreclaimable;
 		else
 			continue;
 
@@ -310,13 +316,15 @@ static int memory_read (void)
 				sstrerror (errno, errbuf, sizeof (errbuf)));
 	}
 
-	if (mem_used >= (mem_free + mem_buffered + mem_cached))
+	if (mem_used >= (mem_free + mem_buffered + mem_cached + mem_slab_unreclaimable + mem_slab_reclaimable))
 	{
-		mem_used -= mem_free + mem_buffered + mem_cached;
+		mem_used -= mem_free + mem_buffered + mem_cached + mem_slab_unreclaimable + mem_slab_reclaimable;
 		memory_submit ("used",     mem_used);
 		memory_submit ("buffered", mem_buffered);
 		memory_submit ("cached",   mem_cached);
 		memory_submit ("free",     mem_free);
+		memory_submit ("slab_unrecl", mem_slab_unreclaimable);
+		memory_submit ("slab_recl",   mem_slab_reclaimable);
 	}
 /* #endif KERNEL_LINUX */
openSUSE Build Service is sponsored by