导航:[首页]->[other]->[使用rrdtool制作报表]

Sample

#!/bin/bash
declare -r file="./rrdtool.rrd"
declare -r timestamp="`date +%s`"
declare -r count=10

run()
{
    #echo -n "${1}"
    echo -n "$((RANDOM%100))"
}

rm -rf "${file}"
rrdtool create "${file}" \
    --step 1 \
    --start "${timestamp}" \
    DS:test:ABSOLUTE:1:U:U \
    RRA:AVERAGE:0.5:1:"${count}"

rrdtool info "${file}"

declare tmptime=""
for((i=1;i<count;i++))
do
    tmptime="$((timestamp + i))"
    rrdtool update "${file}" "${tmptime}:`run ${i}`"
done

rrdtool dump "${file}"
rrdtool first "${file}"
rrdtool last "${file}"

rm -rf "test.png"
rrdtool graph "test.png" \
        --start "${timestamp}" \
        --end "$((timestamp + count))" \
        DEF:Test="${file}":test:AVERAGE \
        LINE2:Test#FF0000

基本命令

root@qjw-VirtualBox:~# rrdtool  --help
RRDtool 1.4.7  Copyright 1997-2012 by Tobias Oetiker <tobi@oetiker.ch>
               Compiled Apr  2 2013 08:08:35

Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv,  dump, restore,
        last, lastupdate, first, info, fetch, tune,
        resize, xport, flushcached

RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)

For more information read the RRD manpages

重点参数

  1. step 取样周期
  2. start 起始时间点
  3. RRA::xff 由于RRA一个周期内,可能需要多次取样,所以xff定义若没有收到更新的次数比重低于多少,那么忽略
  4. RRA::steps 一个RRA周期需要更新的次数。
  5. RRA::rows RRA数据的大小
  6. RRA::cf 如何将多次请求合并成一个

The HEARTBEAT and the STEP

Here is an explanation by Don Baarda on the inner workings of RRDtool. It may help you to sort out why all this UNKNOWN data is popping up in your databases:

RRDtool gets fed samples/updates at arbitrary times. From these it builds Primary Data Points (PDPs) on every "step" interval. The PDPs are then accumulated into the RRAs.

The "heartbeat" defines the maximum acceptable interval between samples/updates. If the interval between samples is less than "heartbeat", then an average rate is calculated and applied for that interval. If the interval between samples is longer than "heartbeat", then that entire interval is considered "unknown". Note that there are other things that can make a sample interval "unknown", such as the rate exceeding limits, or a sample that was explicitly marked as unknown.

The known rates during a PDP's "step" interval are used to calculate an average rate for that PDP. If the total "unknown" time accounts for more than half the "step", the entire PDP is marked as "unknown". This means that a mixture of known and "unknown" sample times in a single PDP "step" may or may not add up to enough "known" time to warrant a known PDP.

The "heartbeat" can be short (unusual) or long (typical) relative to the "step" interval between PDPs. A short "heartbeat" means you require multiple samples per PDP, and if you don't get them mark the PDP unknown. A long heartbeat can span multiple "steps", which means it is acceptable to have multiple PDPs calculated from a single sample. An extreme example of this might be a "step" of 5 minutes and a "heartbeat" of one day, in which case a single sample every day will result in all the PDPs for that entire day period being set to the same average rate.

参考

  1. http://oss.oetiker.ch/rrdtool/doc/index.en.html
  2. http://blog.csdn.net/ysuncn/article/details/1728709