From: Gilles Darold Date: Tue, 24 Jan 2017 11:58:22 +0000 (+0100) Subject: Add report of error class distribution when SQLState is available in the log line... X-Git-Tag: v9.1~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da4a1766dad9f18d3b9f0a72f2c77d654622262e;p=pgbadger Add report of error class distribution when SQLState is available in the log line prefix. Thanks to jacks33 for the feature request. --- diff --git a/pgbadger b/pgbadger index 79d2744..bc4001a 100644 --- a/pgbadger +++ b/pgbadger @@ -161,6 +161,53 @@ AOAAAABgAAAA4AAAAOAAAADgAAAA4AAAAOAAAADgAAAA4AAAAGAAAADgAAAA4AAAAOAAAADgAAAA /Af/4AAAAP//v//gAAAA/////+AAAAA '; +my %CLASS_ERROR_CODE = ( + '00' => 'Successful Completion', + '01' => 'Warning', + '02' => 'No Data (this is also a warning class per the SQL standard)', + '03' => 'SQL Statement Not Yet Complete', + '08' => 'Connection Exception', + '09' => 'Triggered Action Exception', + '0A' => 'Feature Not Supported', + '0B' => 'Invalid Transaction Initiation', + '0F' => 'Locator Exception', + '0L' => 'Invalid Grantor', + '0P' => 'Invalid Role Specification', + '0Z' => 'Diagnostics Exception', + '20' => 'Case Not Found', + '21' => 'Cardinality Violation', + '22' => 'Data Exception', + '23' => 'Integrity Constraint Violation', + '24' => 'Invalid Cursor State', + '25' => 'Invalid Transaction State', + '26' => 'Invalid SQL Statement Name', + '27' => 'Triggered Data Change Violation', + '28' => 'Invalid Authorization Specification', + '2B' => 'Dependent Privilege Descriptors Still Exist', + '2D' => 'Invalid Transaction Termination', + '2F' => 'SQL Routine Exception', + '34' => 'Invalid Cursor Name', + '38' => 'External Routine Exception', + '39' => 'External Routine Invocation Exception', + '3B' => 'Savepoint Exception', + '3D' => 'Invalid Catalog Name', + '3F' => 'Invalid Schema Name', + '40' => 'Transaction Rollback', + '42' => 'Syntax Error or Access Rule Violation', + '44' => 'WITH CHECK OPTION Violation', + '53' => 'Insufficient Resources', + '54' => 'Program Limit Exceeded', + '55' => 'Object Not In Prerequisite State', + '57' => 'Operator Intervention', + '58' => 'System Error (errors external to PostgreSQL itself)', + '72' => 'Snapshot Failure', + 'F0' => 'Configuration File Error', + 'HV' => 'Foreign Data Wrapper Error (SQL/MED)', + 'P0' => 'PL/pgSQL Error', + 'XX' => 'Internal Error', +); + + #### # method used to fork as many child as wanted ## @@ -985,6 +1032,7 @@ my %error_info = (); my %pgb_error_info = (); my %pgb_pool_info = (); my %logs_type = (); +my %errors_code = (); my %per_minute_info = (); my %pgb_per_minute_info = (); my %lock_info = (); @@ -2303,6 +2351,7 @@ sub init_stats_vars %pgb_error_info = (); %pgb_pool_info = (); %logs_type = (); + %errors_code = (); %per_minute_info = (); %pgb_per_minute_info = (); %lock_info = (); @@ -3690,7 +3739,9 @@ sub set_top_sample # Stores top N error sample queries sub set_top_error_sample { - my ($q, $date, $real_error, $detail, $context, $statement, $hint, $db, $user, $app, $remote) = @_; + my ($q, $date, $real_error, $detail, $context, $statement, $hint, $db, $user, $app, $remote, $sqlstate) = @_; + + $errors_code{$sqlstate}++ if ($sqlstate); # Stop when we have our number of samples if (!exists $error_info{$q}{date} || ($#{$error_info{$q}{date}}+1 < $sample)) { @@ -3711,6 +3762,7 @@ sub set_top_error_sample push(@{$error_info{$q}{user}}, $user); push(@{$error_info{$q}{app}}, $app); push(@{$error_info{$q}{remote}}, $remote); + push(@{$error_info{$q}{sqlstate}}, $sqlstate); } } } @@ -4547,6 +4599,21 @@ sub show_error_as_text print $fh "$d\t\t", &comma_numbers($logs_type{$d}), "\t", sprintf("%0.2f", ($logs_type{$d} * 100) / $total_logs), "%\n"; } } + + if (scalar keys %errors_code > 0) { + print $fh "\n- Logs per type ---------------------------------------------\n\n"; + + my $total_logs = 0; + foreach my $d (keys %errors_code) { + $total_logs += $errors_code{$d}; + } + print $fh "Errors class code Count Percentage\n"; + foreach my $d (sort keys %errors_code) { + next if (!$errors_code{$d}); + print $fh "$CLASS_ERROR_CODE{$d}\t$d\t\t", &comma_numbers($errors_code{$d}), "\t", sprintf("%0.2f", ($errors_code{$d} * 100) / $total_logs), "%\n"; + } + } + } sub show_pgb_error_as_text @@ -4779,11 +4846,13 @@ sub html_header } } if (!$disable_error && !$pgbouncer_only) { + my $sqlstate_report = '
  • Error class distribution
  • ' if (scalar keys %errors_code > 0); print $fh qq{