mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 17:59:55 +02:00
Add a disk check
This commit is contained in:
parent
b23ad996a2
commit
25bb9cc324
5 changed files with 144 additions and 10 deletions
117
admin/disk_usage.php
Normal file
117
admin/disk_usage.php
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<script src="<?php echo getURL('node_modules/chart.js/dist/chart.umd.js'); ?>" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<canvas id="diskUsageBarChart" height="50"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var data = <?php echo json_encode(getVideosDirectoryUsageInfo()); ?>;
|
||||||
|
var isCurrentThemeDark = <?php echo json_encode(isCurrentThemeDark()); ?>; // Assuming this returns 1 or 0
|
||||||
|
|
||||||
|
// Define text color based on theme
|
||||||
|
var textColor = isCurrentThemeDark == 1 ? '#ffffff' : '#000000'; // White for dark theme, black for light theme
|
||||||
|
|
||||||
|
var ctxBar = document.getElementById('diskUsageBarChart').getContext('2d');
|
||||||
|
|
||||||
|
var usedSpace = data.used_space_bytes;
|
||||||
|
var freeSpace = data.free_space_bytes;
|
||||||
|
var directoryUsage = data.directory_bytes_used;
|
||||||
|
|
||||||
|
// Calculate the used space excluding directory usage
|
||||||
|
var actualUsedSpace = usedSpace - directoryUsage;
|
||||||
|
|
||||||
|
// Calculate the max value for the x-axis
|
||||||
|
var maxValue = actualUsedSpace + freeSpace + directoryUsage;
|
||||||
|
|
||||||
|
// Stacked Bar Chart Data
|
||||||
|
var stackedBarChartData = {
|
||||||
|
labels: [''], // Empty label to remove 'Disk Usage' text
|
||||||
|
datasets: [{
|
||||||
|
label: 'Free',
|
||||||
|
data: [(freeSpace / (1024 * 1024 * 1024)).toFixed(2)],
|
||||||
|
backgroundColor: '#36A2EB'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Used',
|
||||||
|
data: [(actualUsedSpace / (1024 * 1024 * 1024)).toFixed(2)],
|
||||||
|
backgroundColor: '#FF6384'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Videos',
|
||||||
|
data: [(directoryUsage / (1024 * 1024 * 1024)).toFixed(2)],
|
||||||
|
backgroundColor: '#FFCE56'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create Stacked Bar Chart
|
||||||
|
var diskUsageStackedBarChart = new Chart(ctxBar, {
|
||||||
|
type: 'bar',
|
||||||
|
data: stackedBarChartData,
|
||||||
|
options: {
|
||||||
|
indexAxis: 'y', // This makes the bar chart horizontal
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
stacked: true,
|
||||||
|
beginAtZero: true,
|
||||||
|
max: (maxValue / (1024 * 1024 * 1024)).toFixed(2), // Set max value for the x-axis in GB
|
||||||
|
ticks: {
|
||||||
|
color: textColor // X-axis labels color based on theme
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
stacked: true,
|
||||||
|
ticks: {
|
||||||
|
color: textColor // Y-axis labels color based on theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Disk Usage Overview (GB)',
|
||||||
|
color: textColor, // Title color based on theme
|
||||||
|
font: {
|
||||||
|
size: 18
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
top: 10,
|
||||||
|
bottom: 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
subtitle: {
|
||||||
|
display: true,
|
||||||
|
text: data.real_path,
|
||||||
|
color: textColor, // Subtitle color based on theme
|
||||||
|
font: {
|
||||||
|
size: 14,
|
||||||
|
style: 'italic'
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
bottom: 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
backgroundColor: isCurrentThemeDark == 1 ? '#333333' : '#ffffff', // Tooltip background based on theme
|
||||||
|
titleColor: textColor, // Tooltip title text color based on theme
|
||||||
|
bodyColor: textColor, // Tooltip body text color based on theme
|
||||||
|
callbacks: {
|
||||||
|
label: function(tooltipItem) {
|
||||||
|
return tooltipItem.dataset.label + ': ' + tooltipItem.raw + ' GB';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
color: textColor // Legend text color based on theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -221,9 +221,10 @@ foreach ($ports['ports'] as $key => $value) {
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
<?php include __DIR__ . '/disk_usage.php'; ?>
|
||||||
|
</div>
|
||||||
|
<div class="panel-footer">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-lg-8 col-md-6">
|
<div class="col-lg-8 col-md-6">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
|
|
|
@ -1056,25 +1056,35 @@ function getVideosDirectoryUsageInfo() {
|
||||||
$realPath = realpath($dir);
|
$realPath = realpath($dir);
|
||||||
|
|
||||||
// Get disk usage information using 'du' command
|
// Get disk usage information using 'du' command
|
||||||
$command = "du -sh $realPath 2>&1";
|
$command = "du -s $realPath 2>&1"; // Removed 'h' to get the usage in bytes
|
||||||
$usage = shell_exec($command);
|
$usageOutput = shell_exec($command);
|
||||||
|
$usageBytes = intval(preg_split('/\s+/', $usageOutput)[0] * 1024); // Convert from KB to bytes
|
||||||
|
|
||||||
// Get the total space and free space on the partition
|
// Get the total space and free space on the partition
|
||||||
$totalSpace = disk_total_space($realPath);
|
$totalSpace = disk_total_space($realPath);
|
||||||
$freeSpace = disk_free_space($realPath);
|
$freeSpace = disk_free_space($realPath);
|
||||||
$usedSpace = $totalSpace - $freeSpace;
|
$usedSpace = $totalSpace - $freeSpace;
|
||||||
|
$usedPercentage = ($usedSpace / $totalSpace) * 100;
|
||||||
|
|
||||||
// Format the size values
|
// Format the size values and percentage
|
||||||
$totalSpaceFormatted = humanFileSize($totalSpace);
|
$totalSpaceFormatted = humanFileSize($totalSpace);
|
||||||
$freeSpaceFormatted = humanFileSize($freeSpace);
|
$freeSpaceFormatted = humanFileSize($freeSpace);
|
||||||
$usedSpaceFormatted = humanFileSize($usedSpace);
|
$usedSpaceFormatted = humanFileSize($usedSpace);
|
||||||
|
$usedPercentageFormatted = sprintf('%.2f%%', $usedPercentage);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'is_symbolic_link' => $isSymbolicLink,
|
'is_symbolic_link' => $isSymbolicLink,
|
||||||
'real_path' => $realPath,
|
'real_path' => $realPath,
|
||||||
'directory_usage' => trim($usage),
|
'directory_usage' => trim($usageOutput),
|
||||||
|
'directory_bytes_used' => $usageBytes, // Total bytes used by the directory
|
||||||
|
'total_space_bytes' => $totalSpace, // Total bytes in the partition
|
||||||
|
'free_space_bytes' => $freeSpace, // Free bytes in the partition
|
||||||
|
'used_space_bytes' => $usedSpace, // Used bytes in the partition
|
||||||
|
'directory_used' => humanFileSize($usageBytes),
|
||||||
'total_space' => $totalSpaceFormatted,
|
'total_space' => $totalSpaceFormatted,
|
||||||
'free_space' => $freeSpaceFormatted,
|
'free_space' => $freeSpaceFormatted,
|
||||||
'used_space' => $usedSpaceFormatted
|
'used_space' => $usedSpaceFormatted,
|
||||||
|
'used_percentage' => $usedPercentageFormatted,
|
||||||
|
'used_percentage_number' => $usedPercentage
|
||||||
];
|
];
|
||||||
}
|
}
|
0
view/css/dark.css
Normal file
0
view/css/dark.css
Normal file
|
@ -53,7 +53,7 @@ foreach ($custom as $key => $value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$theme = getCurrentTheme();
|
$theme = getCurrentTheme();
|
||||||
|
$isCurrentThemeDark = isCurrentThemeDark();
|
||||||
if (empty($config)) {
|
if (empty($config)) {
|
||||||
$config = new AVideoConf();
|
$config = new AVideoConf();
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,11 @@ if(!empty($theme)){
|
||||||
?>
|
?>
|
||||||
<link href="<?php echo getURL('view/css/custom/' . $theme . '.css'); ?>" rel="stylesheet" type="text/css" id="customCSS" />
|
<link href="<?php echo getURL('view/css/custom/' . $theme . '.css'); ?>" rel="stylesheet" type="text/css" id="customCSS" />
|
||||||
<?php
|
<?php
|
||||||
|
if($isCurrentThemeDark){
|
||||||
|
?>
|
||||||
|
<link href="<?php echo getURL('view/css/dark.css'); ?>" rel="stylesheet" type="text/css" id="customCSS" />
|
||||||
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (empty($global['userBootstrapLatest'])) {
|
if (empty($global['userBootstrapLatest'])) {
|
||||||
$filename = Video::getStoragePath() . "cache/custom.css";
|
$filename = Video::getStoragePath() . "cache/custom.css";
|
||||||
|
@ -170,6 +175,7 @@ if (isRTL()) {
|
||||||
var my_identification = <?php echo json_encode(User::getNameIdentification()); ?>;
|
var my_identification = <?php echo json_encode(User::getNameIdentification()); ?>;
|
||||||
var mediaId = <?php echo json_encode(getVideos_id()); ?>;
|
var mediaId = <?php echo json_encode(getVideos_id()); ?>;
|
||||||
var player;
|
var player;
|
||||||
|
var isCurrentThemeDark = <?php echo !empty($isCurrentThemeDark)?1:0 ; ?>;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="infoForNonCachedPages">
|
<script id="infoForNonCachedPages">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue