[! use strict; use HTML::Entities; use Proxmox::Utils; use MIME::Base64; use GD::Graph::lines; use Proxmox::Config::System; !] [- $fdat{__sarsel} = [['inbyts', 'In bytes/second'], ['otbyts', 'Out bytes/second'], ]; Execute ('date_selection.epl'); -]
[- if (!$fdat{sarfile}) { print OUT __("No data available."); return; } my $dir = '/var/www/proxmox/statistic/perf/'; my $system_cfg = $fdat{__system_config}; my $iface = $system_cfg->{local}->{int_iface}; $iface =~ s/\:\d+$//; my $out = ""; my ($data0, $data1); open (TMP, "atsar -f $fdat{sarfile} -l -S|"); my $max = 0; my $sel = $fdat{sarsel} || $fdat{__sarsel}[0][0]; my $intvalue = 1; my $found; while (my $line = ) { my $res = {}; my ($hour, $min); if (($hour, $min, $res->{'inbyts'}, $res->{'otbyts'}) = ($line =~ m/^(\d\d)\:(\d\d)\:\d\d\s+\d+\.\d+\s+\d+\.\d+\s+(\d+)\s+(\d+).*$iface\s*/)) { $found = 1; push @$data0, $hour; # hack: +0 to convert string to number (avoid problems with GD::GRAPH) my $v = $res->{"$sel"} + 0; push @$data1, $v; $intvalue = 0 if int ($v) != $v; $max = $v if $v && $max < $v; } } close (TMP); if (!$found) { print OUT __("No data available."); return; } $max = 1 if !$max; my @data = ($data0, $data1); my $graph = GD::Graph::lines->new (600, 400); my $txt = ''; foreach my $va (@{$fdat{__sarsel}}) { $txt = $va->[1] if $fdat{sarsel} eq $va->[0]; } my $prec = $max < 1 ? 100 : 10; my $rmax = int (($max * 1.1 + (1/$prec)) * $prec) / $prec; $graph->set( title => sprintf (decode_entities (("$txt (%s)")), $fdat{sardate}) , transparent => 0, y_long_ticks => 1, dclrs => [ qw(green lblue cyan lyellow lpurple lred lorange) ], y_min_value => 0, y_max_value => $rmax, y_number_format => '%.2f', x_labels_vertical => 1, x_label_skip => 6, ); if ($intvalue) { my $maxv = int ($max * 1.1); my $ytn = $max < 5 ? $max : 5; $graph->set(y_number_format => '%d', y_min_value => 0, y_max_value => $maxv, y_tick_number => $ytn); } $graph->set_legend(decode_entities ($sel)); $graph->plot(\@data); $out .= "

"; my $fn = 'cpuload.png'; open (TMP, ">$dir$fn") or die "Cannot open $fn for write: $!"; print TMP $graph->gd->png(); close TMP; $out .= "

"; print OUT $out; -]