gpt4 book ai didi

PERL RRDTTOL : graph subroutine with conditional legend

转载 作者:行者123 更新时间:2023-12-02 03:53:49 25 4
gpt4 key购买 nike

愚蠢的事情我无法管理...

在 Perl 中,我使用 RRDTool(rrds 模块)创建了一个通用子例程来创建不同时间段(1 天、1 周...)的图表。我想使用一些子参数来显示可选图例。

使用以下代码,不会生成任何图形....

#!/usr/bin/perl
use strict;
use OWNet;
use RRDs;
use warnings;
use diagnostics;

my $rrd = '/var/rrd/electricite.rrd';
my $img = '/mnt/ds211/web/';

&CreateGraph("conso","Consommation electrique 1 heure","1h",1);

sub CreateGraph
# inputs: $_[0]: sensor_rrd_name
# $_[1]: chart title
# $_[2]: interval period (1h,24h,7d,1m,1y,10y)
# $_[3]: Puissance instantanee (1/0)
{
my $temp_graph;
$temp_graph ="\"$img$_[0]-$_[2].png\",";
$temp_graph .="\"--start=end-$_[2]\",";
$temp_graph .="\"--end=now\",";
$temp_graph .="\"--width=600\",";
$temp_graph .="\"--height=200\",";
$temp_graph .="\"--slope-mode\",";
$temp_graph .="\"--title=$_[1]\",";
$temp_graph .="\"--vertical-label=Watt\",";
$temp_graph .="\"--lower-limit=0\",";
$temp_graph .="\"--alt-autoscale-max\",";
$temp_graph .="\"DEF:energy=$rrd:$_[0]:AVERAGE\",";
$temp_graph .="\"CDEF:Watt=energy,3600,*\",";
$temp_graph .="\"LINE2:Watt#0000FF:\",";
$temp_graph .="\"AREA:Watt#00FF00:\",";
$temp_graph .="\"VDEF:WattHour=energy,TOTAL\",";

if ($_[3]==1)
{
$temp_graph .="\"GPRINT:Watt:LAST: Puissance instantanee\\: %6.2lf%sW\",";
}

$temp_graph .="\"GPRINT:WattHour: Consommation totale\\: %6.2lf%sWh\\n\",";
$temp_graph .="\"GPRINT:Watt:MIN: Puissance min\\: %6.2lf%sW\",";
$temp_graph .="\"GPRINT:Watt:AVERAGE: Puissance moyenne\\: %6.2lf%sW\",";
$temp_graph .="\"GPRINT:Watt:MAX: Puissance max\\: %6.2lf%sW\"";

RRDs::graph ("$temp_graph");

if ($ERROR = RRDs::error)
{
print "$0: failed to generate graph $_[0] data into rrd: $ERROR\n";
}
}

谢谢

最佳答案

问题是您向 rrdtool 传递一个字符串而不是带有参数的数组。

代替

RRDs::graph ("\"graph.gif\",\"DEF:...\" ...");

你应该打电话

RRDs::graph ("graph.gif","DEF:...","...");`

如果你想事先准备好你的论点,那么你可以使用

my @args = ("graph.gif","DEF:...","...")
RRDs::graph(@args);

希望这对您有所帮助。

关于PERL RRDTTOL : graph subroutine with conditional legend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com