{"id":254,"date":"2007-03-21T04:04:53","date_gmt":"2007-03-21T01:04:53","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=254"},"modified":"2007-09-13T20:10:46","modified_gmt":"2007-09-13T17:10:46","slug":"round-trip-and-packet-loss-stats-with-rrdtool","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2007\/03\/21\/round-trip-and-packet-loss-stats-with-rrdtool\/","title":{"rendered":"Round Trip and Packet Loss stats with rrdtool"},"content":{"rendered":"<p>To get some nice graphs showing your round trip time and your packet loss, like the following image, follow the steps below:<\/p>\n<p><img src='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/ping_wan_week.png' alt='' \/><\/p>\n<p>What you need before you start: rrdtool and a cron server (vixie-cron is fine).<\/p>\n<p>a) Execute the following<br \/>\n<code><br \/>\n\/usr\/bin\/rrdtool create \/var\/rrds\/ping\/ping_wan.rrd \\<br \/>\n    --step 300 \\<br \/>\n    DS:pl:GAUGE:600:0:100 \\<br \/>\n    DS:rtt:GAUGE:600:0:10000000 \\<br \/>\n    RRA:AVERAGE:0.5:1:800 \\<br \/>\n    RRA:AVERAGE:0.5:6:800 \\<br \/>\n    RRA:AVERAGE:0.5:24:800 \\<br \/>\n    RRA:AVERAGE:0.5:288:800 \\<br \/>\n    RRA:MAX:0.5:1:800 \\<br \/>\n    RRA:MAX:0.5:6:800 \\<br \/>\n    RRA:MAX:0.5:24:800 \\<br \/>\n    RRA:MAX:0.5:288:800<br \/>\n<\/code><\/p>\n<p>You can change \/var\/rrds\/ping\/ping_wan.rrd  to the path\/file.rrd you wish.<\/p>\n<p>b) Save the following to the file ping.sh<br \/>\n<code><br \/>\n#!\/bin\/bash<br \/>\nPING=\/bin\/ping<br \/>\nCOUNT=4<br \/>\nDEADLINE=10<br \/>\nping_host() {<br \/>\n    local output=$($PING -q -n -c $COUNT -w $DEADLINE $1 2&gt;&1)<br \/>\n    # notice $output is quoted to preserve newlines<br \/>\n    local temp=$(echo \"$output\"| awk '<br \/>\n        BEGIN           {pl=100; rtt=0.1}<br \/>\n        \/packets transmitted\/   {<br \/>\n            match($0, \/([0-9]+)% packet loss\/, matchstr)<br \/>\n            pl=matchstr[1]<br \/>\n        }<br \/>\n        \/^rtt\/          {<br \/>\n            # looking for something like 0.562\/0.566\/0.571\/0.024<br \/>\n            match($4, \/(.*)\\\/(.*)\\\/(.*)\\\/(.*)\/, a)<br \/>\n            rtt=a[2]<br \/>\n        }<br \/>\n        \/unknown host\/  {<br \/>\n            # no output at all means network is probably down<br \/>\n            pl=100<br \/>\n            rtt=0.1<br \/>\n        }<br \/>\n        END             {print pl \":\" rtt}<br \/>\n        ')<br \/>\n    RETURN_VALUE=$temp<br \/>\n}<br \/>\n# ping a host on the local lan<br \/>\nping_host www.ntua.gr<br \/>\n\/usr\/bin\/rrdtool update \\<br \/>\n    \/var\/rrds\/ping\/ping_wan.rrd \\<br \/>\n    --template \\<br \/>\n    pl:rtt \\<br \/>\n    N:$RETURN_VALUE<br \/>\n<\/code><br \/>\n<a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/ping.sh.gz' title=''>ping.sh.gz<\/a><br \/>\nChange the ping_host www.ntua.gr to the one of your choice. Make the script executable, chmod +x ping.sh.<\/p>\n<p>If you have changed the \/var\/rrds\/ping\/ping_wan.rrd on step (a) you have to change it here too.<\/p>\n<p>c) Save the following to ping-graph.sh and make it executable.<br \/>\n<code><br \/>\n#!\/bin\/sh<br \/>\ncd \/var\/rrds\/ping\/<br \/>\necho \"<br \/>\n&lt;HTML&gt;<br \/>\n&lt;HEAD&gt;&lt;TITLE&gt;Round-Trip and Packet Loss Stats&lt;\/TITLE&gt;&lt;\/HEAD&gt;<br \/>\n        &lt;BODY&gt;<br \/>\n        &lt;H3&gt;Hourly Round-Trip & Packetloss Stats(1min average)&lt;\/H3&gt;<br \/>\n\" &gt; index.html<br \/>\nrrdtool graph ping_wan_hour.png -h 225 -w 600  -a PNG \\<br \/>\n    --imginfo '&lt;IMG SRC=\/stats\/%s WIDTH=%lu HEIGHT=%lu &gt;' \\<br \/>\n    --start -3600 --end -60 --x-grid MINUTE:10:HOUR:1:MINUTE:30:0:%R \\<br \/>\n    -v \"Round-Trip Time (ms)\" \\<br \/>\n    --rigid \\<br \/>\n    --lower-limit 0 \\<br \/>\n    DEF:roundtrip=ping_wan.rrd:rtt:AVERAGE \\<br \/>\n    DEF:packetloss=ping_wan.rrd:pl:AVERAGE \\<br \/>\n    CDEF:PLNone=packetloss,0,2,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL2=packetloss,2,8,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL15=packetloss,8,15,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL25=packetloss,15,25,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL50=packetloss,25,50,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL75=packetloss,50,75,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL100=packetloss,75,100,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    AREA:roundtrip#4444ff:\"Round Trip Time (millis)\" \\<br \/>\n    GPRINT:roundtrip:LAST:\"Cur\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:AVERAGE:\"Avg\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MAX:\"Max\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MIN:\"Min\\: %5.2lf\\n\" \\<br \/>\n    AREA:PLNone#6c9bcd:\"0-2%\":STACK \\<br \/>\n    AREA:PL2#00ffae:\"2-8%\":STACK \\<br \/>\n    AREA:PL15#ccff00:\"8-15%\":STACK \\<br \/>\n    AREA:PL25#ffff00:\"15-25%\":STACK \\<br \/>\n    AREA:PL50#ffcc66:\"25-50%\":STACK \\<br \/>\n    AREA:PL75#ff9900:\"50-75%\":STACK \\<br \/>\n    AREA:PL100#ff0000:\"75-100%\":STACK \\<br \/>\n    COMMENT:\"(Packet Loss Percentage)\"<br \/>\necho \"<br \/>\n&lt;img src=\"ping_wan_hour.png\"&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;H3&gt;Daily Round-Trip & Packetloss Stats(1min average)&lt;\/H3&gt;<br \/>\n\" &gt;&gt; index.html<br \/>\nrrdtool graph ping_wan_day.png -h 225 -w 600  -a PNG \\<br \/>\n    --imginfo '&lt;IMG SRC=\/stats\/%s WIDTH=%lu HEIGHT=%lu &gt;' \\<br \/>\n    --lazy --start -86400 --end -60 --x-grid MINUTE:30:HOUR:1:HOUR:2:0:%H \\<br \/>\n    -v \"Round-Trip Time (ms)\" \\<br \/>\n    --rigid \\<br \/>\n    --lower-limit 0 \\<br \/>\n    DEF:roundtrip=ping_wan.rrd:rtt:AVERAGE \\<br \/>\n    DEF:packetloss=ping_wan.rrd:pl:AVERAGE \\<br \/>\n    CDEF:PLNone=packetloss,0,2,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL2=packetloss,2,8,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL15=packetloss,8,15,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL25=packetloss,15,25,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL50=packetloss,25,50,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL75=packetloss,50,75,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL100=packetloss,75,100,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    AREA:roundtrip#4444ff:\"Round Trip Time (millis)\" \\<br \/>\n    GPRINT:roundtrip:LAST:\"Cur\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:AVERAGE:\"Avg\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MAX:\"Max\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MIN:\"Min\\: %5.2lf\\n\" \\<br \/>\n    AREA:PLNone#6c9bcd:\"0-2%\":STACK \\<br \/>\n    AREA:PL2#00ffae:\"2-8%\":STACK \\<br \/>\n    AREA:PL15#ccff00:\"8-15%\":STACK \\<br \/>\n    AREA:PL25#ffff00:\"15-25%\":STACK \\<br \/>\n    AREA:PL50#ffcc66:\"25-50%\":STACK \\<br \/>\n    AREA:PL75#ff9900:\"50-75%\":STACK \\<br \/>\n    AREA:PL100#ff0000:\"75-100%\":STACK \\<br \/>\n    COMMENT:\"(Packet Loss Percentage)\"<br \/>\necho \"<br \/>\n&lt;img src=\"ping_wan_day.png\"&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;H3&gt;Weekly Round-Trip & Packetloss Stats(1min average)&lt;\/H3&gt;<br \/>\n\" &gt;&gt; index.html<br \/>\nrrdtool graph ping_wan_week.png -h 225 -w 600 -a PNG \\<br \/>\n    --imginfo '&lt;IMG SRC=\/stats\/%s WIDTH=%lu HEIGHT=%lu &gt;' \\<br \/>\n    --lazy --start -604800 --end -1800 \\<br \/>\n    -v \"Round-Trip Time (ms)\" \\<br \/>\n    --rigid \\<br \/>\n    --lower-limit 0 \\<br \/>\n    DEF:roundtrip=ping_wan.rrd:rtt:AVERAGE \\<br \/>\n    DEF:packetloss=ping_wan.rrd:pl:AVERAGE \\<br \/>\n    CDEF:PLNone=packetloss,0,2,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL2=packetloss,2,8,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL15=packetloss,8,15,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL25=packetloss,15,25,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL50=packetloss,25,50,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL75=packetloss,50,75,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL100=packetloss,75,100,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    AREA:roundtrip#4444ff:\"Round Trip Time (millis)\" \\<br \/>\n    GPRINT:roundtrip:LAST:\"Cur\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:AVERAGE:\"Avg\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MAX:\"Max\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MIN:\"Min\\: %5.2lf\\n\" \\<br \/>\n    AREA:PLNone#6c9bcd:\"0-2%\":STACK \\<br \/>\n    AREA:PL2#00ffae:\"2-8%\":STACK \\<br \/>\n    AREA:PL15#ccff00:\"8-15%\":STACK \\<br \/>\n    AREA:PL25#ffff00:\"15-25%\":STACK \\<br \/>\n    AREA:PL50#ffcc66:\"25-50%\":STACK \\<br \/>\n    AREA:PL75#ff9900:\"50-75%\":STACK \\<br \/>\n    AREA:PL100#ff0000:\"75-100%\":STACK \\<br \/>\n    COMMENT:\"(Packet Loss Percentage)\"<br \/>\necho \"<br \/>\n&lt;img src=\"ping_wan_week.png\"&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;H3&gt;Monthly Round-Trip & Packetloss Stats(1min average)&lt;\/H3&gt;<br \/>\n\" &gt;&gt; index.html<br \/>\nrrdtool graph ping_wan_month.png -h 225 -w 600 -a PNG \\<br \/>\n        --imginfo '&lt;IMG SRC=\/stats\/%s WIDTH=%lu HEIGHT=%lu &gt;' \\<br \/>\n        --lazy --start -2592000 --end -7200 \\<br \/>\n    -v \"Round-Trip Time (ms)\" \\<br \/>\n    --rigid \\<br \/>\n    --lower-limit 0 \\<br \/>\n    DEF:roundtrip=ping_wan.rrd:rtt:AVERAGE \\<br \/>\n    DEF:packetloss=ping_wan.rrd:pl:AVERAGE \\<br \/>\n    CDEF:PLNone=packetloss,0,2,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL2=packetloss,2,8,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL15=packetloss,8,15,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL25=packetloss,15,25,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL50=packetloss,25,50,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL75=packetloss,50,75,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL100=packetloss,75,100,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    AREA:roundtrip#4444ff:\"Round Trip Time (millis)\" \\<br \/>\n    GPRINT:roundtrip:LAST:\"Cur\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:AVERAGE:\"Avg\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MAX:\"Max\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MIN:\"Min\\: %5.2lf\\n\" \\<br \/>\n    AREA:PLNone#6c9bcd:\"0-2%\":STACK \\<br \/>\n    AREA:PL2#00ffae:\"2-8%\":STACK \\<br \/>\n    AREA:PL15#ccff00:\"8-15%\":STACK \\<br \/>\n    AREA:PL25#ffff00:\"15-25%\":STACK \\<br \/>\n    AREA:PL50#ffcc66:\"25-50%\":STACK \\<br \/>\n    AREA:PL75#ff9900:\"50-75%\":STACK \\<br \/>\n    AREA:PL100#ff0000:\"75-100%\":STACK \\<br \/>\n    COMMENT:\"(Packet Loss Percentage)\"<br \/>\necho \"<br \/>\n&lt;img src=\"ping_wan_month.png\"&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;H3&gt;Yearly Round-Trip & Packetloss Stats(1min average)&lt;\/H3&gt;<br \/>\n\" &gt;&gt; index.html<br \/>\nrrdtool graph ping_wan_year.png \\<br \/>\n        --imginfo '&lt;IMG SRC=\/stats\/%s WIDTH=%lu HEIGHT=%lu &gt;' \\<br \/>\n        --lazy --start -31536000 --end -86400 -h 225 -w 600 -a PNG \\<br \/>\n    -v \"Round-Trip Time (ms)\" \\<br \/>\n    --rigid \\<br \/>\n    --lower-limit 0 \\<br \/>\n    DEF:roundtrip=ping_wan.rrd:rtt:AVERAGE \\<br \/>\n    DEF:packetloss=ping_wan.rrd:pl:AVERAGE \\<br \/>\n    CDEF:PLNone=packetloss,0,2,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL2=packetloss,2,8,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL15=packetloss,8,15,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL25=packetloss,15,25,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL50=packetloss,25,50,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL75=packetloss,50,75,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    CDEF:PL100=packetloss,75,100,LIMIT,UN,UNKN,INF,IF \\<br \/>\n    AREA:roundtrip#4444ff:\"Round Trip Time (millis)\" \\<br \/>\n    GPRINT:roundtrip:LAST:\"Cur\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:AVERAGE:\"Avg\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MAX:\"Max\\: %5.2lf\" \\<br \/>\n    GPRINT:roundtrip:MIN:\"Min\\: %5.2lf\\n\" \\<br \/>\n    AREA:PLNone#6c9bcd:\"0-2%\":STACK \\<br \/>\n    AREA:PL2#00ffae:\"2-8%\":STACK \\<br \/>\n    AREA:PL15#ccff00:\"8-15%\":STACK \\<br \/>\n    AREA:PL25#ffff00:\"15-25%\":STACK \\<br \/>\n    AREA:PL50#ffcc66:\"25-50%\":STACK \\<br \/>\n    AREA:PL75#ff9900:\"50-75%\":STACK \\<br \/>\n    AREA:PL100#ff0000:\"75-100%\":STACK \\<br \/>\n    COMMENT:\"(Packet Loss Percentage)\"<br \/>\necho \"<br \/>\n&lt;img src=\"ping_wan_year.png\"&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;\/BODY&gt;<br \/>\n&lt;\/HTML&gt;<br \/>\n\" &gt;&gt; index.html<br \/>\n<\/code><br \/>\nIf you have changed \/var\/rrds\/ping on step (a) you need to change it here in the beggining of the script too.<\/p>\n<p>The above script creates a very simple index.html file inside \/var\/rrds\/ping (unless you&#8217;ve changed it) with 5 graphs: hourly, daily, weekly, monthly and yearly<\/p>\n<p>d) Add the following entries to your crontab:<br \/>\n<code><br \/>\n*\/5 * * * * \/etc\/mrtg\/ping.sh<br \/>\n1,6,11,16,21,26,31,36,41,46,51,56 * * * * \/path\/to\/ping-graph.sh<br \/>\n<\/code><\/p>\n<p>For better accuracy, you can change &#8220;&#8211;step 300&#8221; to &#8220;&#8211;step 60&#8221; in the rrd database creation script and then change the crontab entry for ping.sh from:<br \/>\n<code>*\/5 * * * * \/etc\/mrtg\/ping.sh<\/code><br \/>\nto<br \/>\n<code>* * * * * \/etc\/mrtg\/ping.sh<\/code><\/p>\n<p>Original ping script and rrd config for the graphs from <a href=\"http:\/\/haroon.sis.utoronto.ca\/rrd\/scripts\/\">http:\/\/haroon.sis.utoronto.ca\/rrd\/scripts\/<\/a><\/p>\n<p>Enjoy your graphs. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get some nice graphs showing your round trip time and your packet loss, like the following image, follow the steps below: What you need before you start: rrdtool and a cron server (vixie-cron is fine). a) Execute the following \/usr\/bin\/rrdtool create \/var\/rrds\/ping\/ping_wan.rrd \\ &#8211;step 300 \\ DS:pl:GAUGE:600:0:100 \\ DS:rtt:GAUGE:600:0:10000000 \\ RRA:AVERAGE:0.5:1:800 \\ RRA:AVERAGE:0.5:6:800 \\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[3,8],"tags":[],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-linux","category-networking"],"aioseo_notices":[],"views":35372,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":0,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}