.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "RRD::Simple::Examples 3pm" .TH RRD::Simple::Examples 3pm "2016-09-10" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" RRD::Simple::Examples \- Examples using RRD::Simple .SH "EXAMPLES" .IX Header "EXAMPLES" .SS "Example 1: Basic Data Gathering Using vmstat" .IX Subsection "Example 1: Basic Data Gathering Using vmstat" .Vb 2 \& use strict; \& use RRD::Simple; \& \& my $cmd = "/usr/bin/vmstat 2 3"; \& my $rrdfile = "vmstat\-cpu.rrd"; \& my $rrd = RRD::Simple\->new( file => $rrdfile ); \& \& my @keys = (); \& my %update = (); \& open(PH,"\-|",$cmd) or die qq{Unable to open file handle PH for command "$cmd": $!}; \& while (local $_ = ) { \& next if /\-\-\-/; \& s/^\es+|\es+$//g; \& if (/\ed+/ && @keys) { \& @update{@keys} = split(/\es+/,$_); \& } else { @keys = split(/\es+/,$_); } \& } \& close(PH) or die qq{Unable to close file handle PH for command "$cmd": $!}; \& \& my @cpukeys = splice(@keys,\-4,4); \& my %labels = (wa => "IO wait", id => "Idle", sy => "System", us => "User"); \& \& $rrd\->create(map { ($_ => "GAUGE") } @cpukeys) unless \-f $rrdfile; \& $rrd\->update(map { ($_ => $update{$_}) } @cpukeys); .Ve .SS "Example 2: Setting Minimum and Maximum Value Limits" .IX Subsection "Example 2: Setting Minimum and Maximum Value Limits" This example shows how to set the minimum value to zero on a datasource using the RRDs::tune function. Use \f(CW\*(C`\-i\*(C'\fR or \f(CW\*(C`\-\-minimum\*(C'\fR to set the minimum value, and \f(CW\*(C`\-a\*(C'\fR or \f(CW\*(C`\-\-maximum\*(C'\fR to set the maximum value. .PP See . .PP .Vb 3 \& use strict; \& use RRD::Simple; \& use RRDs; \& \& my %update = (); \& my $cmd = "/usr/bin/iostat \-k"; \& \& open(PH,"\-|",$cmd) or die qq{Unable to open file handle PH for command "$cmd": $!}; \& while (local $_ = ) { \& if (my ($dev,$r,$w) = $_ =~ /^([\ew\ed]+)\es+\eS+\es+\eS+\es+\eS+\es+(\ed+)\es+(\ed+)$/) { \& $update{$dev} = { "read" => $r, "write" => $w }; \& } \& } \& close(PH) or die qq{Unable to close file handle PH for command "$cmd": $!}; \& \& for my $dev (keys %update) { \& my $rrdfile = "iostat\-$dev.rrd"; \& my $rrd = RRD::Simple\->new( file => $rrdfile ); \& \& unless (\-f $rrdfile) { \& $rrd\->create( \& map { ($_ => "DERIVE") } sort keys %{$update{$dev}} \& ); \& RRDs::tune($rrdfile, "\-i", "$_:0") for keys %{$update{$dev}}; \& } \& \& $rrd\->update(%{$update{$dev}}); \& } .Ve .SS "Example 3: Creating RRDs with Different Data Retention Periods" .IX Subsection "Example 3: Creating RRDs with Different Data Retention Periods" The second (optional) parameter to the \fIcreate\fR method is the data retention period. Valid values are \*(L"day\*(R", \*(L"week\*(R", \*(L"month\*(R", \*(L"year\*(R", \*(L"3years\*(R" and \*(L"mrtg\*(R". The default value is \*(L"mrtg\*(R". .PP The \*(L"mrtg\*(R" data retention period uses a data stepping resolution of 300 seconds (5 minutes) and heartbeat of 600 seconds (10 minutes), whereas all the other data retention periods use a data stepping resolution of 60 seconds (1 minute) and heartbeat of 120 seconds (2 minutes). .PP .Vb 2 \& use strict; \& use RRD::Simple; \& \& my $rrd = RRD::Simple\->new( file => "myfile.rrd" ); \& my @period = qw(day week month year 3years mrtg); \& $rrd\->create($period[1], \& datasource1 => "GAUGE", \& datasource2 => "GAUGE", \& datasource3 => "GAUGE", \& ); .Ve .SS "Example 4: Drawing an Average Value Horizonal Rule on a Graph" .IX Subsection "Example 4: Drawing an Average Value Horizonal Rule on a Graph" Graph parameters are preserved and should be passed through to RRDs correctly: \&\s-1VDEF, CDEF, DEF, GPRINT, PRINT, COMMENT, HRULE, VRULE, LINE, AREA, TICK, SHIFT\s0 and \s-1STACK.\s0 Use the \s-1VDEF\s0 and \s-1HRULE\s0 parameters to draw a horizontal rule on your graph. .PP .Vb 2 \& use strict; \& use RRD::Simple; \& \& my $rrd = RRD::Simple\->new( file => "frequency.rrd" ); \& $rrd\->create("day", \& Frequency => "GAUGE", \& ); \& \& my $end = time(); \& my $start = $end \- (60 * 60 * 24); \& my $i = 0; \& my $rand = int(rand(100)); \& \& for (my $t = $start; $t <= $end; $t += 60) { \& $rrd\->update($t, \& Frequency => ( cos($i += 0.01) * 100 ) + $rand, \& ); \& } \& \& $rrd\->graph( \& sources => [ qw(Frequency) ], \& "VDEF:FrequencyAVERAGE=Frequency,AVERAGE" => "", \& "HRULE:FrequencyAVERAGE#00ff77:Average" => "", \& ); .Ve .SS "Example 5: Drawing a Fixed Height Stacked Graph" .IX Subsection "Example 5: Drawing a Fixed Height Stacked Graph" .Vb 2 \& use strict; \& use RRD::Simple; \& \& my $rrdfile = "vmstat\-cpu.rrd"; \& my $rrd = RRD::Simple\->new( file => $rrdfile ); \& \& $rrd\->graph( \& title => "CPU Utilisation", \& vertical_label => "% percent", \& upper_limit => 100, \& lower_limit => 0, \& rigid => "", \& sources => [ qw(sy us wa id) ], \& source_drawtypes => [ qw(AREA STACK STACK STACK) ], \& extended_legend => 1, \& ); .Ve .SS "Example 6: Setting Custom Graph Colours" .IX Subsection "Example 6: Setting Custom Graph Colours" The \f(CW\*(C`color\*(C'\fR parameter can be used to override the default colours for standard elements of the graph. Valid elements are: \s-1BACK, CANVAS, SHADEA, SHADEB, GRID, MGRID, FONT, AXIS, FRAME\s0 and \s-1ARROW.\s0 See for further information. .PP .Vb 2 \& use strict; \& use RRD::Simple; \& \& my $rrd = RRD::Simple\->new( file => "vmstat\-cpu.rrd" ); \& \& $rrd\->graph( \& title => "CPU Utilisation", \& source_colors => { \& sy => "ff0000", \& us => "00ff00", \& wa => "0000ff", \& id => "ffffff", \& }, \& color => [ ( "BACK#F5F5FF", "SHADEA#C8C8FF", \& "SHADEB#9696BE", "ARROW#61B51B", \& "GRID#404852", "MGRID#67C6DE" ) ], \& ); .Ve .SS "Example 7: Capacity Planning Predictions" .IX Subsection "Example 7: Capacity Planning Predictions" .Vb 2 \& use strict; \& use RRD::Simple 1.44; \& \& my $rrd = RRD::Simple\->new( file => "memory_usage.rrd" ); \& \& $rrd\->graph( \& periods => [ qw(week month) ], \& title => "Memory Utilisation", \& base => 1024, \& vertical_label => "bytes", \& sources => [ qw(Total Used) ], \& source_drawtypes => [ qw(AREA LINE) ], \& source_colors => [ qw(dddddd 0000dd) ], \& lower_limit => 0, \& rigid => "", \& "VDEF:D=Used,LSLSLOPE" => "", \& "VDEF:H=Used,LSLINT" => "", \& "VDEF:F=Used,LSLCORREL" => "", \& "CDEF:Proj=Used,POP,D,COUNT,*,H,+" => "", \& "LINE2:Proj#800000: Projection" => "", \& ); .Ve .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2005,2006,2007,2008 Nicola Worthington. .PP This software is licensed under The Apache Software License, Version 2.0. .PP