From: David Marec Date: Mon, 8 May 2023 08:02:18 +0000 (+0200) Subject: fix duplicate name X-Git-Url: http://popeye.lapinbilly.eu/git/?a=commitdiff_plain;h=dde2d0bee304dda389110e4c7155ef71b7a889d7;p=vrac.git fix duplicate name --- diff --git a/vmstat.pl b/vmstat.pl index 79c395a..2898f91 100755 --- a/vmstat.pl +++ b/vmstat.pl @@ -22,16 +22,18 @@ my %dict; while (1) { print scalar localtime() . "\n"; - print "------------------------\n" ; + print "------------------------\n"; system("/usr/bin/vmstat -z --libxo xml >$filename"); my $doc = XML::LibXML->load_xml(location => $filename); + my $c = 0; 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; + $name = $name . "_$c"; + $c++; } if (exists $dict{$name}) { diff --git a/vmstatm.pl b/vmstatm.pl index 005b4a9..edeabdf 100755 --- a/vmstatm.pl +++ b/vmstatm.pl @@ -3,18 +3,23 @@ # requires textproc/p5-XML-LibXML # use warnings; +use strict; use XML::LibXML; my $filename = 'vmstatm.xml'; - my %dict; -my $offset = 10; + +my ($offset) = @ARGV; + +if (not defined $offset) { + $offset = 10; +} while (1) { print scalar localtime() . "\n"; system("/usr/bin/vmstat -m --libxo xml >$filename"); - $doc = XML::LibXML->load_xml(location => $filename); + my $doc = XML::LibXML->load_xml(location => $filename); foreach my $id ( $doc->findnodes('//memory')) { my $name=$id->findvalue('type'); my $used=$id->findvalue('memory-use'); @@ -22,7 +27,12 @@ while (1) { my $v0=$dict{$name} + $offset; if ($v0 < $used) { - print "$name: $v0 => $used \n"; +format DIFF_V0V1 = + @<<<<<<<<<<<<<<<<<<<<<< @######## => @######## + $name,$v0,$used +. + $~ = "DIFF_V0V1"; + write; $dict{$name}=$used; } } else {