无需任何环境,便可获取服务器磁盘、内存、负载、等相关使用情况。
使用方法
vim bbskali.sh #创建sh文件,将下面的代码复制到里面。
chmod+x bbskali.sh #添加运行权限
bash bbskali.sh
会在root
目录下生成bbskali.html
文件!浏览器打开即可!
效果
代码
#!/bin/bash
ip=`ifconfig |grep -w inet |grep inet|grep -v 127 |awk '{print $2}'`
a=`df -hT|grep -w "/"|awk '{print $1}'`
b=`df -hT|grep -w "/"|awk '{print $2}'`
c=`df -hT|grep -w "/"|awk '{print $3}'`
d=`df -hT|grep -w "/"|awk '{print $4}'`
e=`df -hT|grep -w "/"|awk '{print $5}'`
f=`df -hT|grep -w "/"|awk '{print $6}'`
g=`df -hT|grep -w "/"|awk '{print $7}'`
#free-h
neic=`free -h|grep -w "Mem"|awk '{print $1}'`
total=`free -h|grep -w "Mem"|awk '{print $2}'`
used=`free -h|grep -w "Mem"|awk '{print $3}'`
free=`free -h|grep -w "Mem"|awk '{print $4}'`
shared=`free -h|grep -w "Mem"|awk '{print $5}'`
cache=`free -h|grep -w "Mem"|awk '{print $6}'`
available=`free -h|grep -w "Mem"|awk '{print $7}'`
#fuzai
fuzai=`uptime |awk 'sub(/,/,"",$11)'|awk '{print $11}'`
cp=`df -hT|grep -w "/"| awk 'sub(/%/,"",$6)'|awk '{print $6}'`
nc1=`free |grep -w "Mem"|awk '{print $2}'`
nc2=`free |grep -w "Mem"|awk '{print $3}'`
html="<html>
<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">
<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css\" integrity=\"sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu\" crossorigin=\"anonymous\">
<script type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js\"></script>
<head>
<style type=\"text/css\">
.bian{
display: grid;
margin: 0 auto;
box-shadow: 0px 0px 20px -5px rgb(158 158 158 / 22%);
border-radius: 8px;
text-align: center;
background: #fff;
}
</style>
</head>
<body>
<div class=\"bian\">
<div class=\"panel panel-default\">
<div class=\"panel-body table-responsive \">
<div class=\"panel-heading\"><i class=\"glyphicon glyphicon-search\"></i>告警主机:$ip</div>
<div style=\"width: 350px;height: 350px; \">
<div id=\"container\" style=\"height: 90%;text-align: center;font-size: 8px;\"></div>
</div>
<table class=\"table table-bordered table-hover table-condensed\" align=center >
<tr class=\"active\">
<td>文件系统</td><td>类型</td><td>总共</td><td>已用</td><td>可用</td><td>使用率</td><td>挂载点</td>
</tr>
<tr class=\"warning\">
<td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td><td style=\"color:red;font-weight:bold\">$f</td><td>$g</td>
</tr>
<tr class=\"active\">
<td>Mem信息</td><td>总量</td><td>已用</td><td>剩余</td><td>交换</td><td>缓冲</td><td>可用</td>
</tr>
<tr class=\"danger\">
<td>$neic</td><td>$total</td><td>$used</td><td>$free</td><td>$shared</td><td style=\"color:red;font-weight:bold\">$cache</td><td>$available</td>
</tr>
</table>
</div>
</div>
</div>
<script type=\"text/javascript\">
var dom = document.getElementById(\"container\");
var myChart = echarts.init(dom);
var app = {};
var num =$nc2/$nc1;
num = num.toFixed(3)*100;
console.log(num);
var option;
const gaugeData = [
{
value: $fuzai*100,
name: '负载',
title: {
offsetCenter: ['0%', '-30%']
},
detail: {
valueAnimation: true,
offsetCenter: ['0%', '-20%']
}
},
{
value: num,
name: 'Mem使用率',
title: {
offsetCenter: ['0%', '0%']
},
detail: {
valueAnimation: true,
offsetCenter: ['0%', '10%']
}
},
{
value: $cp,
name: '磁盘使用率',
title: {
offsetCenter: ['0%', '30%']
},
detail: {
valueAnimation: true,
offsetCenter: ['0%', '40%']
}
}
];
option = {
series: [
{
type: 'gauge',
startAngle: 90,
endAngle: -270,
pointer: {
show: false
},
progress: {
show: true,
overlap: false,
roundCap: true,
clip: false,
itemStyle: {
borderWidth: 1,
borderColor: '#464646'
}
},
axisLine: {
lineStyle: {
width: 40
}
},
splitLine: {
show: false,
distance: 0,
length: 50
},
axisTick: {
show: false
},
axisLabel: {
show: false,
distance: 50
},
data: gaugeData,
title: {
fontSize: 12
},
detail: {
width: 50,
height: 12,
fontSize: 12,
color: 'auto',
borderColor: 'auto',
borderRadius: 20,
borderWidth: 1,
formatter: '{value}%'
}
}
]
};
if (option && typeof option === 'object') {
myChart.setOption(option);
}
</script>
</body>
</html>"
echo -e "$html" >/root/bbskali.html
``
### 后记
水平有限,不懂得地方请各位大佬赐教!
One comment
666收藏了