Skip to content

Commit

Permalink
fixed the update() function to support newer versions of Tinyproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaku committed Jul 8, 2024
1 parent a9c042d commit 1dc94fb
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions lib/tinyproxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,57 +175,41 @@ sub tinyproxy_update {

#print $data->toStringHTML();

my $xpath = '//tr//td';
my @stats;

# This 'foreach' emulates the method 'to_literal_list' as it was
# introduced in Perl-XML-LibXML version 2.0105 (2013-09-07), and
# unfortunately not all systems have such a recent version.
#
# Some day in the future it should be changed by the line:
# push(@stats, $_) foreach $data->findnodes($xpath)->to_literal_list;
foreach($data->findnodes($xpath)->get_nodelist()) {
my $node;
($node = $_) =~ s@</?td>@@g;
push(@stats, $node);
}
my %hstats = @stats;

for my $key (keys %hstats) {
if($key eq "Number of open connections") {
foreach(split('\n', $data->toStringHTML())) {
if(/^Number of open connections:\s+(\d+)/) {
$str = $e . "open";
$ocon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
$ocon = 0 unless $ocon != $hstats{$key};
$ocon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
$ocon = 0 unless $ocon != $1;
$ocon /= 60;
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
$config->{tinyproxy_hist}->{$str} = $1;
}
if($key eq "Number of requests") {
if(/Number of requests:\s+(\d+)/) {
$str = $e . "reqs";
$reqs = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
$reqs = 0 unless $reqs != $hstats{$key};
$reqs = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
$reqs = 0 unless $reqs != $1;
$reqs /= 60;
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
$config->{tinyproxy_hist}->{$str} = $1;
}
if($key eq "Number of bad connections") {
if(/Number of bad connections:\s+(\d+)/) {
$str = $e . "bcon";
$bcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
$bcon = 0 unless $bcon != $hstats{$key};
$bcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
$bcon = 0 unless $bcon != $1;
$bcon /= 60;
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
$config->{tinyproxy_hist}->{$str} = $1;
}
if($key eq "Number of denied connections") {
if(/Number of denied connections:\s+(\d+)/) {
$str = $e . "dcon";
$dcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
$dcon = 0 unless $dcon != $hstats{$key};
$dcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
$dcon = 0 unless $dcon != $1;
$dcon /= 60;
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
$config->{tinyproxy_hist}->{$str} = $1;
}
if($key eq "Number of refused connections due to high load") {
if(/Number of refused connections due to high load:\s+(\d+)/) {
$str = $e . "rcon";
$rcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
$rcon = 0 unless $rcon != $hstats{$key};
$rcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
$rcon = 0 unless $rcon != $1;
$rcon /= 60;
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
$config->{tinyproxy_hist}->{$str} = $1;
}
}

Expand Down

0 comments on commit 1dc94fb

Please sign in to comment.