随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

一.在/opt/lampp/htdocs/lepus/application/controllers/lp_os.php 文件中添加,目的是让chart_reslut中有内存数据mem_total、mem_avail、mem_cached、swap_total、swap_avail (名字对应数据库中 os_status_history表中 相应的字段名):

在181行后处插入如下代码:

                $chart_reslut[$i]['mem_total'] = $dbdata['mem_total'];
                $chart_reslut[$i]['mem_avail'] = $dbdata['mem_avail'];
                $chart_reslut[$i]['mem_cached'] = $dbdata['mem_cached'];
                $chart_reslut[$i]['swap_total'] = $dbdata['swap_total'];
                $chart_reslut[$i]['swap_avail'] = $dbdata['swap_avail'];

 

二、在/opt/lampp/htdocs/lepus/application/views/os/chart.php中插入代码

插入代码1:在39行后插入如下代码,目的是在详情页中插入两个层,分别用来存放统计内存和缓存的图表:

<div id="memory" style="margin-top:5px; margin-left:10px; width:96%; height:300px; "></div>
<div id="swap" style="margin-top:5px; margin-left:10px; width:96%; height:300px; "></div>

插入代码2:在241行后插入如下代码,目的是在上面的两个层上分别画内存和缓存统计图(单位是KB):

复制代码
//memory start
$(document).ready(function(){
  var data1=[
    <?php if(!empty($chart_reslut)) { foreach($chart_reslut as $item){ ?>
    ["<?php echo $item['time']?>", <?php echo $item['mem_cached']?> ],
    <?php }}else{ ?>
    []   
    <?php } ?>
  ];
  var data2=[
    <?php if(!empty($chart_reslut)) { foreach($chart_reslut as $item){ ?>
    ["<?php echo $item['time']?>", <?php echo $item['mem_total']?> ],
    <?php }}else{ ?>
    []   
    <?php } ?>
  ];
  var data3=[
    <?php if(!empty($chart_reslut)) { foreach($chart_reslut as $item){ ?>
    ["<?php echo $item['time']?>", <?php echo $item['mem_avail']?> ],
    <?php }}else{ ?>
    []   
    <?php } ?>
  ];
  var plot1 = $.jqplot('memory', [data1,data2,data3], {
    seriesDefaults: {
              show: true,     // 设置是否渲染整个图表区域(即显示图表中内容) 
              xaxis: 'xaxis', // either 'xaxis' or 'x2axis'. 
              yaxis: 'yaxis', // either 'yaxis' or 'y2axis'. 
              label: '',      // 用于显示在分类名称框中的分类名称 
              color: '',      // 分类在图标中表示(折现,柱状图等)的颜色 
              lineWidth: 1.5, // 分类图(特别是折线图)宽度 
              shadow: true,   // 各图在图表中是否显示阴影区域 
              shadowAngle: 45,    // 参考grid中相同参数 
              shadowOffset: 1.25, // 参考grid中相同参数 
              shadowDepth: 3,     // 参考grid中相同参数 
              shadowAlpha: 0.1,   // 参考grid中相同参数 
              showLine: true,     //是否显示图表中的折线(折线图中的折线) 
              showMarker: false,   // 是否强调显示图中的数据节点 
              fill: false,        // 是否填充图表中折线下面的区域(填充颜色同折线颜色)以及legend
              rendererOptions: {
                 smooth: true,
              }
    },
    series:[//如果有多个分类需要显示,这在此处设置各个分类的相关配置属性 
           //eg.设置各个分类在分类名称框中的分类名称 
            {label: '<?php echo $this->lang->line('cached'); ?>'},{label: '<?php echo $this->lang->line('total'); ?>'},{label: '<?php echo $this->lang->line('avail'); ?>'}
           //配置参数设置同seriesDefaults 
    ], 
    legend: { 
        show: true, //设置是否出现分类名称框(即所有分类的名称出现在图的某个位置)
        label:'123',
        location: 'ne',     // 分类名称框出现位置, nw, n, ne, e, se, s, sw, w. 
        xoffset: 12,        // 分类名称框距图表区域上边框的距离(单位px) 
        yoffset: 12,        // 分类名称框距图表区域左边框的距离(单位px) 
        background:'',        //分类名称框距图表区域背景色 
        textColor:''          //分类名称框距图表区域内字体颜色 
    }, 
    seriesColors: [ "#ff5800", "#EAA228", "#00CC00", "#839557", "#958c12",  
        "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],  // 默认显示的分类颜色 
    title:{
         text:"<?php echo $cur_host; ?> <?php echo $this->lang->line('memory'); ?> <?php echo $this->lang->line('chart'); ?>",
         show:true,
         fontSize:'13px',
         textColor:'#666',
    },
   
    axes:{
        xaxis:{
            renderer:$.jqplot.DateAxisRenderer,
            tickOptions:{formatString:"<?php echo $chart_option['formatString']; ?>"},
            tickInterval:"",
            label: "",
        },
        yaxis: { 
                renderer: $.jqplot.LogAxisRenderer,
                tickOptions:{ suffix: '' }
        }
    },
    highlighter: {
            show: true,
            showLabel: true,
            tooltipAxes: '',
            sizeAdjust: 7.5 , tooltipLocation : 'ne'
    },
    cursor:{
            show: true,
            zoom: true
    }
  
  });
});
//memoey end
//swap start
$(document).ready(function(){
  var data1=[
    <?php if(!empty($chart_reslut)) { foreach($chart_reslut as $item){ ?>
    ["<?php echo $item['time']?>", <?php echo $item['swap_avail']?> ],
    <?php }}else{ ?>
    []   
    <?php } ?>
  ];
  var data2=[
    <?php if(!empty($chart_reslut)) { foreach($chart_reslut as $item){ ?>
    ["<?php echo $item['time']?>", <?php echo $item['swap_total']?> ],
    <?php }}else{ ?>
    []   
    <?php } ?>
  ];
  var plot1 = $.jqplot('swap', [data1,data2], {
    seriesDefaults: {
              show: true,     // 设置是否渲染整个图表区域(即显示图表中内容) 
              xaxis: 'xaxis', // either 'xaxis' or 'x2axis'. 
              yaxis: 'yaxis', // either 'yaxis' or 'y2axis'. 
              label: '',      // 用于显示在分类名称框中的分类名称 
              color: '',      // 分类在图标中表示(折现,柱状图等)的颜色 
              lineWidth: 1.5, // 分类图(特别是折线图)宽度 
              shadow: true,   // 各图在图表中是否显示阴影区域 
              shadowAngle: 45,    // 参考grid中相同参数 
              shadowOffset: 1.25, // 参考grid中相同参数 
              shadowDepth: 3,     // 参考grid中相同参数 
              shadowAlpha: 0.1,   // 参考grid中相同参数 
              showLine: true,     //是否显示图表中的折线(折线图中的折线) 
              showMarker: false,   // 是否强调显示图中的数据节点 
              fill: false,        // 是否填充图表中折线下面的区域(填充颜色同折线颜色)以及legend
              rendererOptions: {
                 smooth: true,
              }
    },
    series:[//如果有多个分类需要显示,这在此处设置各个分类的相关配置属性 
           //eg.设置各个分类在分类名称框中的分类名称 
            {label: '<?php echo $this->lang->line('avail'); ?>'},{label: '<?php echo $this->lang->line('total'); ?>'}
           //配置参数设置同seriesDefaults 
    ], 
    legend: { 
        show: true, //设置是否出现分类名称框(即所有分类的名称出现在图的某个位置)
        label:'123',
        location: 'ne',     // 分类名称框出现位置, nw, n, ne, e, se, s, sw, w. 
        xoffset: 12,        // 分类名称框距图表区域上边框的距离(单位px) 
        yoffset: 12,        // 分类名称框距图表区域左边框的距离(单位px) 
        background:'',        //分类名称框距图表区域背景色 
        textColor:''          //分类名称框距图表区域内字体颜色 
    }, 
    seriesColors: [ "#00CC00", "#EAA228", "#ff5800", "#839557", "#958c12",  
        "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],  // 默认显示的分类颜色 
    title:{
         text:"<?php echo $cur_host; ?> <?php echo $this->lang->line('swap'); ?> <?php echo $this->lang->line('chart'); ?>",
         show:true,
         fontSize:'13px',
         textColor:'#666',
    },
   
    axes:{
        xaxis:{
            renderer:$.jqplot.DateAxisRenderer,
            tickOptions:{formatString:"<?php echo $chart_option['formatString']; ?>"},
            tickInterval:"",
            label: "",
        },
        yaxis: { 
                renderer: $.jqplot.LogAxisRenderer,
                tickOptions:{ suffix: '' }
        }
    },
    highlighter: {
            show: true,
            showLabel: true,
            tooltipAxes: '',
            sizeAdjust: 7.5 , tooltipLocation : 'ne'
    },
    cursor:{
            show: true,
            zoom: true
    }
  
  });
});
//swap end
复制代码

 

详细指导参考:https://www.cnblogs.com/jingzaixin/p/11867908.html

posted on   大话人生  阅读(214)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示