RRD-BEGINNERS(1) rrdtool RRD-BEGINNERS(1) (NAME) rrd-beginners - RRDtool (SYNOPSIS) RRDtool (DESCRIPTION) RRDtool. RRDtool . RRDtool . << >> (graph) RRDtool . RRDtool Shell Perl . RRDtool RRDtool GNU Tobias Oetiker (ETH) . RRDtool : o RRDtool (back-end) . RRDtool (front-end) . . o . RRDtool . RRDtool . . (overwrite) . RRDtool . << >> (Round Robin) . o . RRDtool . o . RRDtool . UNKNOWN . RRDtool RRDtool . RRDtool (time series) . (timestamp) . epoch ( 01-01-1970) . RRDtool Unix Windows . RRD . Shell Perl . (wrappers) RRDtool ..SS " (Understanding by an example)" RRD . . . RRDtool (monitoring) . . . RRDtool . (DS) (heartbeat) (DST) (RRA) (CF) RRDtool . . rrdtool create target.rrd \ --start 1023654125 \ --step 300 \ DS:mem:GAUGE:600:0:671744 \ RRA:AVERAGE:0.5:12:24 \ RRA:AVERAGE:0.5:288:31 target.rrd . (1'023'654'125) (epoch) ( 1970-01-01) . . () epoch . (step) 300 300 . (wrapper) step step . DS ( Data Source) . (syntax) : DS:variable_name:DST:heartbeat:min:max DS . "variable_name" . DS . step DS . (PDP) Primary Data Point . 300 PDP . 300 RRDtool (interpolate) . DST ( Data Source Type) DS . COUNTER DERIVE ABSOLUTE GAUGE . DS COUNTER step . ( 0 ). COUNTER DST . DERIVE COUNTER . DERIVE . ABSOLUTE 0 . . step ( 300 ) . GAUGE . gauge . DST : Values = 300, 600, 900, 1200 Step = 300 seconds COUNTER DS = 1, 1, 1, 1 DERIVE DS = 1, 1, 1, 1 ABSOLUTE DS = 1, 2, 3, 4 GAUGE DS = 300, 600, 900, 1200 heartbeat . heartbeat 600 . 300 PDP 300 ( 600 ). 600 PDP UNKNOWN . UNKNOWN RRDtool - 0 () . . UNKNOWN 0 . (0) . UNKNOWN . (minimum) (maximum) . . UNKNOWN . (RRA) . (syntax) RRA : RRA:CF:xff:step:rows RRA RRA . (CF) AVERAGE MINIMUM MAXIMUM LAST . (CDP) . CDP CF ( / ) step PDP . RRA rows CDP . . RRA 12 (steps) PDP ( DS) ( CF AVERAGE) CDP . 24 (rows) CDP . PDP 300 . 12 PDP 12 300 1 . 1 CDP ( 12 PDP ) 1 . 24 CDP 1 (1 24 CDP). RRA . 24 CDP 25 CDP . RRA 31 CDP CDP AVERAGE (288 PDP 300 = 24 ). RRA . RRA . DS RRA DS . 3 (DS) RRA RRA 3 ..SS " (Graphical Magic)" RRDtool . <> <> . . DS ( Data Sources) . . . SNMP KBytes Bytes . MBytes mbps . graph RRDtool . if/then/else . RRA RRDtool RRA RRDtool . RRA . (resolution) RRA () . <<-r>> RRDtool . : AREA LINE1 LINE2 LINE3 STACK. AREA . LINE1/2/3 ( ) . STACK AREA LINE1/2/3 (<<>> ). graph STACK AREA/LINE . . graph . RRDtool Shell/Perl (Wrapping RRDtool within Shell/Perl script) RRDtool RRDtool . . target.rrd . Shell Perl . : Shell ( ) #!/bin/sh a=0 while [ "$a" == 0 ]; do snmpwalk -c public 192.168.1.250 hrSWRunPerfMem > snmp_reply total_mem=`awk 'BEGIN {tot_mem=0} { if ($NF == "KBytes") {tot_mem=tot_mem+$(NF-1)} } END {print tot_mem}' snmp_reply` # I can use N as a replacement for the current time rrdtool update target.rrd N:$total_mem # sleep until the next 300 seconds are full perl -e 'sleep 300 - time % 300' done # end of while loop Perl ( ) #!/usr/bin/perl -w # This script fetches data from target.rrd, creates a graph of memory # consumption on the target (Dual P3 Processor 1 GHz, 656 MB RAM) # call the RRD perl module use lib qw( /usr/local/rrdtool-1.0.41/lib/perl ../lib/perl ); use RRDs; my $cur_time = time(); # set current time my $end_time = $cur_time - 86400; # set end time to 24 hours ago my $start_time = $end_time - 2592000; # set start 30 days in the past # fetch average values from the RRD database between start and end time my ($start,$step,$ds_names,$data) = RRDs::fetch("target.rrd", "AVERAGE", "-r", "600", "-s", "$start_time", "-e", "$end_time"); # save fetched values in a 2-dimensional array my $rows = 0; my $columns = 0; my $time_variable = $start; foreach $line (@$data) { $vals[$rows][$columns] = $time_variable; $time_variable = $time_variable + $step; foreach $val (@$line) { $vals[$rows][++$columns] = $val;} $rows++; $columns = 0; } my $tot_time = 0; my $count = 0; # save the values from the 2-dimensional into a 1-dimensional array for $i ( 0 .. $#vals ) { $tot_mem[$count] = $vals[$i][1]; $count++; } my $tot_mem_sum = 0; # calculate the total of all values for $i ( 0 .. ($count-1) ) { $tot_mem_sum = $tot_mem_sum + $tot_mem[$i]; } # calculate the average of the array my $tot_mem_ave = $tot_mem_sum/($count); # create the graph RRDs::graph ("/images/mem_$count.png", "--title= Memory Usage", "--vertical-label=Memory Consumption (MB)", "--start=$start_time", "--end=$end_time", "--color=BACK#CCCCCC", "--color=CANVAS#CCFFFF", "--color=SHADEB#9999CC", "--height=125", "--upper-limit=656", "--lower-limit=0", "--rigid", "--base=1024", "DEF:tot_mem=target.rrd:mem:AVERAGE", "CDEF:tot_mem_cor=tot_mem,0,671744,LIMIT,UN,0,tot_mem,IF,1024,/", "CDEF:machine_mem=tot_mem,656,+,tot_mem,-", "COMMENT:Memory Consumption between $start_time", "COMMENT: and $end_time ", "HRULE:656#000000:Maximum Available Memory - 656 MB", "AREA:machine_mem#CCFFFF:Memory Unused", "AREA:tot_mem_cor#6699CC:Total memory consumed in MB"); my $err=RRDs::error; if ($err) {print "problem generating the graph: $err\n";} # print the output print "Average memory consumption is "; printf "%5.2f",$tot_mem_ave/1024; print " MB. Graphical representation can be found at /images/mem_$count.png."; Ketan Patel 1.11.0 2026-08-08 RRD-BEGINNERS(1)