Perl script to check vmstat -m diffs
authorDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 09:09:00 +0000 (11:09 +0200)
committerDavid Marec <DavidMarec@users.noreply.github.com>
Sun, 7 May 2023 09:09:00 +0000 (11:09 +0200)
vmstatm.pl [new file with mode: 0755]

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