Format vmstat output
authorDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 10:46:59 +0000 (12:46 +0200)
committerDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 10:46:59 +0000 (12:46 +0200)
vmstat.pl

index 6b92c25ea876b2fecfa773333d64f6e874dac1c2..9e7f436614d3d97390ae7c5de633ae2882e57057 100755 (executable)
--- a/vmstat.pl
+++ b/vmstat.pl
@@ -3,6 +3,7 @@
 # requires textproc/p5-XML-LibXML
 #
 use warnings;
+use strict;
 
 use XML::LibXML;
 
@@ -12,13 +13,16 @@ my $filename = 'vmstat.xml';
 my %dict;
 my $offset = 10;
 
+
 while (1) {
        print scalar localtime() . "\n";
+       print "------------------------\n" ;
        system("/usr/bin/vmstat -z --libxo xml >$filename"); 
-       $doc = XML::LibXML->load_xml(location => $filename); 
-       foreach my $id ( $doc->findnodes('//zone')) {
+       my $doc = XML::LibXML->load_xml(location => $filename); 
+       foreach my $id ($doc->findnodes('//zone')) {
                my $name=$id->findvalue('name');
                my $used=$id->findvalue('used');
+               my $val = int($used);
 
                if ($name eq "vm pgcache") {
                        next;
@@ -27,16 +31,23 @@ while (1) {
                if (exists $dict{$name}) {
                        my $v0=$dict{$name} + $offset;
 
-                       if ($v0 < int($used)) {
-                               print "$name: $v0 => $used \n";
-                               $dict{$name}=int(${used});
+                       if ($v0 < $val) {
+format DIFF_V0V1 =
+       @<<<<<<<<<<<<<<<<<<<<<< @######## => @########
+       $name,$v0,$val
+.
+                               $~ = "DIFF_V0V1";
+                               write;
+                               $dict{$name} = $val;
                        }
                } else {
-                       $dict{$name}=int(${used});
+                       $dict{$name} = $val;
                }
        }
-       print "------------------------\n" ;
+
+       print "\n";
 
        sleep(5);
 }
 
+