]> granicus.if.org Git - sysstat/commitdiff
Close #133: sar: Provide available free memory
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 11 Nov 2016 14:09:46 +0000 (15:09 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 11 Nov 2016 14:09:46 +0000 (15:09 +0100)
This patch adds a new metric to sar: Available free memory.
It can be displayed with "sar -r ALL".

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
pr_stats.c
rd_stats.c
rd_stats.h

index c0f5cea71ea718a0571437a90c5cba4fde33e1b2..6208a23a8c530933216bd14d5f09b8a68f2fe9de 100644 (file)
@@ -302,7 +302,7 @@ struct activity memory_act = {
 #endif
 #if defined(SOURCE_SAR) || defined(SOURCE_SADF)
        .hdr_line       = "frmpg/s;bufpg/s;campg/s|"
-                         "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact;kbdirty&kbanonpg;kbslab;kbkstack;kbpgtbl;kbvmused|"
+                         "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact;kbdirty&kbanonpg;kbslab;kbkstack;kbpgtbl;kbvmused;kbavail|"
                          "kbswpfree;kbswpused;%swpused;kbswpcad;%swpcad",
 #endif
 #ifdef SOURCE_SADF
index d8685205711987042f5a23ab6b5a22dd22be56a4..94e46caae07a1f98a941ce759838ba44034fa565 100644 (file)
@@ -477,18 +477,19 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                *smc = (struct stats_memory *) a->buf[curr],
                *smp = (struct stats_memory *) a->buf[prev];
        static unsigned long long
-               avg_frmkb    = 0,
-               avg_bufkb    = 0,
-               avg_camkb    = 0,
-               avg_comkb    = 0,
-               avg_activekb = 0,
-               avg_inactkb  = 0,
-               avg_dirtykb  = 0,
-               avg_anonpgkb = 0,
-               avg_slabkb   = 0,
-               avg_kstackkb = 0,
-               avg_pgtblkb  = 0,
-               avg_vmusedkb = 0;
+               avg_frmkb       = 0,
+               avg_bufkb       = 0,
+               avg_camkb       = 0,
+               avg_comkb       = 0,
+               avg_activekb    = 0,
+               avg_inactkb     = 0,
+               avg_dirtykb     = 0,
+               avg_anonpgkb    = 0,
+               avg_slabkb      = 0,
+               avg_kstackkb    = 0,
+               avg_pgtblkb     = 0,
+               avg_vmusedkb    = 0,
+               avg_availablekb = 0;
        static unsigned long long
                avg_frskb = 0,
                avg_tlskb = 0,
@@ -537,12 +538,13 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
 
                        if (DISPLAY_MEM_ALL(a->opt_flags)) {
                                /* Display extended memory statistics */
-                               cprintf_u64(5, 9,
+                               cprintf_u64(6, 9,
                                            (unsigned long long) smc->anonpgkb,
                                            (unsigned long long) smc->slabkb,
                                            (unsigned long long) smc->kstackkb,
                                            (unsigned long long) smc->pgtblkb,
-                                           (unsigned long long) smc->vmusedkb);
+                                           (unsigned long long) smc->vmusedkb,
+                                           (unsigned long long) smc->availablekb);
                        }
 
                        printf("\n");
@@ -552,18 +554,19 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                         * We assume that the total amount of memory installed can not vary
                         * during the interval given on the command line.
                         */
-                       avg_frmkb    += smc->frmkb;
-                       avg_bufkb    += smc->bufkb;
-                       avg_camkb    += smc->camkb;
-                       avg_comkb    += smc->comkb;
-                       avg_activekb += smc->activekb;
-                       avg_inactkb  += smc->inactkb;
-                       avg_dirtykb  += smc->dirtykb;
-                       avg_anonpgkb += smc->anonpgkb;
-                       avg_slabkb   += smc->slabkb;
-                       avg_kstackkb += smc->kstackkb;
-                       avg_pgtblkb  += smc->pgtblkb;
-                       avg_vmusedkb += smc->vmusedkb;
+                       avg_frmkb       += smc->frmkb;
+                       avg_bufkb       += smc->bufkb;
+                       avg_camkb       += smc->camkb;
+                       avg_comkb       += smc->comkb;
+                       avg_activekb    += smc->activekb;
+                       avg_inactkb     += smc->inactkb;
+                       avg_dirtykb     += smc->dirtykb;
+                       avg_anonpgkb    += smc->anonpgkb;
+                       avg_slabkb      += smc->slabkb;
+                       avg_kstackkb    += smc->kstackkb;
+                       avg_pgtblkb     += smc->pgtblkb;
+                       avg_vmusedkb    += smc->vmusedkb;
+                       avg_availablekb += smc->availablekb;
                }
                else {
                        /* Display average values */
@@ -589,12 +592,13 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                                  (double) avg_dirtykb / avg_count);
 
                        if (DISPLAY_MEM_ALL(a->opt_flags)) {
-                               cprintf_f(5, 9, 0,
+                               cprintf_f(6, 9, 0,
                                          (double) avg_anonpgkb / avg_count,
                                          (double) avg_slabkb / avg_count,
                                          (double) avg_kstackkb / avg_count,
                                          (double) avg_pgtblkb / avg_count,
-                                         (double) avg_vmusedkb / avg_count);
+                                         (double) avg_vmusedkb / avg_count,
+                                         (double) avg_availablekb / avg_count);
                        }
 
                        printf("\n");
@@ -603,7 +607,7 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                        avg_frmkb = avg_bufkb = avg_camkb = avg_comkb = 0;
                        avg_activekb = avg_inactkb = avg_dirtykb = 0;
                        avg_anonpgkb = avg_slabkb = avg_kstackkb = 0;
-                       avg_pgtblkb = avg_vmusedkb = 0;
+                       avg_pgtblkb = avg_vmusedkb = avg_availablekb = 0;
                }
        }
 
index 42188eb2637ce131e8d3217b553cbf141d62c49a..34c4ade3e59331ff938fb14163342d7ea5e9fbba 100644 (file)
@@ -232,6 +232,10 @@ void read_meminfo(struct stats_memory *st_memory)
                        /* Read the amount of free memory in kB */
                        sscanf(line + 8, "%lu", &st_memory->frmkb);
                }
+               else if (!strncmp(line, "MemAvailable:", 13)) {
+                       /* Read the amount of available memory in kB */
+                       sscanf(line + 13, "%lu", &st_memory->availablekb);
+               }
                else if (!strncmp(line, "Buffers:", 8)) {
                        /* Read the amount of buffered memory in kB */
                        sscanf(line + 8, "%lu", &st_memory->bufkb);
index c617fa752e40241d5408d2e1743f9716dabc039d..9abd3c1dbde2d0abb01f470aec852a64a70baf67 100644 (file)
@@ -163,22 +163,23 @@ struct stats_io {
 
 /* Structure for memory and swap space utilization statistics */
 struct stats_memory {
-       unsigned long frmkb     __attribute__ ((aligned (8)));
-       unsigned long bufkb     __attribute__ ((aligned (8)));
-       unsigned long camkb     __attribute__ ((aligned (8)));
-       unsigned long tlmkb     __attribute__ ((aligned (8)));
-       unsigned long frskb     __attribute__ ((aligned (8)));
-       unsigned long tlskb     __attribute__ ((aligned (8)));
-       unsigned long caskb     __attribute__ ((aligned (8)));
-       unsigned long comkb     __attribute__ ((aligned (8)));
-       unsigned long activekb  __attribute__ ((aligned (8)));
-       unsigned long inactkb   __attribute__ ((aligned (8)));
-       unsigned long dirtykb   __attribute__ ((aligned (8)));
-       unsigned long anonpgkb  __attribute__ ((aligned (8)));
-       unsigned long slabkb    __attribute__ ((aligned (8)));
-       unsigned long kstackkb  __attribute__ ((aligned (8)));
-       unsigned long pgtblkb   __attribute__ ((aligned (8)));
-       unsigned long vmusedkb  __attribute__ ((aligned (8)));
+       unsigned long frmkb             __attribute__ ((aligned (8)));
+       unsigned long bufkb             __attribute__ ((aligned (8)));
+       unsigned long camkb             __attribute__ ((aligned (8)));
+       unsigned long tlmkb             __attribute__ ((aligned (8)));
+       unsigned long frskb             __attribute__ ((aligned (8)));
+       unsigned long tlskb             __attribute__ ((aligned (8)));
+       unsigned long caskb             __attribute__ ((aligned (8)));
+       unsigned long comkb             __attribute__ ((aligned (8)));
+       unsigned long activekb          __attribute__ ((aligned (8)));
+       unsigned long inactkb           __attribute__ ((aligned (8)));
+       unsigned long dirtykb           __attribute__ ((aligned (8)));
+       unsigned long anonpgkb          __attribute__ ((aligned (8)));
+       unsigned long slabkb            __attribute__ ((aligned (8)));
+       unsigned long kstackkb          __attribute__ ((aligned (8)));
+       unsigned long pgtblkb           __attribute__ ((aligned (8)));
+       unsigned long vmusedkb          __attribute__ ((aligned (8)));
+       unsigned long availablekb       __attribute__ ((aligned (8)));
 };
 
 #define STATS_MEMORY_SIZE      (sizeof(struct stats_memory))