ONO::Apps::Admin::Screen::Info::Statistics

package ONO::Apps::Admin::Screen::Info::Statistics;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################


use strict;

use ONO::IO;
use ONO::Core::HostOS;

use ONO::ToolBox::System;
use ONO::Lib::UI::Progress;

###############################################################################
# ONO
###############################################################################

sub screen {

my (
$self,
$db,
$community,
$lang,
$BLK_ref,
$vars_ref,
$sql_ref,
$ono_ref,
) = @_;

#: Display some basic system statistics.

my %BLK = %$BLK_ref;
my %vars = %$vars_ref;

my ($TITLE,$SUBTITLE,$SCREEN,$LEFT,$RIGHT,$TOOLS);

$TITLE = "Usage & limitations";
$SUBTITLE = "CPU, memory, storage & more ...";

my $cpu = ONO::IO->cpu;
my $CPU = ONO::Lib::UI::Progress->percent(ONO::Core::HostOS->cpu_load_percent("c"),"","","",50,0,75);

my $mem = ONO::IO->mem;
my (
$mem2,$used,
$free,$p1,$p2
) = ONO::Core::HostOS->mem_load;
my $MEM = ONO::Lib::UI::Progress->percent($p1,"","","",50,0,75);


$RIGHT .= qq~<div class="box_fabric mb10">
<h3>CPU</h3>
<div class="box_paper">$cpu$CPU</div>
</div>
<div class="box_fabric mb10">
<h3>RAM:</h3>
<div class="box_paper">$mem ($mem2 MB, $used MB used, $free MB free)$MEM</div>
</div>
~;

my @disks = ONO::IO->disks;
$SCREEN .= ONO::ToolBox::System->diskfree_display(\@disks,"f","<h3>Disk storage</h3>");

my $TMP;
foreach my $dir (ONO::IO->dir("var/tmp")) {
if ($dir !~ /^\./) {

my $BG;

if ($vars{'tmp_flush'} eq $dir) {
$BG = " bg_red";
foreach my $flush (ONO::IO->dir("var/tmp/$dir")) {
ONO::IO->rm("var/tmp/$dir/$flush");
ONO::IO->rmdir("var/tmp/$dir/$flush");
}
}

my $obj = ONO::IO->count("var/tmp/$dir");
my $size = ONO::IO->size("var/tmp/$dir","dh");

$TMP .= qq~<tr class="row bt bb$BG">
<td class="pad10_2 tar">$dir:</td>
<td class="pad10_2 w100">
<a href="/ono/admin/?/info_statistics/&tmp_flush=$dir" class="button_red button_mini fr">flush</a>
<span class="bold">$obj</span> directories or files, <span class="bold">$size</span>
</td>
</tr>
~;
}
}

$SCREEN .= qq~<div class="box_fabric mt10 mb10">
<h3>Web ($ENV{'SERVER_SOFTWARE'})</h3>
<div class="box_paper">
<table class="wide_table bt bb">
<tr>
<td class="pad10_2 tar">websites:</td>
<td class="pad10_2 w100"></td>
</tr>
<tr>
<td class="pad10_2 tar">platforms:</td>
<td class="pad10_2"></td>
</tr>
</table>
</div>
</div>
<div class="box_fabric mb10">
<h3>Users & e-mail</h3>
<div class="box_paper">
<table class="wide_table bt bb">
<tr>
<td class="pad10_2 tar">users:</td>
<td class="pad10_2 w100"></td>
</tr>
<tr>
<td class="pad10_2 tar">communities:</td>
<td class="pad10_2"></td>
</tr>
<tr>
<td class="pad10_2 tar">e-mail:</td>
<td class="pad10_2"></td>
</tr>
</table>
</div>
</div>
<div class="box_fabric mb10">
<h3>Databases</h3>
<div class="box_paper">
<table class="wide_table bt bb">
<tr>
<td class="pad10_2 tar">configs:</td>
<td class="pad10_2 w100"></td>
</tr>
</table>
</div>
</div>
<div class="box_fabric mb10">
<h3>Temporary files & caches</h3>
<div class="box_paper">
<table class="wide_table bt bb">
$TMP
</table>
</div>
</div>
<div class="box_fabric mb10">
<h3>Backups</h3>
<div class="box_paper">
<table class="wide_table bt bb">
<tr>
<td class="pad10_2 tar">jobs:</td>
<td class="pad10_2 w100"></td>
</tr>
</table>
</div>
</div>
~;

$RIGHT .= qq~<h3>Disk usage</h3>
<div class="inline"><a href="/ono/admin/?/setup/" class="button button_small mb20">$BLK{'setup'}</a></div>
<h3>Notifications</h3>
Administrators will get information about the disk load on a regular basis:
<ul>
<li>a monthly e-mail will always be sent</li>
<li>a weekly e-mail will be sent if the disk load is higher than 80%</li>
<li>a daily e-mail will be sent if the disk load is higher than 90%</li>
</ul>
~;


return ($TITLE,$SUBTITLE,$SCREEN,$LEFT,$RIGHT,$TOOLS);

}

###############################################################################
# end of script
###############################################################################

1;

__END__