From c0dbcebe7a2484128c535275ca308fa22936ddbc Mon Sep 17 00:00:00 2001 From: Darold Date: Mon, 16 Apr 2012 00:05:25 +0200 Subject: [PATCH] Remove display of locks, sessions and connections statistics when none are available --- pgbadger | 150 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 48 deletions(-) diff --git a/pgbadger b/pgbadger index d355749..05e95a2 100755 --- a/pgbadger +++ b/pgbadger @@ -750,10 +750,29 @@ function toggle(idButton, idDiv, label) { Overall statistics | Hourly statistics | Queries by type | -Locks by type | -Sessions per database | -Sessions per user | -Sessions per host | +}; +if (scalar keys %lock_info > 0) { + print $fh qq{Locks by type |}; +} +if (exists $session_info{database}) { + print $fh qq{Sessions per database |}; +} +if (exists $session_info{user}) { + print $fh qq{Sessions per user |}; +} +if (exists $session_info{host}) { + print $fh qq{Sessions per host |}; +} +if (exists $connection_info{database}) { + print $fh qq{Connections per database |}; +} +if (exists $connection_info{user}) { + print $fh qq{Connections per user |}; +} +if (exists $connection_info{host}) { + print $fh qq{Connections per host |}; +} +print $fh qq{ Slowest queries | Queries that took up the most time (N) | Most frequent queries (N) | @@ -777,7 +796,32 @@ sub html_footer
Table of contents
@@ -1071,7 +1115,8 @@ sub dump_as_html print $fh "\n"; # Lock stats per type - print $fh qq{ + if (scalar keys %lock_info > 0) { + print $fh qq{

Locks by type ^

@@ -1082,22 +1127,24 @@ sub dump_as_html }; - my $total_count = 0; - my $total_duration = 0; - foreach my $t (sort keys %lock_info) { - print $fh "\n"; - foreach my $o (sort keys %{$lock_info{$t}}) { - next if (($o eq 'count') || ($o eq 'duration') || ($o eq 'chronos')); - print $fh "\n"; + my $total_count = 0; + my $total_duration = 0; + foreach my $t (sort keys %lock_info) { + print $fh "\n"; + foreach my $o (sort keys %{$lock_info{$t}}) { + next if (($o eq 'count') || ($o eq 'duration') || ($o eq 'chronos')); + print $fh "\n"; + } + $total_count += $lock_info{$t}{count}; + $total_duration += $lock_info{$t}{duration}; } - $total_count += $lock_info{$t}{count}; - $total_duration += $lock_info{$t}{duration}; + print $fh "\n"; + print $fh "
Av. duration (s)
$t", &comma_numbers($lock_info{$t}{count}), "", &convert_time($lock_info{$t}{duration}), "", &convert_time($lock_info{$t}{duration}/$lock_info{$t}{count}), "
$o", &comma_numbers($lock_info{$t}{$o}{count}), "", &convert_time($lock_info{$t}{$o}{duration}), "", &convert_time($lock_info{$t}{$o}{duration}/$lock_info{$t}{$o}{count}), "
$t", &comma_numbers($lock_info{$t}{count}), "", &convert_time($lock_info{$t}{duration}), "", &convert_time($lock_info{$t}{duration}/$lock_info{$t}{count}), "
$o", &comma_numbers($lock_info{$t}{$o}{count}), "", &convert_time($lock_info{$t}{$o}{duration}), "", &convert_time($lock_info{$t}{$o}{duration}/$lock_info{$t}{$o}{count}), "
Total", &comma_numbers($total_count), "", &convert_time($total_duration), "", &convert_time($total_duration/($total_count||1)), "
\n"; } - print $fh "Total", &comma_numbers($total_count), "", &convert_time($total_duration), "", &convert_time($total_duration/($total_count||1)), "\n"; - print $fh "\n"; # Show session per database statistics - print $fh qq{ + if (exists $session_info{database}) { + print $fh qq{

Sessions per database ^

@@ -1108,13 +1155,14 @@ sub dump_as_html }; - foreach my $d (sort keys %{$session_info{database}}) { - print $fh "\n"; + foreach my $d (sort keys %{$session_info{database}}) { + print $fh "\n"; + } + print $fh "
$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}), "
$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"; } - print $fh "\n"; - # Show session per user statistics - print $fh qq{ + if (exists $session_info{user}) { + print $fh qq{

Sessions per user ^

@@ -1125,13 +1173,15 @@ sub dump_as_html }; - foreach my $d (sort keys %{$session_info{user}}) { - print $fh "\n"; + foreach my $d (sort keys %{$session_info{user}}) { + print $fh "\n"; + } + print $fh "
$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}), "
$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"; } - print $fh "\n"; # Show session per host statistics - print $fh qq{ + if (exists $session_info{host}) { + print $fh qq{

Sessions per host ^

@@ -1142,15 +1192,16 @@ sub dump_as_html }; - foreach my $d (sort keys %{$session_info{host}}) { - print $fh "\n"; + foreach my $d (sort keys %{$session_info{host}}) { + print $fh "\n"; + } + print $fh "
$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}), "
$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"; } - print $fh "\n"; - $connection_info{count}++; # Show connection per database statistics - print $fh qq{ + if (exists $connection_info{database}) { + print $fh qq{

Connections per database ^

@@ -1160,17 +1211,18 @@ sub dump_as_html }; - foreach my $d (sort keys %{$connection_info{database}}) { - print $fh "\n"; - foreach my $u (sort keys %{$connection_info{user}}) { - next if (!exists $connection_info{database_user}{$d}{$u}); - print $fh "\n"; + foreach my $d (sort keys %{$connection_info{database}}) { + print $fh "\n"; + foreach my $u (sort keys %{$connection_info{user}}) { + next if (!exists $connection_info{database_user}{$d}{$u}); + print $fh "\n"; + } } + print $fh "
$d", &comma_numbers($connection_info{database}{$d}), "
$u", &comma_numbers($connection_info{database_user}{$d}{$u}), "
$d", &comma_numbers($connection_info{database}{$d}), "
$u", &comma_numbers($connection_info{database_user}{$d}{$u}), "
\n"; } - print $fh "\n"; - # Show connection per user statistics - print $fh qq{ + if (exists $connection_info{user}) { + print $fh qq{

Connections per user ^

@@ -1179,13 +1231,15 @@ sub dump_as_html }; - foreach my $u (sort keys %{$connection_info{user}}) { - print $fh "\n"; + foreach my $u (sort keys %{$connection_info{user}}) { + print $fh "\n"; + } + print $fh "
$u", &comma_numbers($connection_info{user}{$u}), "
$u", &comma_numbers($connection_info{user}{$u}), "
\n"; } - print $fh "\n"; # Show connection per host statistics - print $fh qq{ + if (exists $connection_info{host}) { + print $fh qq{

Connections per host ^

@@ -1194,11 +1248,11 @@ sub dump_as_html }; - foreach my $h (sort keys %{$connection_info{host}}) { - print $fh "\n"; + foreach my $h (sort keys %{$connection_info{host}}) { + print $fh "\n"; + } + print $fh "
$h", &comma_numbers($connection_info{host}{$h}), "
$h", &comma_numbers($connection_info{host}{$h}), "
\n"; } - print $fh "\n"; - # Show top informations print $fh qq{ -- 2.50.0