使用php显示远程服务器的磁盘uasge数据
我有一个shell脚本,它将远程服务器的磁盘使用情况数据写入文本文件。文本文件(diskusage.txt)的内容为: 我使用php函数(line_functions.php)读取此文件,函数如下:使用php显示远程服务器的磁盘uasge数据,php,html,Php,Html,我有一个shell脚本,它将远程服务器的磁盘使用情况数据写入文本文件。文本文件(diskusage.txt)的内容为: 我使用php函数(line_functions.php)读取此文件,函数如下: <?php function getColLines1($col, $lines) { $lin1 = explode(' ', $lines[0]); return $lin1[$col]; } function getColLines2($col, $lines) {
<?php
function getColLines1($col, $lines)
{
$lin1 = explode(' ', $lines[0]);
return $lin1[$col];
}
function getColLines2($col, $lines)
{
$lin2 = explode(' ', $lines[1]);
return $lin2[$col];
}
function getColLines3($col, $lines)
{
$lin3 = explode(' ', $lines[2]);
return $lin3[$col];
}
function getColLines4($col, $lines)
{
$lin4 = explode(' ', $lines[3]);
return $lin4[$col];
}
function getColLines5($col, $lines)
{
$lin5 = explode(' ', $lines[4]);
return $lin5[$col];
}
?>
现在,我在html表格中显示这些数据,如下代码所示:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<?php
include 'line_functions.php';
$lines = file('/diskusage.txt');
$server1_root_pc=getColLines1(0, $lines).PHP_EOL; $server1_app_usedvstotal=getColLines1(1, $lines).PHP_EOL;
#displaying progress bar for disk.
if (trim($server1_root_pc)<="70%"){
echo '<div class="progress"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$server1_root_pc.'"
aria-valuemin="0" aria-valuemax="100" style="width: '.$server1_root_pc.'" >
'.$server1_root_pc.' '.$server1_app_usedvstotal.' Used
</div></div>';}
elseif(trim($server1_root_pc) >"70%" && trim($server1_root_pc)<="80%"){
echo '<div class="progress"><div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="'.$server1_root_pc.'"
aria-valuemin="0" aria-valuemax="100" style="width: '.$server1_root_pc.'" >
'.$server1_root_pc.' '.$server1_app_usedvstotal.' Used
</div></div>';}
else {echo '<div class="progress"><div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$server1_root_pc.'"
aria-valuemin="0" aria-valuemax="100" style="width: '.$server1_root_pc.'" >
'.$server1_root_pc.' '.$server1_app_usedvstotal.' Used
</div></div>';}
?>
</div>
引导示例
这应该起作用:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<?php
$lines = file('/diskusage.txt');
foreach($lines as $line) {
$cols = explode(' ', $line);
$server_root_pc = $cols[0];
$server_app_usedvstotal = $cols[1];
$percentage = (int) str_replace("%", "", $server_root_pc);
$status = "success";
if ($percentage > 80) {
$status = "danger";
} elseif ($percentage > 70) {
$status = "warning";
}
echo '<div class="progress"><div class="progress-bar progress-bar-'.$status.'" role="progressbar" aria-valuenow="'.$server_root_pc.'"
aria-valuemin="0" aria-valuemax="100" style="width: '.$server_root_pc.'" >
'.$server_root_pc.' '.$server_app_usedvstotal.' Used
</div></div>';
}
?>
</div>
</body>
</html>
引导示例
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<?php
$lines = file('/diskusage.txt');
foreach($lines as $line) {
$cols = explode(' ', $line);
$server_root_pc = $cols[0];
$server_app_usedvstotal = $cols[1];
$percentage = (int) str_replace("%", "", $server_root_pc);
$status = "success";
if ($percentage > 80) {
$status = "danger";
} elseif ($percentage > 70) {
$status = "warning";
}
echo '<div class="progress"><div class="progress-bar progress-bar-'.$status.'" role="progressbar" aria-valuenow="'.$server_root_pc.'"
aria-valuemin="0" aria-valuemax="100" style="width: '.$server_root_pc.'" >
'.$server_root_pc.' '.$server_app_usedvstotal.' Used
</div></div>';
}
?>
</div>
</body>
</html>