Skip to content

Commit 1dc94fb

Browse files
committed
fixed the update() function to support newer versions of Tinyproxy
1 parent a9c042d commit 1dc94fb

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

lib/tinyproxy.pm

+21-37
Original file line numberDiff line numberDiff line change
@@ -175,57 +175,41 @@ sub tinyproxy_update {
175175

176176
#print $data->toStringHTML();
177177

178-
my $xpath = '//tr//td';
179-
my @stats;
180-
181-
# This 'foreach' emulates the method 'to_literal_list' as it was
182-
# introduced in Perl-XML-LibXML version 2.0105 (2013-09-07), and
183-
# unfortunately not all systems have such a recent version.
184-
#
185-
# Some day in the future it should be changed by the line:
186-
# push(@stats, $_) foreach $data->findnodes($xpath)->to_literal_list;
187-
foreach($data->findnodes($xpath)->get_nodelist()) {
188-
my $node;
189-
($node = $_) =~ s@</?td>@@g;
190-
push(@stats, $node);
191-
}
192-
my %hstats = @stats;
193-
194-
for my $key (keys %hstats) {
195-
if($key eq "Number of open connections") {
178+
foreach(split('\n', $data->toStringHTML())) {
179+
if(/^Number of open connections:\s+(\d+)/) {
196180
$str = $e . "open";
197-
$ocon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
198-
$ocon = 0 unless $ocon != $hstats{$key};
181+
$ocon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
182+
$ocon = 0 unless $ocon != $1;
199183
$ocon /= 60;
200-
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
184+
$config->{tinyproxy_hist}->{$str} = $1;
201185
}
202-
if($key eq "Number of requests") {
186+
if(/Number of requests:\s+(\d+)/) {
203187
$str = $e . "reqs";
204-
$reqs = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
205-
$reqs = 0 unless $reqs != $hstats{$key};
188+
$reqs = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
189+
$reqs = 0 unless $reqs != $1;
206190
$reqs /= 60;
207-
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
191+
$config->{tinyproxy_hist}->{$str} = $1;
208192
}
209-
if($key eq "Number of bad connections") {
193+
if(/Number of bad connections:\s+(\d+)/) {
210194
$str = $e . "bcon";
211-
$bcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
212-
$bcon = 0 unless $bcon != $hstats{$key};
195+
$bcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
196+
$bcon = 0 unless $bcon != $1;
213197
$bcon /= 60;
214-
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
198+
$config->{tinyproxy_hist}->{$str} = $1;
215199
}
216-
if($key eq "Number of denied connections") {
200+
if(/Number of denied connections:\s+(\d+)/) {
217201
$str = $e . "dcon";
218-
$dcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
219-
$dcon = 0 unless $dcon != $hstats{$key};
202+
$dcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
203+
$dcon = 0 unless $dcon != $1;
220204
$dcon /= 60;
221-
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
205+
$config->{tinyproxy_hist}->{$str} = $1;
222206
}
223-
if($key eq "Number of refused connections due to high load") {
207+
if(/Number of refused connections due to high load:\s+(\d+)/) {
224208
$str = $e . "rcon";
225-
$rcon = $hstats{$key} - ($config->{tinyproxy_hist}->{$str} || 0);
226-
$rcon = 0 unless $rcon != $hstats{$key};
209+
$rcon = $1 - ($config->{tinyproxy_hist}->{$str} || 0);
210+
$rcon = 0 unless $rcon != $1;
227211
$rcon /= 60;
228-
$config->{tinyproxy_hist}->{$str} = $hstats{$key};
212+
$config->{tinyproxy_hist}->{$str} = $1;
229213
}
230214
}
231215

0 commit comments

Comments
 (0)