自定义Ganglia集群图 - 如何显示平均指标值,而不是总指标值

时间:2012-08-17 00:45:25

标签: rrdtool ganglia

如何在自定义图表中显示平均值,而不是总值?

以前我通过创建自定义.php文件生成集群摘要图表已经成功,如下所述:

http://sourceforge.net/apps/trac/ganglia/wiki/Custom_graphs

但是,到目前为止,我想要显示给定指标的每秒总动作数。但现在,我有一些时序数据,我想显示所有集群节点的平均(平均)度量值。这是怎么做到的?在我当前的实现中,生成的图表显示了所有节点的总时间值,这没有用。

这是.php:

<?php

/* Pass in by reference! */
function graph_jmx_times_report ( &$rrdtool_graph ) { 

    global $context,
           $hostname,
           $graph_var,
           $range,
           $rrd_dir,
           $size,
           $strip_domainname;

    if ($strip_domainname) {
       $hostname = strip_domainname($hostname);
    }   

    $jmx = $graph_var;
    $title = $jmx.' Processing Time';
    if ($context != 'host') {
       $rrdtool_graph['title'] = $title;
    } else {
       $rrdtool_graph['title'] = "$hostname $title last $range";
    }   
    $rrdtool_graph['lower-limit']    = '0';
    $rrdtool_graph['vertical-label'] = 'milliseconds';
        $rrdtool_graph['extras']         = '--rigid --base 1024';
    $rrdtool_graph['height'] += ($size == 'medium') ? 89 : 0;

        $series = "DEF:'tot_time'='${rrd_dir}/jmx_tomcat_proc_time_ms.rrd':'sum':AVERAGE"
                ."DEF:'fc_time'='${rrd_dir}/jmx_tomcat_freqcap_lookup_time_75.rrd':'sum':AVERAGE "
                ."DEF:'ro_time'='${rrd_dir}/jmx_tomcat_readonly_lookup_time_75.rrd':'sum':AVERAGE "
                ."DEF:'rt_time'='${rrd_dir}/jmx_tomcat_realtime_lookup_time_75.rrd':'sum':AVERAGE "
                ."AREA:'tot_time'#CFF1FC:'' "
                ."LINE2:'fc_time'#F19A2A:'Freq Cap 75' "
                ."LINE2:'ro_time'#66CC33:'Read-only 75' "
                ."LINE2:'rt_time'#CC99CC:'Realtime 75' "
                ."LINE2:'tot_time'#20ABD9:'Processing Time' "
        ;

    $rrdtool_graph['series'] = $series;

    return $rrdtool_graph;

}

?>

1 个答案:

答案 0 :(得分:3)

除了num数据源之外,Ganglia使用的摘要RRD还包含sum数据源。 num值表示sum的计算主机数,仅在摘要RRD中可用。

您可以使用RRDtool CDEF指令通过将sum除以num来计算所有主机的平均值。

以下是一个例子:

if ($context != 'host') { // cluster or grid summary graph context
    $series = 
     "'DEF:fc_time_sum=${rrd_dir}/jmx_tomcat_freqcap_lookup_time_75.rrd:sum:AVERAGE' " 
    ."'DEF:fc_time_num=${rrd_dir}/jmx_tomcat_freqcap_lookup_time_75.rrd:num:AVERAGE' " 
    ."'CDEF:avg_fc_time=fc_time_sum,fc_time_num,/' " 
    ."'LINE2:avg_fc_time#0000FF:Average Freq Cap 75' ";
} else { // single host graph context
    //here you can't use the num data source
}

此平均值也显示在ganglia-web附带的sample_report.php文件中。