class RRD

{

//rrdtool 执行权限

private $rrdBinPath = '/usr/bin/rrdtool';

//rrd文件地址

private $rrdFile;

//默认开始时间从2000年的1月1号

private $rrdStart = 946656000;

//默认时间间隔是300秒(5分钟)

private $rrdStep = 300;

private $rrdDsname = array('dsname');

//rrdtool生成的图片地址

private $graphFile;

private $graphWidth = 800;

private $graphHeight = 400;

private $graphLineColor = array('#473C8B', '#66CDAA',

'#A0522D', '#EE3A8C','#CD0000');

public function __construct($rrdFile, $graphFile,

$rrdBinPath='')

{

$this->rrdFile = $rrdFile;

$this->graphFile = $graphFile;

if($rrdBinPath)

{

$this->rrdBinPath = $rrdBinPath;

}

}

public function rrdCreate($rrdStart=0, $rrdStep=0,

$rrdDsname=array(), $debug=0)

{

if($rrdStart > 0)

{

$this->rrdStart = $rrdStart;

}

if($rrdStep > 0)

{

$this->rrdStep = $rrdStep;

}

if(count($rrdDsname) > 0)

{

$this->rrdDsname = $rrdDsname;

}

$dsCommand = '';

foreach ($this->rrdDsname as $dsname)

{

$dsCommand .= "DS:{$dsname}:GAUGE:600:0:U ";

}

$command = "{$this->rrdBinPath} create {$this->rrdFile}

--start {$this->rrdStart} --step {$this->rrdStep}

{$dsCommand} RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:4:600

RRA:AVERAGE:0.5:24:600 RRA:AVERAGE:0.5:288:730";

return $this->execCommand($command, $debug);

}

public function rrdUpdate($timestamp, $data=array(),

$debug=0)

{

if($data && $timestamp > 0)

{

$dsCommand = "";

$valueCommand = "";

foreach($data as $dsname=>$value)

{

if(is_int($dsname))

{

$dsname = $this->rrdDsname[$dsname];

}

$dsCommand .= $dsname.":";

$valueCommand .= $value.":";

}

$dsCommand = substr($dsCommand, 0, -1);

$valueCommand = substr($valueCommand, 0, -1);

$command = "{$this->rrdBinPath} update {$this->rrdFile}

-t {$dsCommand} {$timestamp}:{$valueCommand}";

return $this->execCommand($command, $debug);

}

else

{

return 'ERROR_01';

}

}

public function rrdGraph($s, $e, $rrdDsname=array(), $option =

array(), $debug=0)

{

if(isset($option['with']) && intval($option['with'])

> 0)

{

$this->graphWidth = $option['with'];

}

if(isset($option['height']) &&

intval($option['height']) > 0)

{

$this->graphHeight = $option['height'];

}

if(!$rrdDsname)

{

$rrdDsname = $this->rrdDsname;

}

$defCommand = '';

$lineCommand = '';

foreach ($rrdDsname as $dsname)

{

if(strpos($dsname, ':') !== false)

{

$tempArr = explode(':', $dsname);

$tempDsname = $tempArr[0];

$tempLineColor = $tempArr[1];

$defCommand .=

"DEF:my{$tempDsname}='{$this->rrdFile}':{$tempDsname}:AVERAGE

VDEF:myaverage=my{$tempDsname},AVERAGE

VDEF:mymax=my{$tempDsname},MAXIMUM ";

$lineCommand .=

"LINE:my{$tempDsname}".$tempLineColor.":'".$tempDsname."'

".'GPRINT:myaverage'.$tempDsname.':"AVERAGE\:%6.0lf"

GPRINT:mymax'.$tempDsname.':"MAXIMUM\:%6.0lf\n" ';

}

else

{

$defCommand .=

"DEF:my{$dsname}='{$this->rrdFile}':{$dsname}:AVERAGE

VDEF:myaverage{$dsname}=my{$dsname},AVERAGE

VDEF:mymax{$dsname}=my{$dsname},MAXIMUM ";

$lineCommand .=

"LINE:my{$dsname}".array_pop($this->graphLineColor).":'".$dsname."'

".'GPRINT:myaverage'.$dsname.':"AVERAGE\:%6.0lf"

GPRINT:mymax'.$dsname.':"MAXIMUM\:%6.0lf\n" ';

}

}

$command = "{$this->rrdBinPath} graph {$this->graphFile}

--start {$s} --end {$e} {$defCommand} {$lineCommand} -w

{$this->graphWidth} -h {$this->graphHeight}";

return $this->execCommand($command, $debug);

}

private function execCommand($command, $debug)

{

if($debug !== 0)

{

echo $command;

}

system($command, $result);

if($result === 0)

{

return true;

}

else

{

return 'ERROR_02';

}

}

}

rrdtool php 绘图,PHP封装RRDTool的操作相关推荐

  1. python菜鸟excel教程-Python菜鸟之路: 封装通用excel操作

    前言 最近工作常要干些excel导入导出的活,用python来做最方便,写的多了,就想封装下读写的操作,后续通用,python菜鸟,大佬轻喷(不服可以来写Java ....当我没说) 设计 1.pyt ...

  2. 在数据仓储的情况下进一步封装数据库基础操作,此版本为异步版本

    1 /// <summary> 2 /// 在数据仓储的情况下进一步封装数据库基础操作,此版本为异步版本 Created by ZhangQC 2016.08.17 3 /// </ ...

  3. python cartopy绘制北极/python绘图函数封装/python气象绘图

    因为研究需要大量出图,于是将常用的绘图函数封装,提高绘图效率. 绘图函数 函数主要有两部分组成: 1.完成解决北极投影重叠的z_masked函数,详情参见python cartopy极地投影重叠解决 ...

  4. php精辟代码欣赏,数据库操作类,封装所有数据库操作

    下面是php各种代码库,个人分享 <?php //******************************************************************* //此处 ...

  5. Python封装MySQL数据库操作(pymysql)

    Python封装MySQL数据库操作(pymysql) # 连接MySQL class DbManager(object):# 构造函数def __init__(self):self.conn = N ...

  6. 使用RRDTOOL进行绘图

    如果您不熟悉RRDTOOL,可以先参看前面的RRDTOOL入门,简单来说,RRDTOOL不仅仅是数据库工具,它还是一种强大的前端绘图工具,可以直接根据所存的数据绘出复杂的图形.其绘图主要使用graph ...

  7. rrdtool php 绘图,利用PHP的Popen实现RRDTOOL作图的动态输出

    error_reporting(E_ALL); //作图命令,注意看 graph 后面加了一个连接符 $command = '/opt/rrdtool/bin/rrdtool graph - --st ...

  8. 【python科研绘图】封装接口直接利用DataFrame绘制百分比堆叠柱状图

    封装接口直接利用DataFrame绘制百分比柱状图 1. 背景前言 2. 官方网址示例 2.1 matplotlib_percentage_stacked_bar_plot 2.2 percent-s ...

  9. interface IEngineControl封装引擎通用操作

    using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace SIAT ...

最新文章

  1. PyTorch Tricks 集锦
  2. 【Python学习】 - Pandas包,对于describe函数和mean函数求平均值的效率问题
  3. 前端基础:初步认识Chrome调试面板,学会简单的代码调试,必会!
  4. springboot 日志级别_SpringBoot实战(十三):Admin动态修改日志级别
  5. 【杂文】从实习到校招到工作
  6. 4.Linux性能诊断 --- Linux工作流程内存管理
  7. Chrome浏览器插件之---AdBlock和Adblock Plus
  8. 思科路由视频_HCNA-HNTD(H12-211)中文题库H10.24
  9. 城市大脑一网统管数据中台建设方案
  10. MediaCreationTool2004 U盘安装系统
  11. asp中 打开网页时出现“操作必须使用一个可更新的查询”原因及解决办法
  12. 如何准备机器学习工程师的面试 ?
  13. windows环境下C++实现的多种目录监控和优劣解析
  14. 阿里巴巴全球化测试技术介绍
  15. Kylin高级主题-Cube构建算法介绍(逐层算法和快速算法)
  16. 艾司博讯:拼多多诱导非官方交易怎么处理?
  17. LabVIEW 通讯与罗克韦尔 AB Allen Bradley PLC通讯 EhernetIP 网口TCP标签通讯 SL500实测通过
  18. pycharm跑代码时警告libpng warning: iCCP: known incorrect sRGB profile
  19. delphi android 打印机,用delphi控制小票打印机打印图片
  20. Adobe illustrator 输入数学平方公式

热门文章

  1. 虚伪的友情再见!!!!
  2. 由微软13校招加密题引申
  3. 注册Live.com信箱--第四波 Live信箱注册又现漏洞
  4. flash转为html5工具
  5. 2020年的Java程序员面试三件套:多线程+算法,看完吊打面试官
  6. 湖北职称英语和计算机考试,湖北取消职称英语考试了吗
  7. 回忆PHTOTSHOP技巧-复制技巧篇
  8. 不知道wifi密码时, 笔记本怎么连接到网络?
  9. Python_Monkeyrunner
  10. 音乐,是打开心灵的钥匙