- コマンドで使用
rrdtool graph
してPRINT
、データ ソースの標準偏差を取得します ( stdev_array
)
- 選別
stdev_array
- の順に積み上げてグラフ化
stdev_array
これは PHP のコードですが、どの言語でも実行できます。
RRDtool 1.4.5 を使用
しています$rrd_path
(rrd ファイルへのパス)、$img_path
(イメージを書き込むパス)、$data_sources
(DS 名の配列、RRD の構築方法によって異なります)、$rrd_colors
(の配列ヘキサカラー)。
$rrd_colors_count = count($rrd_colors);
$stdev_command = "rrdtool graph /dev/null ";
foreach ($data_sources as $index => $ds_name)
{
$stdev_command .= "DEF:serv$index=$rrd_path:$ds_name:AVERAGE ";
$stdev_command .= "VDEF:stdev$index=serv$index,STDEV PRINT:stdev$index:%lf ";
}
exec($stdev_command, $stdev_order, $ret);
if ($ret === 0)
{
array_shift($stdev_order); // remove first useless line "0x0" (may depend on your rrdtool version?)
asort($stdev_order); // sort by standard deviation keeping the indexes
}
else $stdev_order = $data_sources; // backup in case $stdev_command failed
$graph_command = "rrdtool graph $img_path ";
$graph_command .= "AREA:0 ";
foreach ($stdev_order as $index => $useless)
{
$ds_name = $data_sources[$index];
$graph_command .= "DEF:line$index=$rrd_path:$ds_name:AVERAGE ";
$graph_command .= "STACK:line$index" . $rrd_colors[$index%$rrd_colors_count].' ';
}
exec($graph_command, $out, $ret);
// check $ret (and $out) to see if all is good