weixin_33724570 2014-05-04 12:50 采纳率: 0%
浏览 23

PHP Jquery Flot Cpu使用情况

how do I use it to best?

can be represented by jquery chart the CPU usage?

I thought of jquery Flot.

How do I let the graphics automatically update?

Hope you can give me tips.

greeting

My attempt, unfortunately he only chooses random values processed area:

<?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>
  • 写回答

1条回答 默认 最新

  • 狐狸.fox 2014-05-04 13:13
    关注

    i dont know how to do with jquery,but using php and css we can do this

    (hope this is what you are asking)

    <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>';
    ?>
    

    sample output

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮