User Tools

Site Tools


rrdtool

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
rrdtool [2018/12/08 12:49] – created 0.0.0.0rrdtool [2019/01/30 11:32] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== RRDTool ======+==== Compact, simple example ==== 
 +=== Data Source === 
 +<code> 
 +free -m 
 +             total       used       free     shared    buffers     cached 
 +Mem:           499        214        284          0          2        169
  
-=====Compact, simple example===== +  -  Total 
-====Data Source==== +free -m | grep Mem | awk '{print $2}' 
-<code>0@@</code> +499
-====Create a database==== +
-<code>1@@</code> +
-====Update the database and print out the latest graph==== +
-<code>2@@</code> +
-====Schedule this shell to run on a regular basis==== +
-<code>3@@</code>+
  
-=====A more involved example===== +  -  Used 
-<code>4@@</code>+free -m | grep Mem | awk '{print $3}' 
 +65 
 +</code> 
 +=== Create a database === 
 +<code> 
 +rrdtool create /root/mem.rrd --step 60 DS:mem:GAUGE:120:0:499 RRA:MAX:0.5:1:31622400 
 +</code> 
 +=== Update the database and print out the latest graph === 
 +<code> 
 +  - !/bin/bash
  
-=====Display information about the database===== +  -  update data 
-<code>5@@</code> +mem_used=`free -m | grep Mem | awk '{print $3}'` 
-=====Print out the data in the database===== +/usr/bin/rrdtool update /root/mem.rrd --template mem N:$mem_used
-<code>6@@</code>+
  
-=====Export a part of the data in the RRA in JSON or XML format=====+  -  create graph 
 +/usr/bin/rrdtool graph /var/www/html/mem.png   \\ 
 +    -w 500 -h 150 -a PNG                       \\ 
 +    --slope-mode                               \\ 
 +    --start -3600 --end now                    \\ 
 +    --font DEFAULT:7:                          \\ 
 +    --title "Memory used (last hour)"          \\ 
 +    --watermark "`date`"                       \\ 
 +    --x-grid MINUTE:5:MINUTE:10:MINUTE:10:0:%R \\ 
 +    --alt-y-grid                               \\ 
 +    --rigid                                    \\ 
 +    --lower-limit=0                            \\ 
 +    --color BACK#363636                        \\ 
 +    --color CANVAS#000000                      \\ 
 +    --color GRID#999999                        \\ 
 +    --color MGRID#B5B5B5                       \\ 
 +    --color FONT#CCCCCC                        \\ 
 +    DEF:memory=/root/mem.rrd:mem:MAX           \\ 
 +    AREA:memory#FFD700                         \\ 
 +    LINE1:memory#FFD700:Memory used (MB)       \\ 
 +    GPRINT:memory:LAST:Last\\: %5.2lf           \\ 
 +    GPRINT:memory:AVERAGE:Avg\\: %5.2lf         \\ 
 +    GPRINT:memory:MAX:Max\\: %5.2lf             \\ 
 +    GPRINT:memory:MIN:Min\\: %5.2lf 
 +</code> 
 +=== Schedule this shell to run on a regular basis === 
 +<code> 
 +crontab -l 
 +  * /5 * * * * /root/update_and_create_graph.sh 
 +</code> 
 + 
 +==== A more involved example ==== 
 +<code> 
 +  - !/usr/bin/ksh 
 +  -  ============================================================================== 
 +  -  Name         : dbamon_grapher.ksh 
 +  -  Description  : Creates and updates rrdtool databases 
 +  -  
 +  -  Parameters   : none 
 +  -  
 +  -  Notes        : Only as 'up-to-date' as the latest files sent over 
 +  -  
 +  -  Modification History 
 +  -  ==================== 
 +  -  When      Who               What 
 +  -  ========= ================= ================================================== 
 +  -  06-DEC-13 Stuart Barkley    Created 
 +  -  ============================================================================== 
 + 
 +CWD=`dirname $0` 
 + 
 +  -  name of the file to process 
 +COLLECTOR_DIR="/var/www/dbdc.be.ibm.com/dba" 
 +COLLECTOR_FILES=${COLLECTOR_DIR}/"2dbamon_spool_stats*" 
 +RRDTOOL="/usr/bin/rrdtool" 
 +RRDDIR="/var/www/dbdc.be.ibm.com/dba" 
 +PNGDIR="/var/www/dbdc.be.ibm.com/html/images" 
 + 
 +  -  ======================================= 
 +  -  thats it, nothing to change below here! 
 +  -  ======================================= 
 + 
 + 
 +function cre_export_duration { 
 +    rrd_dir=$1 
 +    rrdname=$2 
 +    $RRDTOOL create ${rrd_dir}/${rrdname}                 \\ 
 +        --start 1384000000                                \\ 
 +        -s 86400                                          \\ 
 +        DS:started:GAUGE:100000:1300000000:2000000000     \\ 
 +        DS:stopped:GAUGE:100000:1300000000:2000000000     \\ 
 +        RRA:AVERAGE:0.5:1:720 
 +    if [[ $? -ne 0 ]]; then 
 +        echo "cre_export_duration: failed to create ${rrd_dir}/${rrdname}" 
 +        return 1 
 +    fi 
 +  -     echo "cre_export_duration: created ${rrd_dir}/${rrdname}" 
 +    return 0 
 +
 + 
 + 
 + 
 +rm -f $RRDDIR/*rrd 
 + 
 + 
 + 
 + 
 +  -  create the rrd databases 
 +  -  ------------------------ 
 +for statfile in `ls -t ${COLLECTOR_FILES}` 
 +do 
 +    IFS="|" 
 +    exec 0<$statfile 
 +    while read host db type started stopped 
 +    do 
 +        [[ "$stopped" == "" ]] && continue 
 +        rrdfile="export_duration_${host}_${db}.rrd" 
 +        ls ${RRDDIR}/${rrdfile} >/dev/null 2>&
 +        if [[ $? -ne 0 ]]; then 
 +            cre_export_duration "$RRDDIR" "$rrdfile" 
 +        fi 
 +    done 
 +done 
 + 
 + 
 +  -  --------------------------------------------- 
 +  -  update the rrd databases with the latest data 
 +  -  --------------------------------------------- 
 +for statfile in `ls -t ${COLLECTOR_FILES}` 
 +do 
 +  - echo "statfile: $statfile" 
 +    cat $statfile | sort -nk4 | while IFS=\\| read host db type started stopped 
 +    do 
 +        [[ "$stopped" == "" ]] && continue 
 +        rrdfile="export_duration_${host}_${db}.rrd" 
 +        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped} 
 +        [[ $? -ne 0 ]] && echo "nok: $?" 
 +    done 
 +done 
 + 
 + 
 +  - rrdtool fetch /var/www/dbdc.be.ibm.com/dba/export_duration_uaccdba22_ENDQ1.rrd AVERAGE --start "-1week" 
 + 
 + 
 +  -          --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#fffffc \\ 
 +  -          --color FONT#CCCCCC \\ 
 + 
 + 
 +for statfile in `ls -t ${COLLECTOR_FILES}` 
 +do 
 +    awk -F'|' '{print $1"|"$2}' $statfile | sort | uniq | while IFS=\\| read host db 
 +    do 
 +echo "host:$host;db:$db" 
 +        [[ "$db" == "" ]] && continue 
 +        $RRDTOOL graph ${PNGDIR}/export_duration_${host}_${db}.png                 \\ 
 +         -a PNG                                                                    \\ 
 +         -s "-14days"                                                              \\ 
 +         --slope-mode                                                              \\ 
 +         --title="Export duration for ${db} on ${host}"                            \\ 
 +         --vertical-label Minutes                                                  \\ 
 +         --alt-y-grid \\ 
 +         --rigid   \\ 
 +         --color BACK#ffffd0    \\ 
 +         --color CANVAS#ffffd0   \\ 
 +         --color GRID#0000FF       \\ 
 +         --color MGRID#996      \\ 
 +         --color FONT#000      \\ 
 +         "DEF:started=${RRDDIR}/export_duration_${host}_${db}.rrd:started:AVERAGE" \\ 
 +         "DEF:stopped=${RRDDIR}/export_duration_${host}_${db}.rrd:stopped:AVERAGE" \\ 
 +         "CDEF:duration=stopped,started,-,60,/"                                    \\ 
 +         'AREA:duration#996:Duration' 
 +    done 
 +done 
 +</code> 
 + 
 +==== Display information about the database ==== 
 +<code> 
 +rrdtool info <database> 
 +eg: 
 +rrdtool info export_duration_wdcrhbp05_ARISPPMP.rrd 
 +</code> 
 +==== Print out the data in the database ==== 
 +<code> 
 +rrdtool fetch <database> <consolidation function> --start <start time in epoch seconds> 
 +eg: 
 +rrdtool fetch export_duration_wdcrhbp05_ARISPPMP.rrd AVERAGE --start now-100000 
 +</code> 
 + 
 +==== 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
-<code>7@@</code>+<code> 
 +rrdtool xport --json -s now-1month DEF:rmantime=dbamon_rman-duration_SOL_solax025_BI4REFP.rrd:rmantime:MAX CDEF:mins=rmantime,60,/ XPORT:mins 
 +</code>
 or or
-<code>8@@</code>+<code> 
 +rrdtool xport -s now-1month DEF:rmantime=dbamon_rman-duration_SOL_solax025_BI4REFP.rrd:rmantime:MAX CDEF:mins=rmantime,60,/ XPORT:mins > xport.xml 
 +</code>
 and trim the results to bare data and trim the results to bare data
-<code>9@@</code>+<code> 
 +cat xport.xml | grep '<row>' | grep -v NaN | sed -e 's/ //g' -e 's/<row><t>//' -e 's/<\\/t><v>/ /' -e 's/<\\/v><\\/row>//' 
 +</code>
  
-=====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
  
-<code>10@@</code>+<code> 
 +rrdtool dump filename.rrd [[filename.xml]] [[--header|-h {none,xsd,dtd}]] [[--no-header]] [[--daemon address]] > filename.xml 
 +eg: 
 +rrdtool dump export_duration_wdcrhbp05_ARISPPMP.rrd dumped.xml 
 +</code>
 and and
-<code>11@@</code>+<code> 
 +rrdtool restore filename.xml filename.rrd [[--range-check|-r]] [[--force|-f]] 
 +eg: 
 +rrdtool restore dumped.xml export_duration_wdcrhbp05_ARISPPMP.rrd -f 
 +</code> 
 + 
 +==== References ==== 
 +  *  [[http://oss.oetiker.ch/rrdtool/|http://oss.oetiker.ch/rrdtool/]] 
 +  *  [[http://khmel.org/?p=236|Original page]] 
 +  *  [[http://cuddletech.com/articles/rrd/ar01s02.html|Creating an initial RRD]] 
 +  *  [[http://apfelboymchen.net/gnu/rrd/create/|Better explanations of RRA]]
  
-=====References===== 
-  * [[http://oss.oetiker.ch/rrdtool/|http://oss.oetiker.ch/rrdtool/]] 
-  * [[http://khmel.org/?p=236|Original page]] 
-  * [[http://cuddletech.com/articles/rrd/ar01s02.html|Creating an initial RRD]] 
-  * [[http://apfelboymchen.net/gnu/rrd/create/|Better explanations of RRA]] 
rrdtool.1544273361.txt.gz · Last modified: 2018/12/08 12:49 by 0.0.0.0

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki