Re: pg_analyser uptime problem - Mailing list pgsql-general

From DAROLD Gilles
Subject Re: pg_analyser uptime problem
Date
Msg-id 3B9A9E7B.FB46042F@darold.net
Whole thread Raw
List pgsql-general
Hi Andy,


Thanks for your report, it was a silly bug. I send you a patch that correct

the problem.

The last postmaster starting date is now retrieved from the last
modification
date of the unix socket (generaly /tmp/.s.PGSQL.5432) and updated if a
postmaster start line is found in the log file.

You can change the path and filename to the unix socket into the
configuration
file with adding an option like this:

sock_file       /tmp/.s.PGSQL.5432

Notes that here it's the default value so you can not declare this option.

The distribution will be updated next week...

Regards,

Gilles Darold
--- pg_analyzer/pg_analyzer.pl    Mon Sep  3 19:24:41 2001
+++ pg_analyzer.new/pg_analyzer.pl    Sat Sep  8 23:56:10 2001
@@ -26,7 +26,7 @@

 my $VERSION = '1.1';

-# Global variables and their default value
+# Global variables and their default value, most can be overiden into the pg_analyzer.conf file
 my $PG_LOG = '/home/postgres/server.log';
 my $OUT_DIR = '/home/postgres/log_report';
 my $DATE_PROG = '/bin/date';
@@ -40,6 +40,7 @@
 my $NOTIFY = 'no';
 my $INCREMENTAL = 'no';
 my $VERBOSE = 1;
+my $SOCK_FILE = '/tmp/.s.PGSQL.5432';

 # String that if match in a line will be skipped
 # These are default, removing these line will break the report
@@ -771,6 +772,7 @@
         $NOTIFY = $value if ($key eq 'notify');
         $INCREMENTAL = $value if ($key eq 'incremental');
         $VERBOSE = $value if ($key eq 'silent');
+        $SOCK_FILE = $value if ($key eq 'sock_file');
     }
     close CONF;

@@ -807,6 +809,18 @@
         exit 0;
     }

+    # Obtain the last starting date of the postmaster by reading the creation time
+    # of the unix socket file. Default file is /tmp/.s.PGSQL.5432
+    my @date_time = localtime((stat("$SOCK_FILE"))[10]);
+    $date_time[5] += 1900;
+    $date_time[4]++;
+    $date_time[4] = "0" . $date_time[4] if ($date_time[4] < 10);
+    $date_time[3] = "0" . $date_time[3] if ($date_time[3] < 10);
+    $date_time[2] = "0" . $date_time[2] if ($date_time[2] < 10);
+    $date_time[1] = "0" . $date_time[1] if ($date_time[1] < 10);
+    $date_time[0] = "0" . $date_time[0] if ($date_time[0] < 10);
+    $BEGIN_DATE = "$date_time[5]-$date_time[4]-$date_time[3] $date_time[2]:$date_time[1]:$date_time[0]";
+
     if ($VERBOSE) {
         print STDERR "Configuration options:\n";
         print STDERR "\tPG_LOG = $PG_LOG\n";
@@ -821,6 +835,8 @@
         print STDERR "\tQUERIES = $QUERIES\n";
         print STDERR "\tNOTIFY = $NOTIFY\n";
         print STDERR "\tINCREMENTAL = $INCREMENTAL\n";
+        print STDERR "\tSOCK_FILE = $SOCK_FILE\n";
+        print STDERR "\tBEGIN_DATE = $BEGIN_DATE\n";
     }

 }

pgsql-general by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Idea: jobs.postgresql.org
Next
From: Justin Clift
Date:
Subject: Re: Idea: jobs.postgresql.org