[英]PHP Jquery Flot Cpu usage
我如何最好地使用它?
可以用jquery圖表表示的CPU使用率?
我想到了jQuery Flot。
如何讓圖形自動更新?
希望你能給我提示。
問候
我的嘗試是,不幸的是,他只選擇了隨機值處理區域:
<?php
function get_server_cpu_usage(){
$load = sys_getloadavg();
return $load[0];
}
?>
<script>
$(function() {
var data1 = [];
var totalPoints = 300;
function GetData() {
data1.shift();
while (data1.length < totalPoints) {
var prev = data1.length > 0 ? data1[data1.length - 1] : 50;
var y = prev + <?=get_server_cpu_usage()?> * 10 - 5;
y = y < 0 ? 0 : (y > 100 ? 100 : y);
data1.push(y);
}
var result = [];
for (var i = 0; i < data1.length; ++i) {
result.push([i, data1[i]])
}
return result;
}
var updateInterval = 100;
var plot = $.plot($("#reatltime-chart #reatltime-chartContainer"), [
GetData()], {
series: {
lines: {
show: true,
fill: true
},
shadowSize: 0
},
yaxis: {
min: 0,
max: 100,
ticks: 10
},
xaxis: {
show: false
},
grid: {
hoverable: true,
clickable: true,
tickColor: "#f9f9f9",
borderWidth: 1,
borderColor: "#eeeeee"
},
colors: ["#79D1CF"],
tooltip: true,
tooltipOpts: {
defaultTheme: false
}
});
function update() {
plot.setData([GetData()]);
plot.draw();
setTimeout(update, updateInterval);
}
update();
});
</script>
我不知道如何使用jQuery,但是使用php和css我們可以做到這一點
(希望這就是您的要求)
<style>
.showbar {
width: 8px;
margin: 1px;
display: inline-block;
position: relative;
background-color: #aeaeae;
vertical-align: baseline;
}
</style>
<?php
$load = sys_getloadavg();//normally sometimes you'll get float points lessthan 1 so to show these values in bar just some value to make it positive so that you can see the bar
echo '<div style="height: '.($load[0]).
'em;" class="showbar"></div>'.($load[1]).
'<div style="height: '.($load[2]).
' class="showbar"></div>';
?>
樣本輸出
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.