X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/b57167a10dcdf5c36f21f058e2aecf277aff54bc..1c46ea617272124eae806cd59532ae86822eaf4f:/upsgraph.pl diff --git a/upsgraph.pl b/upsgraph.pl index 10f622b..0d19fb6 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -11,6 +11,7 @@ if ((@ARGV != 1) && (@ARGV != 2)) { use Net::SNMP; use IO::Socket::INET; +use IO::Select; use RRDs; use File::Copy; use Data::Dumper; @@ -124,7 +125,13 @@ sub fetch_tcp(@) { return undef if (!$sock); - chomp(my $value = <$sock>); + my $select = IO::Select->new($sock); + + my $value = undef; + + if ($select->can_read(1)) { + chomp($value) if (sysread($sock, $value, 4096) > 0); + } close($sock); @@ -150,11 +157,19 @@ sub fetch_tcp_multi(@) { return undef if (!$sock); - while(<$sock>) { - chomp; - (my $key, my $value) = split(/${delimiter}/, $_); - $value=~ s/\s//g; - $values{$key} = $value; + my $select = IO::Select->new($sock); + + while($select->can_read(1)) { + if (sysread($sock, my $buf, 16384) > 0) { + $buf=~s/\r//g; + foreach my $line (split(/\n/, $buf)) { + (my $key, my $value) = split(/${delimiter}/, $line); + $value=~ s/\s//g; + $values{$key} = $value; + } + } else { + last; + } } close($sock); @@ -428,7 +443,7 @@ while(1) { print HTML "
\n"; open (HTML2, ">${outdir}/${hostname}.${var}.html.new"); - print HTML2 '' . $vars->{$var}->{'name'} . ''; + print HTML2 '' . $vars->{$var}->{'name'} . ''; print HTML2 ''; push @graphdef, "VDEF:min=${var},MINIMUM"; @@ -458,7 +473,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; ($averages, $width, $height) = @@ -475,7 +490,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; ($averages, $width, $height) = @@ -492,7 +507,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; print HTML2 "\n"; close(HTML2);