From b0bd99147a75e6220ba3e51e26c61f908a032090 Mon Sep 17 00:00:00 2001 From: IKEDA Soji Date: Sat, 29 Apr 2023 17:12:29 +0900 Subject: [PATCH] Overall statistics panel for each domain (#1661) --- default/web_tt2/nav.tt2 | 12 ++++++++++++ default/web_tt2/serveradmin.tt2 | 7 +++++++ default/web_tt2/stats.tt2 | 6 ++++-- src/cgi/wwsympa.fcgi.in | 27 ++++++++++++++++++++++----- src/lib/Sympa/Log.pm | 30 ++++++++++++++++++++---------- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/default/web_tt2/nav.tt2 b/default/web_tt2/nav.tt2 index f3021baa2..b73701353 100644 --- a/default/web_tt2/nav.tt2 +++ b/default/web_tt2/nav.tt2 @@ -129,6 +129,18 @@ [%|loc%]Families[%END%] [% END %] + + [% IF subaction == 'stats' %] + [% SET class = 'active' %] + [% ELSE %] + [% SET class = '' %] + [% END %] +
  • + + [%|loc%]Statistics[%END%] + +
  • + [% IF subaction == 'translation' %] [% SET class = 'active' %] [% ELSE %] diff --git a/default/web_tt2/serveradmin.tt2 b/default/web_tt2/serveradmin.tt2 index 00ead05dd..d4e967417 100644 --- a/default/web_tt2/serveradmin.tt2 +++ b/default/web_tt2/serveradmin.tt2 @@ -287,6 +287,13 @@ [% close_table %] [% END %] + +[% IF subaction == 'stats' ~%] +

    [%|loc(domain)%]Virtual domain %1 statistics[%END%]

    +

    [%|loc%]This page displays overall information regarding the activity on this virtual domain.[%END%]

    + [% PROCESS stats.tt2 %] +[%~ END %] + [% IF subaction == 'translation' %]

    [%|loc%]Translating Sympa[%END%]

    [%|loc%]Sympa is designed to allow easy internationalization of its user interface (service email messages and web interface). All translations for a language are gathered into a single PO file that can be manipulated by the standard GNU gettext tools.[%END%]

    diff --git a/default/web_tt2/stats.tt2 b/default/web_tt2/stats.tt2 index 1fbbd2a36..509b12843 100644 --- a/default/web_tt2/stats.tt2 +++ b/default/web_tt2/stats.tt2 @@ -1,12 +1,14 @@ -

    [%|loc(listname)%]List %1 statistics[%END%]

    +[% IF listconf ~%] +

    [%|loc(listname)%]List %1 statistics[%END%]

    -

    [%|loc%]This page displays overall information regarding the list activity[%END%]

    +

    [%|loc%]This page displays overall information regarding the list activity[%END%]

    [%|loc(shared_size)%]Shared document directory size: %1 kB[%END%]
    [%|loc(arc_size)%]Web archives size: %1 kB[%END%]

    +[%~ END %] [% FOREACH stat_id IN [ 'send_mail', 'add_or_subscribe', 'signoff', 'del', 'auto_del' ] ~%] [% SET o = stats.$stat_id ~%] diff --git a/src/cgi/wwsympa.fcgi.in b/src/cgi/wwsympa.fcgi.in index 65acc0b01..58c6bebb1 100644 --- a/src/cgi/wwsympa.fcgi.in +++ b/src/cgi/wwsympa.fcgi.in @@ -5912,6 +5912,9 @@ sub do_serveradmin { ## Checking families and other virtual hosts. get_server_details(); + if ($in{'subaction'} eq 'stats') { + _get_stats(); + } ## Server files foreach my $f ( @@ -15085,10 +15088,24 @@ sub do_decl_del { sub do_stats { wwslog('info', ''); - $param->{'shared_size'} = - int((Sympa::WWW::SharedDocument->new($list)->get_size + 512) / 1024); - $param->{'arc_size'} = - int((Sympa::Archive->new(context => $list)->get_size + 512) / 1024); + return _get_stats(); +} + +sub _get_stats { + my $that; + + if (ref $list eq 'Sympa::List') { + $that = $list; + + $param->{'shared_size'} = + int( + (Sympa::WWW::SharedDocument->new($that)->get_size + 512) / 1024); + $param->{'arc_size'} = + int( + (Sympa::Archive->new(context => $that)->get_size + 512) / 1024); + } else { + $that = $robot; + } my $stats = { send_mail => {title => $language->gettext("Mail sending")}, @@ -15104,7 +15121,7 @@ sub do_stats { }; foreach my $operation (keys %$stats) { - my $data = $log->aggregate_daily_data($list, $operation); + my $data = $log->aggregate_daily_data($that, $operation); if (%{$data || {}}) { $stats->{$operation}{'stats_values'} = '[' . join( ',', diff --git a/src/lib/Sympa/Log.pm b/src/lib/Sympa/Log.pm index 0c53d421e..ff59f7ee4 100644 --- a/src/lib/Sympa/Log.pm +++ b/src/lib/Sympa/Log.pm @@ -759,7 +759,7 @@ sub _aggregate_data { sub aggregate_daily_data { my $self = shift; $self->syslog('debug2', '(%s, %s)', @_); - my $list = shift; + my $that = shift; my $operation = shift; my $sdm; @@ -771,24 +771,34 @@ sub aggregate_daily_data { my $result; + my $cond; + my @vars; + if (ref $that eq 'Sympa::List') { + $cond = q{robot_counter = ? AND list_counter = ?}; + @vars = ($that->{'domain'}, $that->{'name'}); + } else { + $cond = q{robot_counter = ?}; + @vars = ($that); + } + my $sth; - my $row; unless ( $sth = $sdm->do_prepared_query( - q{SELECT beginning_date_counter AS "date", - count_counter AS "count" - FROM stat_counter_table - WHERE data_counter = ? AND - robot_counter = ? AND list_counter = ?}, + sprintf( + q{SELECT beginning_date_counter AS "date", + count_counter AS "count" + FROM stat_counter_table + WHERE data_counter = ? AND %s}, $cond + ), $operation, - $list->{'domain'}, $list->{'name'} + @vars ) ) { $self->syslog('err', 'Unable to get stat data %s for list %s', - $operation, $list); + $operation, $that); return; } - while ($row = $sth->fetchrow_hashref('NAME_lc')) { + while (my $row = $sth->fetchrow_hashref('NAME_lc')) { my $midnight = Sympa::Tools::Time::get_midnight_time($row->{'date'}); $result->{$midnight} = 0 unless defined $result->{$midnight}; $result->{$midnight} += $row->{'count'};