rrdtool
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| rrdtool [2018/12/06 21:05] – created 91.177.234.129 | rrdtool [2019/01/30 11:32] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ==== Compact, simple example |
| + | === Data Source | ||
| + | < | ||
| + | free -m | ||
| + | | ||
| + | Mem: | ||
| - | =====Compact, | + | - Total |
| - | ====Data Source==== | + | free -m | grep Mem | awk '{print $2}' |
| - | < | + | 499 |
| - | ====Create a database==== | + | |
| - | < | + | |
| - | ====Update the database and print out the latest graph==== | + | |
| - | < | + | |
| - | ====Schedule this shell to run on a regular basis==== | + | |
| - | < | + | |
| - | =====A more involved example===== | + | - Used |
| - | < | + | free -m | grep Mem | awk ' |
| + | 65 | ||
| + | </ | ||
| + | === Create a database | ||
| + | < | ||
| + | rrdtool create / | ||
| + | </ | ||
| + | === Update the database and print out the latest graph === | ||
| + | < | ||
| + | - !/bin/bash | ||
| - | =====Display information about the database===== | + | - update data |
| - | < | + | mem_used=`free -m | grep Mem | awk ' |
| - | =====Print out the data in the database===== | + | /usr/ |
| - | < | + | |
| - | =====Export a part of the data in the RRA in JSON or XML format===== | + | - create graph |
| + | / | ||
| + | -w 500 -h 150 -a PNG \\ | ||
| + | --slope-mode | ||
| + | --start -3600 --end now \\ | ||
| + | --font DEFAULT: | ||
| + | --title " | ||
| + | --watermark " | ||
| + | --x-grid MINUTE: | ||
| + | --alt-y-grid | ||
| + | --rigid | ||
| + | --lower-limit=0 \\ | ||
| + | --color BACK# | ||
| + | --color CANVAS# | ||
| + | --color GRID# | ||
| + | --color MGRID# | ||
| + | --color FONT# | ||
| + | DEF: | ||
| + | AREA: | ||
| + | LINE1: | ||
| + | GPRINT: | ||
| + | GPRINT: | ||
| + | GPRINT: | ||
| + | GPRINT: | ||
| + | </ | ||
| + | === Schedule this shell to run on a regular basis === | ||
| + | < | ||
| + | crontab -l | ||
| + | * /5 * * * * / | ||
| + | </ | ||
| + | |||
| + | ==== A more involved example ==== | ||
| + | < | ||
| + | - !/ | ||
| + | - ============================================================================== | ||
| + | - Name : dbamon_grapher.ksh | ||
| + | - Description | ||
| + | - | ||
| + | - Parameters | ||
| + | - | ||
| + | - Notes : Only as ' | ||
| + | - | ||
| + | - Modification History | ||
| + | - ==================== | ||
| + | - When Who | ||
| + | - ========= ================= ================================================== | ||
| + | - 06-DEC-13 Stuart Barkley | ||
| + | - ============================================================================== | ||
| + | |||
| + | CWD=`dirname $0` | ||
| + | |||
| + | - name of the file to process | ||
| + | COLLECTOR_DIR="/ | ||
| + | COLLECTOR_FILES=${COLLECTOR_DIR}/" | ||
| + | RRDTOOL="/ | ||
| + | RRDDIR="/ | ||
| + | PNGDIR="/ | ||
| + | |||
| + | - ======================================= | ||
| + | - thats it, nothing to change below here! | ||
| + | - ======================================= | ||
| + | |||
| + | |||
| + | function cre_export_duration { | ||
| + | rrd_dir=$1 | ||
| + | rrdname=$2 | ||
| + | $RRDTOOL create ${rrd_dir}/ | ||
| + | --start 1384000000 | ||
| + | -s 86400 \\ | ||
| + | DS: | ||
| + | DS: | ||
| + | RRA: | ||
| + | if [[ $? -ne 0 ]]; then | ||
| + | echo " | ||
| + | return 1 | ||
| + | fi | ||
| + | - echo " | ||
| + | return 0 | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | rm -f $RRDDIR/ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | - create the rrd databases | ||
| + | - ------------------------ | ||
| + | for statfile in `ls -t ${COLLECTOR_FILES}` | ||
| + | do | ||
| + | IFS=" | ||
| + | exec 0< | ||
| + | while read host db type started stopped | ||
| + | do | ||
| + | [[ " | ||
| + | rrdfile=" | ||
| + | ls ${RRDDIR}/ | ||
| + | if [[ $? -ne 0 ]]; then | ||
| + | cre_export_duration " | ||
| + | fi | ||
| + | done | ||
| + | done | ||
| + | |||
| + | |||
| + | - --------------------------------------------- | ||
| + | - update the rrd databases with the latest data | ||
| + | - --------------------------------------------- | ||
| + | for statfile in `ls -t ${COLLECTOR_FILES}` | ||
| + | do | ||
| + | - echo " | ||
| + | cat $statfile | sort -nk4 | while IFS=\\| read host db type started stopped | ||
| + | do | ||
| + | [[ " | ||
| + | rrdfile=" | ||
| + | $RRDTOOL update ${RRDDIR}/ | ||
| + | [[ $? -ne 0 ]] && echo "nok: $?" | ||
| + | done | ||
| + | done | ||
| + | |||
| + | |||
| + | - rrdtool fetch / | ||
| + | |||
| + | |||
| + | - --color BACK#996 \\ # the bit where the title is written | ||
| + | - --color CANVAS#996 \\ # the background to the graph area | ||
| + | - --color GRID#0000FF \\ # the grid lines (graph paper) | ||
| + | - --color MGRID# | ||
| + | - --color FONT#CCCCCC \\ | ||
| + | |||
| + | |||
| + | for statfile in `ls -t ${COLLECTOR_FILES}` | ||
| + | do | ||
| + | awk -F' | ||
| + | do | ||
| + | echo " | ||
| + | [[ " | ||
| + | $RRDTOOL graph ${PNGDIR}/ | ||
| + | -a PNG \\ | ||
| + | -s " | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | ' | ||
| + | done | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | ==== Display information about the database ==== | ||
| + | < | ||
| + | rrdtool info < | ||
| + | eg: | ||
| + | rrdtool info export_duration_wdcrhbp05_ARISPPMP.rrd | ||
| + | </ | ||
| + | ==== Print out the data in the database ==== | ||
| + | < | ||
| + | rrdtool fetch < | ||
| + | eg: | ||
| + | rrdtool fetch export_duration_wdcrhbp05_ARISPPMP.rrd AVERAGE --start now-100000 | ||
| + | </ | ||
| + | |||
| + | ==== Export a part of the data in the RRA in JSON or XML format ==== | ||
| Most of these parameters are the same as those used to graph the data | Most of these parameters are the same as those used to graph the data | ||
| - | < | + | < |
| + | rrdtool xport --json -s now-1month DEF: | ||
| + | </ | ||
| or | or | ||
| - | < | + | < |
| + | rrdtool xport -s now-1month DEF: | ||
| + | </ | ||
| and trim the results to bare data | and trim the results to bare data | ||
| - | < | + | < |
| + | cat xport.xml | grep '< | ||
| + | </ | ||
| - | =====Delete entry in rrd database===== | + | ==== Delete entry in rrd database ==== |
| This function is not (yet) available and so the best work-around is: | This function is not (yet) available and so the best work-around is: | ||
| - | * Use RRDTool Dump to export RRD file to XML | + | * Use RRDTool Dump to export RRD file to XML |
| - | * Open the XML file, find and edit the bad data | + | * Open the XML file, find and edit the bad data |
| - | * Restore the RRD file using RRDTool Restore | + | * Restore the RRD file using RRDTool Restore |
| - | < | + | < |
| + | rrdtool dump filename.rrd [[filename.xml]] [[--header|-h {none, | ||
| + | eg: | ||
| + | rrdtool dump export_duration_wdcrhbp05_ARISPPMP.rrd dumped.xml | ||
| + | </ | ||
| and | and | ||
| - | < | + | < |
| + | rrdtool restore filename.xml filename.rrd [[--range-check|-r]] [[--force|-f]] | ||
| + | eg: | ||
| + | rrdtool restore dumped.xml export_duration_wdcrhbp05_ARISPPMP.rrd -f | ||
| + | </ | ||
| + | |||
| + | ==== References ==== | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| - | =====References===== | ||
| - | * [[http:// | ||
| - | * [[http:// | ||
| - | * [[http:// | ||
| - | * [[http:// | ||
rrdtool.1544130327.txt.gz · Last modified: 2018/12/06 21:05 by 91.177.234.129
