From 100eef73b68e12eee1a92644282b8f2924833761 Mon Sep 17 00:00:00 2001 From: David Marec Date: Sun, 7 May 2023 12:46:59 +0200 Subject: [PATCH] Format vmstat output --- vmstat.pl | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/vmstat.pl b/vmstat.pl index 6b92c25..9e7f436 100755 --- 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); } + -- 2.47.0