From c3bd57b4f6dd4f501ca29f22f33a513d9b94cffc Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Thu, 3 May 2012 20:14:40 +0200 Subject: [PATCH] Replace GD::Graph by the Flotr2 javascript library to draw graphics - Guillaume Lelarge --- pgbadger | 659 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 394 insertions(+), 265 deletions(-) diff --git a/pgbadger b/pgbadger index d26f383..94bf13a 100755 --- a/pgbadger +++ b/pgbadger @@ -26,12 +26,14 @@ use IO::File; use Benchmark; use IO::File; use File::Basename; +use Time::Local 'timelocal_nocheck'; $| = 1; # Global variables overriden during install my $ZCAT_PROG = '/bin/zcat'; my $VERSION = '0.1'; +my $JQGRAPH = 1; # Command line options my $logfile = ''; @@ -57,6 +59,8 @@ my $regex_prefix_dbuser = ''; my $quiet = 0; my $progress = 0; my $NUMPROGRESS = 10000; +my @DIMENSIONS = (1000,400); +my $RESRC_URL = ''; my $t0 = Benchmark->new; @@ -394,7 +398,7 @@ Usage: $0 -l logfile [...] -x | --extension : output format. Values: text or html. Default: html -m | --maxlength size : maximum length of a query, it will be cutted above the given size. Default: no truncate - -g | --graph : generate graphs, requires GD::Graph perl module + -g | --graph : generate graphs using the Flotr2 javascript library -b | --begin datetime : start date/time for the data to be parsed in log. -e | --end datetime : end date/time for the data to be parsed in log. -q | --quiet : disable output to stderr and don't print debug informations. @@ -671,10 +675,15 @@ Report not supported by text format sub html_header { + my $date = localtime(time); print $fh qq{ PgBadger: PostgreSQL log analyzer + + + + +}; +if ($JQGRAPH) { + my @jslib = ; + print $fh <
@@ -1041,9 +1068,14 @@ sub dump_as_html my @data1 = (); my @data2 = (); my @data3 = (); + my $d1 = ''; + my $d2 = ''; + my $d3 = ''; foreach my $tm (sort {$a <=> $b} keys %{$per_minute_info{query}}) { $tm =~ /(\d{4})(\d{2})(\d{2})/; - my $prefix = "$1-$2-$3 "; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; foreach my $h ("00" .. "23") { my %dataavg = (); foreach my $m ("00" .. "59") { @@ -1059,112 +1091,168 @@ sub dump_as_html } } foreach my $rd ('00','05','10','15','20','25','30','35','40','45','50','55') { - push(@data2, int(($dataavg{average}{"$rd"} || 0) / 300)); + my $t = timelocal_nocheck(0,$rd,$h,$d,$mo,$y) * 1000; + # Average per 5 minutes + $d2 .= "[$t, " . int(($dataavg{average}{"$rd"} || 0) / 300) . "],"; # Maxi per minute - push(@data1, $dataavg{max}{"$rd"} || 0); + $d1 .= "[$t, " . ($dataavg{max}{"$rd"} || 0) . "],"; # Mini per minute - push(@data3, $dataavg{min}{"$rd"} || 0); - push(@labels, "$prefix $h:$rd"); + $d3 .= "[$t, " . ($dataavg{min}{"$rd"} || 0) . "],"; } } } delete $per_minute_info{query}; - map {s/^\d{4}-//; s/^\d{2}-\d{2} // if ($_ !~ /(00:00|12:00)/); } @labels; - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - push(@graph_values, [ @data2 ] ); @data2 = (); - push(@graph_values, [ @data3 ] ); @data3 = (); - &create_graph('queriespersecond', 'Queries per second (5 minutes average)', 'Hours', 'Queries per second', 'Maximum', 'Average', 'Minimum'); - @graph_values = (); - print $fh qq{

Queries per second

}; +# print $fh qq{ +# +# +# +#}; + $d1 =~ s/,$//; + $d2 =~ s/,$//; + $d3 =~ s/,$//; + &flotr2_graph(1, 'queriespersecond_graph', $d1, $d2, $d3, 'Queries per second (5 minutes average)', + 'Queries per second','Maximum','Average','Minimum'); + $d1 = ''; + $d2 = ''; + $d3 = ''; # All queries foreach my $tm (sort {$a <=> $b} keys %per_hour_info) { $tm =~ /(\d{4})(\d{2})(\d{2})/; - my $prefix = "$1-$2-$3 "; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; foreach my $h ("00" .. "23") { - push(@labels, "$prefix $h:00"); - push(@data1, $per_hour_info{$tm}{$h}{count} || 0); - push(@data2, sprintf("%.2f", (($per_hour_info{$tm}{$h}{duration} || 0) / ($per_hour_info{$tm}{$h}{count} || 1)) /1000)); - } - } - map {s/^\d{4}-//; s/^\d{2}-\d{2} // if ($_ !~ /(00:00|12:00)/); } @labels; - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - push(@graph_values, [ @data2 ] ); @data2 = (); - &create_graph_twoaxes('allqueries', 'All queries', 'Hours', 'Queries', 'Duration', 'Number of queries','Average duration (s)'); - print $fh qq{

All queries

}; - @graph_values = (); - - # checkpoint size - if (exists $checkpoint_info{chronos}) { - foreach my $tm (sort {$a <=> $b} keys %{$checkpoint_info{chronos}}) { - $tm =~ /(\d{4})(\d{2})(\d{2})/; - my $prefix = "$1-$2-$3 "; - foreach my $h ("00" .. "23") { - push(@labels, "$prefix $h:00"); - push(@data1, $checkpoint_info{chronos}{$tm}{$h}{wbuffer} || 0); - } + my $t = timelocal_nocheck(0,0,$h,$d,$mo,$y) * 1000; + $d1 .= "[$t, " . ($per_hour_info{$tm}{$h}{count} || 0) . "],"; + $d2 .= "[$t, " . sprintf("%.2f", (($per_hour_info{$tm}{$h}{duration} || 0) / ($per_hour_info{$tm}{$h}{count} || 1)) /1000) . "],"; } - map {s/^\d{4}-//; s/^\d{2}-\d{2} // if ($_ !~ /(00:00|12:00)/); } @labels; - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_twoaxes('checkpointbuffers', 'Checkpoint write buffers', 'Hours', 'Buffers'); - print $fh qq{

Checkpoint write buffers

}; - @graph_values = (); } +# print $fh qq{ +# +# +# +#}; + $d1 =~ s/,$//; + $d2 =~ s/,$//; + &flotr2_graph(2, 'allqueries_graph', $d1, '', '', 'All queries', + 'Queries','Number of queries','','','Duration',$d2,'Average duration (s)'); + $d1 = ''; + $d2 = ''; # Select queries foreach my $tm (sort {$a <=> $b} keys %per_hour_info) { $tm =~ /(\d{4})(\d{2})(\d{2})/; - my $prefix = "$1-$2-$3 "; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; foreach my $h ("00" .. "23") { - push(@labels, "$prefix $h:00"); - push(@data1, $per_hour_info{$tm}{$h}{'SELECT'}{count} || 0); - push(@data2, sprintf("%.2f", (($per_hour_info{$tm}{$h}{'SELECT'}{duration} || 0) / ($per_hour_info{$tm}{$h}{'SELECT'}{count} || 1)) /1000)); + my $t = timelocal_nocheck(0,0,$h,$d,$mo,$y) * 1000; + $d1 .= "[$t, " . ($per_hour_info{$tm}{$h}{'SELECT'}{count} || 0) . "],"; + $d2 .= "[$t, " . sprintf("%.2f", (($per_hour_info{$tm}{$h}{'SELECT'}{duration} || 0) / ($per_hour_info{$tm}{$h}{'SELECT'}{count} || 1)) /1000) . "],"; } } - map {s/^\d{4}-//; s/^\d{2}-\d{2} // if ($_ !~ /(00:00|12:00)/); } @labels; - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - push(@graph_values, [ @data2 ] ); @data2 = (); - &create_graph_twoaxes('selectqueries', 'SELECT queries', 'Hours', 'Queries', 'Duration', 'Number of queries','Average duration (s)'); - print $fh qq{

SELECT queries

}; - @graph_values = (); +# print $fh qq{ +# +# +# +#}; + $d1 =~ s/,$//; + $d2 =~ s/,$//; + &flotr2_graph(3, 'selectqueries_graph', $d1, '', '', 'SELECT queries', + 'Queries','Number of queries','','','Duration',$d2,'Average duration (s)'); + $d1 = ''; + $d2 = ''; # Write queries - my @data4 = (); + my $d4 = ''; foreach my $tm (sort {$a <=> $b} keys %per_hour_info) { $tm =~ /(\d{4})(\d{2})(\d{2})/; - my $prefix = "$1-$2-$3 "; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; foreach my $h ("00" .. "23") { - push(@labels, "$prefix $h:00"); + my $t = timelocal_nocheck(0,0,$h,$d,$mo,$y) * 1000; my $wcount = $per_hour_info{$tm}{$h}{'UPDATE'}{count} + $per_hour_info{$tm}{$h}{'DELETE'}{count} + $per_hour_info{$tm}{$h}{'INSERT'}{count}; my $wduration = $per_hour_info{$tm}{$h}{'UPDATE'}{duration} + $per_hour_info{$tm}{$h}{'DELETE'}{duration} + $per_hour_info{$tm}{$h}{'INSERT'}{duration}; - push(@data1, $per_hour_info{$tm}{$h}{'DELETE'}{count} || 0); - push(@data2, $per_hour_info{$tm}{$h}{'INSERT'}{count} || 0); - push(@data3, $per_hour_info{$tm}{$h}{'UPDATE'}{count} || 0); - push(@data4, sprintf("%.2f", (($wduration || 0) / ($wcount || 1)) /1000)); + $d1 .= "[$t, " . ($per_hour_info{$tm}{$h}{'DELETE'}{count} || 0) . "],"; + $d2 .= "[$t, " . ($per_hour_info{$tm}{$h}{'INSERT'}{count} || 0) . "],"; + $d3 .= "[$t, " . ($per_hour_info{$tm}{$h}{'UPDATE'}{count} || 0) . "],"; + $d4 .= "[$t, " . sprintf("%.2f", (($wduration || 0) / ($wcount || 1)) /1000) . "],"; } } - map {s/^\d{4}-//; s/^\d{2}-\d{2} // if ($_ !~ /(00:00|12:00)/); } @labels; - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - push(@graph_values, [ @data2 ] ); @data2 = (); - push(@graph_values, [ @data3 ] ); @data2 = (); - push(@graph_values, [ @data4 ] ); @data4 = (); - &create_graph_twoaxes('writequeries', 'Write queries', 'Hours', 'Queries', 'Duration', 'DELETE queries', 'INSERT queries', 'UPDATE queries', 'Average duration (s)'); - print $fh qq{

Write queries

}; - @graph_values = (); +# print $fh qq{ +# +# +# +#}; + $d1 =~ s/,$//; + $d2 =~ s/,$//; + $d3 =~ s/,$//; + $d4 =~ s/,$//; + &flotr2_graph(4, 'writequeries_graph', $d1, $d2, $d3, 'Write queries', + 'Queries','DELETE queries','INSERT queries','UPDATE queries','Duration',$d4,'Average duration (s)'); + $d1 = ''; + $d2 = ''; + $d3 = ''; + $d4 = ''; + # checkpoint size + if (exists $checkpoint_info{chronos}) { + foreach my $tm (sort {$a <=> $b} keys %{$checkpoint_info{chronos}}) { + $tm =~ /(\d{4})(\d{2})(\d{2})/; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; + foreach my $h ("00" .. "23") { + my $t = timelocal_nocheck(0,0,$h,$d,$mo,$y) * 1000; + $d1 .= "[$t, " . ($checkpoint_info{chronos}{$tm}{$h}{wbuffer} || 0) . "],"; + } + } +# print $fh qq{ +# +# +# +#}; + + $d1 =~ s/,$//; + &flotr2_graph(5, 'checkpointwritebuffers_graph', $d1, '', '', 'Checkpoint write buffers', + 'Buffers','Write buffers','',''); + $d1 = ''; + } + # Temporary file size + if (exists $tempfile_info{chronos}) { + foreach my $tm (sort {$a <=> $b} keys %{$tempfile_info{chronos}}) { + $tm =~ /(\d{4})(\d{2})(\d{2})/; + my $y = $1 - 1900; + my $mo = $2 - 1; + my $d = $3; + foreach my $h ("00" .. "23") { + my $t = timelocal_nocheck(0,0,$h,$d,$mo,$y) * 1000; + $d1 .= "[$t, " . ($tempfile_info{chronos}{$tm}{$h}{size} || 0) . "],"; + $d2 .= "[$t, " . ($tempfile_info{chronos}{$tm}{$h}{count} || 0) . "],"; + } + } +# print $fh qq{ +# +# +# +#}; + $d1 =~ s/,$//; + $d2 =~ s/,$//; + &flotr2_graph(6, 'temporaryfile_graph', $d1, '', '', 'Temporary files', + 'Size','Size of files','','','Number',$d2,'Number of files'); + $d1 = ''; + $d2 = ''; + } } # INSERT/DELETE/UPDATE/SELECT repartition print $fh qq{

Queries by type ^

-
+
@@ -1182,17 +1270,14 @@ sub dump_as_html print $fh "\n"; print $fh "\n"; print $fh "\n" if (($total - $totala) > 0); - print $fh "
Type
UPDATE", &comma_numbers($overall_stat{'UPDATE'}), "", sprintf("%0.2f", ($overall_stat{'UPDATE'}*100)/$total), "%
DELETE", &comma_numbers($overall_stat{'DELETE'}), "", sprintf("%0.2f", ($overall_stat{'DELETE'}*100)/$total), "%
OTHERS", &comma_numbers($total - $totala), "", sprintf("%0.2f", (($total - $totala)*100)/$total), "%
\n"; - + print $fh "
\n"; if ($graph) { - my @data1 = (); - push(@data1, sprintf("%0.2f", ($overall_stat{'SELECT'}*100)/$total), sprintf("%0.2f", ($overall_stat{'INSERT'}*100)/$total), sprintf("%0.2f", ($overall_stat{'UPDATE'}*100)/$total), sprintf("%0.2f", ($overall_stat{'DELETE'}*100)/$total), sprintf("%0.2f", (($total - $totala)*100)/$total)); - my @labels = ('SELECT' . " $data1[0]\%", 'INSERT' . " $data1[1]\%", 'UPDATE' . " $data1[2]\%", 'DELETE' . " $data1[3]\%", 'OTHER' . " $data1[4]\%"); - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('querytype', 'Type of queries'); - print $fh qq{

Type of queries

}; - @graph_values = (); + &flotr2_piegraph('queriesbytype_graph','Type of queries', + ( + 'SELECT' => $overall_stat{'SELECT'},'INSERT'=>$overall_stat{'INSERT'},'UPDATE'=>$overall_stat{'UPDATE'}, + 'DELETE'=>$overall_stat{'DELETE'},'Others' => $total - $totala + ) + ); } print $fh "\n"; @@ -1201,7 +1286,7 @@ sub dump_as_html print $fh qq{

Locks by type ^

-
+
@@ -1223,19 +1308,13 @@ sub dump_as_html $total_duration += $lock_info{$t}{duration}; } print $fh "\n"; - print $fh "
Type
Total", &comma_numbers($total_count), "", &convert_time($total_duration), "", &convert_time($total_duration/($total_count||1)), "
\n"; if ($graph) { - my @data1 = (); - my @labels = (); + my %locktype = (); foreach my $t (sort keys %lock_info) { - push(@data1, sprintf("%0.2f", ($lock_info{$t}{count}*100)/($total_count || 1))); - push(@labels, "$t $data1[-1]\%"); + $locktype{$t} = $lock_info{$t}{count} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('locktype', 'Type of locks'); - print $fh qq{

Type of locks

}; - @graph_values = (); + &flotr2_piegraph('lockbytype_graph','Type of locks', %locktype); } print $fh "
\n"; } @@ -1245,7 +1324,7 @@ sub dump_as_html print $fh qq{

Sessions per database ^

-
+
@@ -1259,19 +1338,13 @@ sub dump_as_html print $fh "\n"; $total_count += $session_info{database}{$d}{count}; } - print $fh "
Database
$d", &comma_numbers($session_info{database}{$d}{count}), "", &convert_time($session_info{database}{$d}{duration}), "", &convert_time($session_info{database}{$d}{duration}/$session_info{database}{$d}{count}), "
\n"; if ($graph) { - my @data1 = (); - my @labels = (); + my %infos = (); foreach my $d (sort keys %{$session_info{database}}) { - push(@data1, sprintf("%0.2f", ($session_info{database}{$d}{count}*100)/$total_count)); - push(@labels, "$d $data1[-1]\%"); + $infos{$d} = $session_info{database}{$d}{count} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('databasesession', 'Databases sessions'); - print $fh qq{

Databases Sessions

}; - @graph_values = (); + &flotr2_piegraph('databasesessions_graph','Sessions per database', %infos); } print $fh "
\n"; } @@ -1280,7 +1353,7 @@ sub dump_as_html print $fh qq{

Sessions per user ^

-
+
@@ -1294,19 +1367,13 @@ sub dump_as_html $total_count += $session_info{user}{$d}{count}; print $fh "\n"; } - print $fh "
User
$d", &comma_numbers($session_info{user}{$d}{count}), "", &convert_time($session_info{user}{$d}{duration}), "", &convert_time($session_info{user}{$d}{duration}/$session_info{user}{$d}{count}), "
\n"; if ($graph) { - my @data1 = (); - my @labels = (); + my %infos = (); foreach my $d (sort keys %{$session_info{user}}) { - push(@data1, sprintf("%0.2f", ($session_info{user}{$d}{count}*100)/$total_count)); - push(@labels, "$d $data1[-1]\%"); + $infos{$d} = $session_info{user}{$d}{count} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('usersession', 'Users sessions'); - print $fh qq{

Users Sessions

}; - @graph_values = (); + &flotr2_piegraph('usersessions_graph','Sessions per user', %infos); } print $fh "
\n"; } @@ -1316,7 +1383,7 @@ sub dump_as_html print $fh qq{

Sessions per host ^

-
+
@@ -1330,19 +1397,13 @@ sub dump_as_html $total_count += $session_info{host}{$d}{count}; print $fh "\n"; } - print $fh "
Host
$d", &comma_numbers($session_info{host}{$d}{count}), "", &convert_time($session_info{host}{$d}{duration}), "", &convert_time($session_info{host}{$d}{duration}/$session_info{host}{$d}{count}), "
\n"; if ($graph) { - my @data1 = (); - my @labels = (); + my %infos = (); foreach my $d (sort keys %{$session_info{host}}) { - push(@data1, sprintf("%0.2f", ($session_info{host}{$d}{count}*100)/$total_count)); - push(@labels, "$d $data1[-1]\%"); + $infos{$d} = $session_info{host}{$d}{count} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('hostsession', 'Hosts sessions'); - print $fh qq{

Hosts Sessions

}; - @graph_values = (); + &flotr2_piegraph('hostsessions_graph','Sessions per host', %infos); } print $fh "
\n"; } @@ -1353,7 +1414,7 @@ sub dump_as_html print $fh qq{

Connections per database ^

-
+
@@ -1370,19 +1431,13 @@ sub dump_as_html print $fh "\n"; } } - print $fh "
Database
$u", &comma_numbers($connection_info{database_user}{$d}{$u}), "
1)) { - my @data1 = (); - my @labels = (); + print $fh "
\n"; + if ($graph) { + my %infos = (); foreach my $d (sort keys %{$connection_info{database}}) { - push(@data1, sprintf("%0.2f", ($connection_info{database}{$d}*100)/$total_count)); - push(@labels, "$d $data1[-1]\%"); + $infos{$d} = $connection_info{database}{$d} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('databaseconn', 'Database connections'); - print $fh qq{

Databases connections

}; - @graph_values = (); + &flotr2_piegraph('databaseconnections_graph','Connections per database', %infos); } print $fh "\n"; } @@ -1391,7 +1446,7 @@ sub dump_as_html print $fh qq{

Connections per user ^

-
+
@@ -1404,19 +1459,13 @@ sub dump_as_html print $fh "\n"; $total_count += $connection_info{user}{$u}; } - print $fh "
User
$u", &comma_numbers($connection_info{user}{$u}), "
1)) { - my @data1 = (); - my @labels = (); - foreach my $u (sort keys %{$connection_info{user}}) { - push(@data1, sprintf("%0.2f", ($connection_info{user}{$u}*100)/$total_count)); - push(@labels, "$u $data1[-1]\%"); + print $fh "
\n"; + if ($graph) { + my %infos = (); + foreach my $d (sort keys %{$connection_info{user}}) { + $infos{$d} = $connection_info{user}{$d} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('userconn', 'Users connections'); - print $fh qq{

Users connections

}; - @graph_values = (); + &flotr2_piegraph('userconnections_graph','Connections per user', %infos); } print $fh "\n"; } @@ -1426,7 +1475,7 @@ sub dump_as_html print $fh qq{

Connections per host ^

-
+
@@ -1439,19 +1488,13 @@ sub dump_as_html print $fh "\n"; $total_count += $connection_info{host}{$h}; } - print $fh "
Host
$h", &comma_numbers($connection_info{host}{$h}), "
1)) { - my @data1 = (); - my @labels = (); - foreach my $h (sort keys %{$connection_info{host}}) { - push(@data1, sprintf("%0.2f", ($connection_info{host}{$h}*100)/$total_count)); - push(@labels, "$h $data1[-1]\%"); + print $fh "
\n"; + if ($graph) { + my %infos = (); + foreach my $d (sort keys %{$connection_info{host}}) { + $infos{$d} = $connection_info{host}{$d} || 0; } - push(@graph_values, [ @labels ] ); @labels = (); - push(@graph_values, [ @data1 ] ); @data1 = (); - &create_graph_pie('hostconn', 'Hosts connections'); - print $fh qq{

Hosts connections

}; - @graph_values = (); + &flotr2_piegraph('hostconnections_graph','Connections per host', %infos); } print $fh "\n"; } @@ -2033,40 +2076,6 @@ sub normalize_error return $orig_query; } - -sub create_graph -{ - my ($filename, $title, $x_label, $y_label, @legends) = @_; - - use GD::Graph::lines; - my $graf = new GD::Graph::lines(1000, 350); - $graf->set( - x_label => $x_label || '', - y_label => $y_label || '', - title => $title || '', - bgclr => '#ffffff', - fgclr => '#dddddd', - legendclr => '#993300', - legend_placement=> 'RC', - dclrs => [ qw(red orange green) ], - x_labels_vertical => 1, - transparent => 1, - long_ticks => 1, - shadow_depth => 5, - box_axis => 0, - show_values => 0, - x_label_skip => 12, - ) or die "FATAL: error creating graph, " . $graf->error . "\n"; - $graf->set_text_clr('#993300'); - $graf->set_legend(@legends) if ($#legends >= 0); - my $gd = $graf->plot(\@graph_values) or die $graf->error; - open(IMG, ">$outdir$filename.png") or die $!; - binmode IMG; - print IMG $gd->png; - close IMG; - -} - sub average_five_minutes { my $val = shift; @@ -2084,50 +2093,6 @@ sub average_five_minutes return $val; } -sub create_graph_twoaxes -{ - my ($filename, $title, $x_label, $y1_label, $y2_label, @legends) = @_; - - use GD::Graph::lines; - my $len = $#graph_values; - my @use_axis = (); - for (my $i = 0; $i <= $len; $i++) { - if ($i < $len) { - push(@use_axis, '1'); - } else { - push(@use_axis, '2'); - } - } - my $graf = new GD::Graph::lines(1000, 350); - $graf->set( - x_label => $x_label || '', - y1_label => $y1_label || '', - y2_label => $y2_label || '', - title => $title || '', - two_axes => 1, - use_axis => \@use_axis, - bgclr => '#ffffff', - fgclr => '#dddddd', - legendclr => '#993300', - legend_placement=> 'RC', - dclrs => [ qw(red orange green blue) ], - x_labels_vertical => 1, - transparent => 1, - long_ticks => 1, - shadow_depth => 5, - box_axis => 0, - show_values => 0, - ) or die "FATAL: error creating graph, " . $graf->error . "\n"; - $graf->set_text_clr('#993300'); - $graf->set_legend(@legends) if ($#legends >= 0); - my $gd = $graf->plot(\@graph_values) or die $graf->error; - open(IMG, ">$outdir$filename.png") or die $!; - binmode IMG; - print IMG $gd->png; - close IMG; - -} - sub autodetect_format { @@ -2166,30 +2131,6 @@ sub autodetect_format return $fmt; } -sub create_graph_pie -{ - my ($filename, $title, @legends) = @_; - - use GD::Graph::pie; - my $graf = new GD::Graph::pie(400, 200); - $graf->set( - title => $title || '', - bgclr => '#ffffff', - fgclr => '#dddddd', - legendclr => '#993300', - dclrs => [ qw(lbrown lorange lgray lyellow lgreen lblue lpurple lred) ], - transparent => 1, - ) or die "FATAL: error creating graph, " . $graf->error . "\n"; - $graf->set_text_clr('#993300'); - $graf->set_legend(@legends) if ($#legends >= 0); - my $gd = $graf->plot(\@graph_values) or die $graf->error; - open(IMG, ">$outdir$filename.png") or die $!; - binmode IMG; - print IMG $gd->png; - close IMG; - -} - sub progress_bar { my ( $got, $total, $width, $char ) = @_; $width ||= 25; $char ||= '='; @@ -2198,3 +2139,191 @@ sub progress_bar { $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/+$total; } + +sub flotr2_graph +{ + my ($buttonid, $divid, $data1, $data2, $data3, $title, $ytitle, $legend1, $legend2, $legend3, $ytitle2, $data4, $legend4) = @_; + + $data1 = "var d1 = [$data1];" if ($data1); + $data2 = "var d2 = [$data2];" if ($data2); + $data3 = "var d3 = [$data3];" if ($data3); + $data4 = "var d4 = [$data4];" if ($data4); + + $legend1 = "{ data: d1, label: \"$legend1\" }," if ($legend1); + $legend2 = "{ data: d2, label: \"$legend2\" }," if ($legend2); + $legend3 = "{ data: d3, label: \"$legend3\" }," if ($legend3); + $legend4 = "{ data: d4, label: \"$legend4\",yaxis: 2 }," if ($legend4); + + my $yaxis2 = ''; + if ($ytitle2) { + $yaxis2 = "yaxis2: { title: \"$ytitle2\", min: 0 },"; + } + print $fh <
+ +EOF + +} + +sub flotr2_piegraph +{ + my ($divid, $title, %data) = @_; + + my @datadef = (); + my @contdef = (); + my $i = 1; + foreach my $k (sort keys %data) { + push(@datadef, "var d$i = [ [0,$data{$k}] ];\n"); + push(@contdef, "{ data: d$i, label: \"$k\" },\n"); + $i++; + } + print $fh < + +EOF + +} + + +__DATA__ + + + -- 2.40.0