],
;
+if ( $db eq 'PostgreSQL' ) {
+
+ my $enabled = FS::Record->scalar_sql('SHOW wal_level') eq 'hot_standby'
+ && FS::Record->scalar_sql('SHOW archive_mode') eq 'on';
+
+ my $slave =
+ FS::Record->scalar_sql('SHOW archive_command') =~ / postgres\@([\w\.\-]+): /
+ ? $1 : '';
+
+ $status{'Replication'} = [
+ { 'title' => 'Status', #?
+ 'value' => $enabled ? 'Enabled' : 'Disabled',
+ },
+ ];
+
+ if ( $enabled ) {
+ push @{ $status{'Replication'} },
+ { 'title' => 'Slave',
+ 'value' => $slave || '(Missing, or unparseable archive_command)',
+ },
+ ;
+ if ( $slave ) {
+ #how far behind is it? will be easier once we're off 9.1
+ # http://www.keithf4.com/monitoring_streaming_slave_lag/
+ # except pg_stat_replication still doesn't fill in the columns we need as
+ # non-Pg user :/
+ push @{ $status{'Replication'} },
+ { 'title' => 'Slave',
+ 'value' => $slave || '(Missing, or unparseable archive_command)',
+ },
+ ;
+ }
+ }
+
+} else {
+
+ $status{'Replication'} = [
+ { 'title' => 'Enabled',
+ 'value' => "(Not yet checked on $db)",
+ },
+ ];
+
+}
+
if ( _is_running('cdrd') ) {
my $delay = FS::Record->scalar_sql('
}
+ my $pr_delay = FS::Record->scalar_sql('
+ SELECT AVG(end_date-start_date)
+ FROM queue_stat
+ GROUP BY statnum
+ ORDER BY statnum DESC
+ LIMIT 100
+ ');
+ if ( $pr_delay ) {
+ my $h = int($delay/3600);
+ my $m = int( ($delay%3600) / 60 );
+ my $s = $delay%60;
+
+ $pr_delay = ( $h ? $h. 'h' : '' ).
+ ( $h||$m ? $m. 'm' : '').
+ $s. 's';
+
+ }
+
+ my $dayago = time2str('%Y-%m-%d %X', time - 86400);
+ my $cdrs = FS::Record->scalar_sql(qq{
+ SELECT COUNT(*) FROM cdr
+ WHERE ( freesidestatus IS NULL OR freesidestatus = '' )
+ AND calldate > '$dayago'
+ });
+
$status{'CDR Processing'} = [
{ 'title' => 'Current processing delay',
'value' => $delay,
},
+ { 'title' => 'Average billing time',
+ 'value' => $pr_delay,
+ },
+ { 'title' => 'Unprocessed CDRs (last 24 hours)',
+ 'value' => $cdrs,
+ },
];
}