- FILE *fh;
- char buffer[1024];
-
- char *fields[8];
- int numfields;
-
- _Bool detailed_slab_info = 0;
-
- gauge_t mem_total = 0;
- gauge_t mem_used = 0;
- gauge_t mem_buffered = 0;
- gauge_t mem_cached = 0;
- gauge_t mem_free = 0;
- gauge_t mem_slab_total = 0;
- gauge_t mem_slab_reclaimable = 0;
- gauge_t mem_slab_unreclaimable = 0;
-
- if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
- {
- char errbuf[1024];
- WARNING ("memory: fopen: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
- }
-
- while (fgets (buffer, sizeof (buffer), fh) != NULL)
- {
- gauge_t *val = NULL;
-
- if (strncasecmp (buffer, "MemTotal:", 9) == 0)
- val = &mem_total;
- else if (strncasecmp (buffer, "MemFree:", 8) == 0)
- val = &mem_free;
- else if (strncasecmp (buffer, "Buffers:", 8) == 0)
- val = &mem_buffered;
- else if (strncasecmp (buffer, "Cached:", 7) == 0)
- val = &mem_cached;
- else if (strncasecmp (buffer, "Slab:", 5) == 0)
- val = &mem_slab_total;
- else if (strncasecmp (buffer, "SReclaimable:", 13) == 0) {
- val = &mem_slab_reclaimable;
- detailed_slab_info = 1;
- }
- else if (strncasecmp (buffer, "SUnreclaim:", 11) == 0) {
- val = &mem_slab_unreclaimable;
- detailed_slab_info = 1;
- }
- else
- continue;
-
- numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
- if (numfields < 2)
- continue;
-
- *val = 1024.0 * atof (fields[1]);
- }
-
- if (fclose (fh))
- {
- char errbuf[1024];
- WARNING ("memory: fclose: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- }
-
- if (mem_total < (mem_free + mem_buffered + mem_cached + mem_slab_total))
- return (-1);
-
- mem_used = mem_total - (mem_free + mem_buffered + mem_cached + mem_slab_total);
-
- /* SReclaimable and SUnreclaim were introduced in kernel 2.6.19
- * They sum up to the value of Slab, which is available on older & newer
- * kernels. So SReclaimable/SUnreclaim are submitted if available, and Slab
- * if not. */
- if (detailed_slab_info)
- MEMORY_SUBMIT ("used", mem_used,
- "buffered", mem_buffered,
- "cached", mem_cached,
- "free", mem_free,
- "slab_unrecl", mem_slab_unreclaimable,
- "slab_recl", mem_slab_reclaimable);
- else
- MEMORY_SUBMIT ("used", mem_used,
- "buffered", mem_buffered,
- "cached", mem_cached,
- "free", mem_free,
- "slab", mem_slab_total);
+ FILE *fh;
+ char buffer[1024];
+
+ char *fields[8];
+ int numfields;
+
+ _Bool detailed_slab_info = 0;
+
+ gauge_t mem_total = 0;
+ gauge_t mem_used = 0;
+ gauge_t mem_buffered = 0;
+ gauge_t mem_cached = 0;
+ gauge_t mem_free = 0;
+ gauge_t mem_slab_total = 0;
+ gauge_t mem_slab_reclaimable = 0;
+ gauge_t mem_slab_unreclaimable = 0;
+
+ if ((fh = fopen("/proc/meminfo", "r")) == NULL) {
+ char errbuf[1024];
+ WARNING("memory: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ return (-1);
+ }
+
+ while (fgets(buffer, sizeof(buffer), fh) != NULL) {
+ gauge_t *val = NULL;
+
+ if (strncasecmp(buffer, "MemTotal:", 9) == 0)
+ val = &mem_total;
+ else if (strncasecmp(buffer, "MemFree:", 8) == 0)
+ val = &mem_free;
+ else if (strncasecmp(buffer, "Buffers:", 8) == 0)
+ val = &mem_buffered;
+ else if (strncasecmp(buffer, "Cached:", 7) == 0)
+ val = &mem_cached;
+ else if (strncasecmp(buffer, "Slab:", 5) == 0)
+ val = &mem_slab_total;
+ else if (strncasecmp(buffer, "SReclaimable:", 13) == 0) {
+ val = &mem_slab_reclaimable;
+ detailed_slab_info = 1;
+ } else if (strncasecmp(buffer, "SUnreclaim:", 11) == 0) {
+ val = &mem_slab_unreclaimable;
+ detailed_slab_info = 1;
+ } else
+ continue;
+
+ numfields = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields));
+ if (numfields < 2)
+ continue;
+
+ *val = 1024.0 * atof(fields[1]);
+ }
+
+ if (fclose(fh)) {
+ char errbuf[1024];
+ WARNING("memory: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ }
+
+ if (mem_total < (mem_free + mem_buffered + mem_cached + mem_slab_total))
+ return (-1);
+
+ mem_used =
+ mem_total - (mem_free + mem_buffered + mem_cached + mem_slab_total);
+
+ /* SReclaimable and SUnreclaim were introduced in kernel 2.6.19
+ * They sum up to the value of Slab, which is available on older & newer
+ * kernels. So SReclaimable/SUnreclaim are submitted if available, and Slab
+ * if not. */
+ if (detailed_slab_info)
+ MEMORY_SUBMIT("used", mem_used, "buffered", mem_buffered, "cached",
+ mem_cached, "free", mem_free, "slab_unrecl",
+ mem_slab_unreclaimable, "slab_recl", mem_slab_reclaimable);
+ else
+ MEMORY_SUBMIT("used", mem_used, "buffered", mem_buffered, "cached",
+ mem_cached, "free", mem_free, "slab", mem_slab_total);