From: Darold Date: Wed, 18 Apr 2012 19:34:42 +0000 (+0200) Subject: Add pie graph for Queries by type X-Git-Tag: v3.2~262 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=372adecc1b92471827ee021bb55eba532205b68a;p=pgbadger Add pie graph for Queries by type --- diff --git a/pgbadger b/pgbadger index 1c63047..544da4e 100755 --- a/pgbadger +++ b/pgbadger @@ -1114,6 +1114,8 @@ sub dump_as_html # INSERT/DELETE/UPDATE/SELECT repartition print $fh qq{

Queries by type ^

+ +
@@ -1131,7 +1133,18 @@ 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", (($total - $totala)*100)/$total)); + my @labels = ('SELECT' . " $data1[0]\%", 'INSERT' . " $data1[1]\%", 'UPDATE' . " $data1[2]\%", 'DELETE' . " $data1[3]\%"); + 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 = (); + } + print $fh "\n"; # Lock stats per type if (scalar keys %lock_info > 0) { @@ -1874,7 +1887,6 @@ sub create_graph binmode IMG; print IMG $gd->png; close IMG; - @graph_values = (); } @@ -1936,7 +1948,6 @@ sub create_graph_twoaxes binmode IMG; print IMG $gd->png; close IMG; - @graph_values = (); } @@ -1978,3 +1989,28 @@ 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, ">$filename.png") or die $!; + binmode IMG; + print IMG $gd->png; + close IMG; + +} + +