Skip to content

Commit

Permalink
Day left calc
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatacconi committed Feb 27, 2024
1 parent c829287 commit 6d005f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
27 changes: 21 additions & 6 deletions app/shareds/DiskUsage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<template v-if="calcStatExecuted">
<div>
<p>
Occupancy percentage of the partition where log folder resides.
Occupancy percentage of disk's partition where log folder resides.
</p>

<!-- Need to change color when over 80 (orange) and 90 (red) -->
<v-progress-linear
v-model="diskUsageData['used-space-percentage']"
height="30"
:color="progressBarColor(diskUsageData['used-space-percentage'])"
>
<strong>{{ Math.ceil(diskUsageData['used-space-percentage']) }}%</strong>
</v-progress-linear>
Expand All @@ -29,15 +29,20 @@
</span>
<span class="text-h6 text--gray">
<br>
<strong class="pl-3">({{ diskUsageData['total-log-size-yesterday'] }}</strong> {{ diskUsageData['unit'] }} - amount of logs collected yesterday)
(
<strong>{{ diskUsageData['total-log-space-yesterday'] }}</strong> {{ diskUsageData['unit'] }} amount of logs collected yesterday
<template v-if=" diskUsageData['day-left'] != '' && diskUsageData['day-left'] > 0 && diskUsageData['day-left'] <= 365 ">
, {{ diskUsageData['day-left'] }} day/s left.
</template>
)
</span>
</template>
</p>
<div>

<!-- Need to be completed -->
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
The bar representing the percentage of disk occupancy will change color to identify an emergency situation.
<br>
The daily log size data will allow you to calculate the time available to fill the disk
</div>
</template>

Expand Down Expand Up @@ -82,6 +87,16 @@
self.calcStatExecuted = true;
self.diskUsageData = response.data;
});
},
progressBarColor(percentage) {
if (percentage > 90) {
return 'red';
} else if (percentage > 80) {
return 'orange';
} else {
return 'primary';
}
}
},
Expand Down
17 changes: 16 additions & 1 deletion routes/api/task-stat.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,14 @@ static function (array $file) {
$free_space = $free_space_disp = disk_free_space($LOGS_DIR);
$used_space = $used_space_disp = $total_space - $free_space;

$date_focus = strtotime('yesterday');
$aFILE = glob($LOGS_DIR .'/'. '*_'.date("Y-m-d", $date_focus).'*_'.date("Y-m-d", $date_focus).'_*.log');

$total_space_yesterday = 0;
foreach ($aFILE as $file) {
$total_space_yesterday += filesize($file);
}

$num_len = strlen($used_space);
if($unit = 'AUTO'){
if($num_len < 4){
Expand All @@ -884,10 +892,17 @@ static function (array $file) {
$total_space_disp = number_format(($total_space / pow(1024, $exponent)), 2, '.', '');
$free_space_disp = number_format(($free_space / pow(1024, $exponent)), 2, '.', '');
$used_space_disp = number_format(($used_space / pow(1024, $exponent)), 2, '.', '');
$total_space_yesterday_disp = number_format(($total_space_yesterday / pow(1024, $exponent)), 2, '.', '');
}

$data["total-partition-size"] = $total_space_disp;
$data["total-log-size-yesterday"] = 0; //need implementation
$data["total-log-space-yesterday"] = $total_space_yesterday_disp;

$data["day-left"] = "";
if($total_space_yesterday > 0){
$data["day-left"] = ceil($free_space / $total_space_yesterday);
}

$data["partition-free-space"] = $free_space_disp;
$data["partition-used-space"] = $used_space_disp;
$data["unit"] = $unit;
Expand Down

0 comments on commit 6d005f1

Please sign in to comment.