Add Perl script to check vmstat diff
authorDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 08:18:50 +0000 (10:18 +0200)
committerDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 08:18:50 +0000 (10:18 +0200)
vmstat.pl [new file with mode: 0755]

diff --git a/vmstat.pl b/vmstat.pl
new file mode 100755 (executable)
index 0000000..6b92c25
--- /dev/null
+++ b/vmstat.pl
@@ -0,0 +1,42 @@
+#!/usr/local/bin/perl
+#
+# requires textproc/p5-XML-LibXML
+#
+use warnings;
+
+use XML::LibXML;
+
+my $filename = 'vmstat.xml';
+
+
+my %dict;
+my $offset = 10;
+
+while (1) {
+       print scalar localtime() . "\n";
+       system("/usr/bin/vmstat -z --libxo xml >$filename"); 
+       $doc = XML::LibXML->load_xml(location => $filename); 
+       foreach my $id ( $doc->findnodes('//zone')) {
+               my $name=$id->findvalue('name');
+               my $used=$id->findvalue('used');
+
+               if ($name eq "vm pgcache") {
+                       next;
+               }
+               
+               if (exists $dict{$name}) {
+                       my $v0=$dict{$name} + $offset;
+
+                       if ($v0 < int($used)) {
+                               print "$name: $v0 => $used \n";
+                               $dict{$name}=int(${used});
+                       }
+               } else {
+                       $dict{$name}=int(${used});
+               }
+       }
+       print "------------------------\n" ;
+
+       sleep(5);
+}
+