Curs: | SeguretatXarxesInformàtiques, LinuxAdministracioAvancada, DissenyXarxesLinux |
Fitxers: | EinesMonitoritzacio.pdf (EinesMonitoritzacio.odp) |
Repositori SVN: | https://[email protected]/svn/iceupc/SeguretatXarxesInformàtiques |
Usuari: | anonymous |
Paraula de pas: | sense paraula de pas |
Autors: | Sergi Tur Badenas |
RRDtool és una acrònim de round-robin database tool. És una eina que permet gestionar series de dades en el temps ( time-series data) com per exemple ampla de banda de xarxa, temperatures, càrrega de la CPU, etc.
Les dades s'emmagatzemen en bases de dades round-robin (buffers circulars) de forma que la quantitat d'espai que es necessita per emmgatzemar les dades es manté constant en el temps.
Cal destacar que a més d'emmagatzemar dades en una base de dades round-robin també permet mostra les dades de forma gràfica.
Als repositoris oficials d'Ubuntu/Debian podeu trobar el paquet rrdtool:
$ sudo apt-get install rrdtool
$ dpkg -L rrdtool /. /usr /usr/share /usr/share/doc /usr/share/doc/rrdtool /usr/share/doc/rrdtool/html /usr/share/doc/rrdtool/html/bin_dec_hex.html /usr/share/doc/rrdtool/html/rrddump.html /usr/share/doc/rrdtool/html/rrdgraph_examples.html /usr/share/doc/rrdtool/html/rrdrestore.html /usr/share/doc/rrdtool/html/rrdupdate.html /usr/share/doc/rrdtool/html/cdeftutorial.html /usr/share/doc/rrdtool/html/rrdfetch.html /usr/share/doc/rrdtool/html/rrdgraph_graph.html /usr/share/doc/rrdtool/html/rrdthreads.html /usr/share/doc/rrdtool/html/rrdxport.html /usr/share/doc/rrdtool/html/rpntutorial.html /usr/share/doc/rrdtool/html/rrdfirst.html /usr/share/doc/rrdtool/html/rrdgraph_rpn.html /usr/share/doc/rrdtool/html/rrdtool.html /usr/share/doc/rrdtool/html/rrd-beginners.html /usr/share/doc/rrdtool/html/rrdinfo.html /usr/share/doc/rrdtool/html/rrdtune.html /usr/share/doc/rrdtool/html/rrdbuild.html /usr/share/doc/rrdtool/html/rrdflushcached.html /usr/share/doc/rrdtool/html/rrdcgi.html /usr/share/doc/rrdtool/html/rrdgraph.html /usr/share/doc/rrdtool/html/rrdlast.html /usr/share/doc/rrdtool/html/rrdlastupdate.html /usr/share/doc/rrdtool/html/rrdcreate.html /usr/share/doc/rrdtool/html/rrdgraph_data.html /usr/share/doc/rrdtool/html/rrdresize.html /usr/share/doc/rrdtool/html/rrdtutorial.html /usr/share/doc/rrdtool/html/rrdgraph_libdbi.html /usr/share/doc/rrdtool/html/rrdlua.html /usr/share/doc/rrdtool/html/librrd.html /usr/share/doc/rrdtool/html/RRDs.html /usr/share/doc/rrdtool/html/RRDp.html /usr/share/doc/rrdtool/examples /usr/share/doc/rrdtool/examples/ifOctets.tcl /usr/share/doc/rrdtool/examples/cgi-demo.cgi /usr/share/doc/rrdtool/examples/4charts.pl /usr/share/doc/rrdtool/examples/bigtops.pl /usr/share/doc/rrdtool/examples/minmax.pl /usr/share/doc/rrdtool/examples/shared-demo.pl.gz /usr/share/doc/rrdtool/examples/stripes.pl /usr/share/doc/rrdtool/examples/test.rb /usr/share/doc/rrdtool/examples/perftest.pl.gz /usr/share/doc/rrdtool/examples/piped-demo.pl.gz /usr/share/doc/rrdtool/NEWS.Debian.gz /usr/share/doc/rrdtool/changelog.gz /usr/share/doc/rrdtool/NEWS.gz /usr/share/doc/rrdtool/README.Debian /usr/share/doc/rrdtool/copyright /usr/share/doc/rrdtool/changelog.Debian.gz /usr/share/doc/rrdtool/CONTRIBUTORS.gz /usr/share/man /usr/share/man/man1 /usr/share/man/man1/rrddump.1.gz /usr/share/man/man1/rrdrestore.1.gz /usr/share/man/man1/rrdupdate.1.gz /usr/share/man/man1/cdeftutorial.1.gz /usr/share/man/man1/rrdfetch.1.gz /usr/share/man/man1/rrdgraph_graph.1.gz /usr/share/man/man1/rrdthreads.1.gz /usr/share/man/man1/rrdxport.1.gz /usr/share/man/man1/rpntutorial.1.gz /usr/share/man/man1/rrdfirst.1.gz /usr/share/man/man1/rrdtool.1.gz /usr/share/man/man1/rrd-beginners.1.gz /usr/share/man/man1/rrdinfo.1.gz /usr/share/man/man1/rrdtune.1.gz /usr/share/man/man1/rrdbuild.1.gz /usr/share/man/man1/rrdflushcached.1.gz /usr/share/man/man1/rrdcgi.1.gz /usr/share/man/man1/rrdgraph.1.gz /usr/share/man/man1/rrdlast.1.gz /usr/share/man/man1/rrdlastupdate.1.gz /usr/share/man/man1/rrdcreate.1.gz /usr/share/man/man1/rrdgraph_data.1.gz /usr/share/man/man1/rrdresize.1.gz /usr/share/man/man1/rrdtutorial.1.gz /usr/share/man/man1/rrdgraph_libdbi.1.gz /usr/share/man/man1/rrdlua.1.gz /usr/share/man/man1/bin_dec_hex.1.gz /usr/share/man/man1/rrdgraph_examples.1.gz /usr/share/man/man1/rrdgraph_rpn.1.gz /usr/share/man/man3 /usr/share/man/man3/librrd.3.gz /usr/share/doc-base /usr/share/doc-base/rrdtool /usr/bin /usr/bin/rrdtool /usr/bin/rrdupdate /usr/bin/rrdcgi /usr/share/doc/rrdtool/html/index.html
http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html
Glossari de termes:
El punts de dades primaris són els valors que s'obtenen cada x temps (step). Per a crear arxius de dades Round Robin s'aplica un procés de consolidació o s'utilitza una funció (funció de consolidació) per calcular punts de consolidació. Vegeu la següent gràfica:
El següent exemple ens pot ser útils per saber com funciona RRDTool, es tracta d'un exemple de com crear una base de dades RRD :
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
On:
DS:variable_name:DST:heartbeat:min:max
On:
El següent exemple pot ajudar millor a entendre com funciona:
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
NOTA: Cal tenir en compte que si no proporcioneu els nous punts de dades exactament cada 300 segons no és cap problema, RRD interpola les dades correctament!
Es poden indicar tants DS com faci falta en una mateixa base de dades RRD.
L'última part són els RRAs (Round Robin Archives):
RRA:AVERAGE:0.5:12:24 \ RRA:AVERAGE:0.5:288:31
La sintaxi és:
RRA:CF:xff:step:rows
On:
A Cacti es defineixen gràficament els RRAs a la secció Management > Data Sources > RRAs:
A l'exemple:
RRA:AVERAGE:0.5:12:24 \
És tracta d'un arxiu round robin que guarda les dades de 1 dia (24 valors, un per cada hora, ja que 12 valors cada 300 segons)
i:
RRA:AVERAGE:0.5:288:31
Es tracta de l'arxiu mensual (31 valors, un per dia ja que 288x300=84000 segons és un dia )
Es pot treballar amb RRDTool directament amb llenguatges de programació com:
Perl, python, Tcl, PHP, etc.
És l'ordre principal del paquet RRDTool. Segons el manual:
$ man rrdtool
L'ordre està dividida en subfuncions:
architecture to another. Check rrddump.
rrdfetch.
Per a més informació consulteu:
$ man rrdcreate
Per a més informació consulteu:
$ man rrdupdate
Per a més informació consulteu:
$ man rrdgraph
La sinopsis de l'ordre rrdtool graph és la següent:
rrdtool graph|graphv filename [option ...] [data definition ...] [data calculation ...] [variable definition ...] [graph element ...] [print element ...]
L'ordre s'utilitza per representar en forma de gràfica les dades de una base de dades Round Robin. El seu objectiu principal és crear una representació gràfica bonica i per a humans (a diferencia de les series de dades a pèl que són més properes a les màquines que no pas als humans.)
rrdtool graph necessita dades que pot agafar de una o més bases de dades RRD.
NOTA: Si es volen mostrar dades estadístiques com la mitjana, el màxim o el percentils de la sèrie de dades és millor recollir-los a la part variable definition.
Cal tenir en compte que sovint les dades no estaran en el format que les volem mostrar, per exemple es molt típic estar recollint dades en bytes/sec però lo habitual és mostrar les velocitats/amples de banda en bits per segon (bps). Per aquesta raó es poden fer operacions i càlculs amb les dades abans de mostrar-les. S'utilitza la notació RPN per indicar les operacions a realitzar.
El primer paràmetre és el nom de la imatge a generar:
$ rrdtool graph NOMFITXERAMBLAIMATGE OPCIONS
Es pot utilitzar - per a mostrar l'imatge per la sortida estàndard:
$ rrdtool graph - OPCIONS > NOMFITXERAMBLAIMATGE
El format de sortida per defecte és PNG. Amb:
[-a|--imgformat PNG|SVG|EPS|PDF]
Es pot indicar altres formats (per exemple SVG es un format vectorial i permet mantenir l'aspecte amb les ampliacions (s'evita l'efecte de pixelació))
Separarem les opcions de la generació de les gràfiques en qüestions de presentació i en les qüestions relacionades ales dades i variables i mostrar.
La sintaxi és la següent:
DEF:vname=rrdfile:ds-name:CF[:step=step][:start=time][:end=time] CDEF:vname=RPN expression VDEF:vname=RPN expression
Es necessita com a mínim un DEF i una LINE o AREA o GPRINT o PRINT per tal de generar quelcom útil.
Les tres instruccions anteriors (DEF, CDEF i VDEF) extreuen valors dels fitxers RRD. Opcionalment a més poden alterar les dades abans de mostrar-les (per exemple una conversió de bytes a bits)
El nom de la variable (vname) ha de complir les següents normes: els caràcters vàlids són A-Z, a-z, 0-9, -,_ i una mida màxima de 255 caràcters. Al escollir el nom de les variables és una bona idea utilitzar noms en mínuscules i així no poden coincidir amb els noms dels operadors de la notació RPN.
DEF
DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=
On:
Un exemple:
DEF:a="random.rrd":random:AVERAGE
Altres opcions:
TODO By default, an RRA which contains the correct consolidated data at an appropriate resolution will be chosen. The resolution can be overridden with the --step option. The resolution can again be overridden by specifying the step size. The time span of this data is the same as for the graph by default, you can override this by specifying start and end. Remember to escape colons in the time specification! If the resolution of the data is higher than the resolution of the graph, the data will be further consolidated. This may result in a graph that spans slightly more time than requested. Ideally each point in the graph should correspond with one CDP from an RRA. For instance, if your RRD has an RRA with a resolution of 1800 seconds per CDP, you should create an image with width 400 and time span 400*1800 seconds (use appropriate start and end times, such as --start end-8days8hours). If consolidation needs to be done, the CF of the RRA specified in the DEF itself will be used to reduce the data density. This behavior can be changed using :reduce=<CF>. This optional parameter specifies the CF to use during the data reduction phase.
Altres exemples:
DEF:ds0=router.rrd:ds0:AVERAGE DEF:ds0weekly=router.rrd:ds0:AVERAGE:step=7200 DEF:ds0weekly=router.rrd:ds0:AVERAGE:start=end-1h DEF:ds0weekly=router.rrd:ds0:AVERAGE:start=11\:00:end=start+1h
VDEF
VDEF:vname=RPN expression
This command returns a value and/or a time according to the RPN statements used. The resulting vname will, depending on the functions used, have a value and a time component. When you use this vname in another RPN expression, you are effectively inserting its value just as if you had put a number at that place. The variable can also be used in the various graph and print elements.
Example: VDEF:avg=mydata,AVERAGE
Note that currently only aggregation functions work in VDEF rpn expressions. Patches to change this are welcome.
CDEF
CDEF:vname=RPN expression
This command creates a new set of data points (in memory only, not in the RRD file) out of one or more other data series. The RPN instructions are used to evaluate a mathematical function on each data point. The resulting vname can then be used further on in the script, just as if it were generated by a DEF instruction.
Example: CDEF:mydatabits=mydata,8,*
About CDEF versus VDEF
At some point in processing, RRDtool has gathered an array of rates ready to display.
CDEF works on such an array. For example, CDEF:new=ds0,8,* would multiply each of the array members by eight (probably transforming bytes into bits). The result is an array containing the new values.
VDEF also works on such an array but in a different way. For example, VDEF:max=ds0,MAXIMUM would scan each of the array members and store the maximum value. When do you use VDEF versus CDEF?
Use CDEF to transform your data prior to graphing. In the above example, we'd use a CDEF to transform bytes to bits before graphing the bits.
You use a VDEF if you want max(1,5,3,2,4) to return five which would be displayed in the graph's legend (to answer, what was the maximum value during the graph period).
If you want to apply 'complex' operations to the result of a VDEF you have to use a CDEF again since VDEFs only look like RPN expressions, they aren't really.
Quin rang dades mostrar
Cal indicar el rang de temps amb els paràmetres:
[-s|--start time] [-e|--end time] [-S|--step seconds]
Els valors per defecte són:
Mostrar la gràfica dels últims 86400 segons (un dia abans) amb la millor possible resol·lució (step igual al de les dades recollides?)
Els valors de temps d'inici i final es poden indicar de diverses formes (en segons des de 1/1/19170, en valors negatius des de la data actual, etc.)
L'opció step permet modificar la resol·lució. Si es posa un valor d'step menor que el que s'ha utilitzat per recollir les dades no es millora res. Si s'utilitza un valor més gran es mostra una resol·lució pitjor
Títols
[-t|--title string] [-v|--vertical-label string]
-t Permet indicar el títol de la gràfica (el que apareix a la part superior) i -v permet posar el títol de l'axis vertical.
Mides
[-w|--width pixels] [-h|--height pixels] [-j|--only-graph] [-D|--full-size-mode]
Els valors per defecte són: 400x100 pixels. If you specify the --full-size-mode option, the width and height specify the final dimensions of the output image and the canvas is automatically resized to fit.
Es pot obtenir un thumbnail amb:
--only-graph i height < 32 pixels
Límits
[-u|--upper-limit value] [-l|--lower-limit value] [-r|--rigid]
Per defecte la gràfica s'autoescala. Es pot canviar aquest comportament modificant els valors indicats.
Y-Axis
[-y|--y-grid grid step:label factor] [-y|--y-grid none]
Y-axis grid lines appear at each grid step interval. Labels are placed every label factor lines. You can specify -y none to suppress the grid and labels altogether. The default for this option is to automatically select sensible values.
If you have set --y-grid to 'none' not only the labels get suppressed, also the space reserved for the labels is removed. You can still add space manually if you use the --units-length command to explicitly reserve space.
[-Y|--alt-y-grid]
Place the Y grid dynamically based on the graph's Y range. The algorithm ensures that you always have a grid, that there are enough but not too many grid lines, and that the grid is metric. That is the grid lines are placed every 1, 2, 5 or 10 units. This parameter will also ensure that you get enough decimals displayed even if your graph goes from 69.998 to 70.001. (contributed by Sasha Mikheev).
[-o|--logarithmic]
Logarithmic y-axis scaling.
[-X|--units-exponent value]
This sets the 10**exponent scaling of the y-axis values. Normally, values will be scaled to the appropriate units (k, M, etc.). However, you may wish to display units always in k (Kilo, 10e3) even if the data is in the M (Mega, 10e6) range, for instance. Value should be an integer which is a multiple of 3 between -18 and 18 inclusively. It is the exponent on the units you wish to use. For example, use 3 to display the y-axis values in k (Kilo, 10e3, thousands), use -6 to display the y-axis values in u (Micro, 10e-6, millionths). Use a value of 0 to prevent any scaling of the y-axis values.
This option is very effective at confusing the heck out of the default RRDtool autoscaling function and grid painter. If RRDtool detects that it is not successful in labeling the graph under the given circumstances, it will switch to the more robust --alt-y-grid mode.
[-L|--units-length value]
How many digits should RRDtool assume the y-axis labels to be? You may have to use this option to make enough space once you start fiddling with the y-axis labeling.
[--units=si]
With this option y-axis values on logarithmic graphs will be scaled to the appropriate units (k, M, etc.) instead of using exponential notation. Note that for linear graphs, SI notation is used by default.
Right Y Axis
[--right-axis scale:shift] [--right-axis-label label]
A second axis will be drawn to the right of the graph. It is tied to the left axis via the scale and shift parameters. You can also define a label for the right axis.
[--right-axis-format format-string]
By default the format of the axis labels gets determined automatically. If you want to do this your self, use this option with the same %lf arguments you know from the PRINT and GPRINT commands.
Llegenda
[-g|--no-legend]
Suppress generation of the legend; only render the graph.
[-F|--force-rules-legend]
Force the generation of HRULE and VRULE legends even if those HRULE or VRULE will not be drawn because out of graph boundaries (mimics behavior of pre 1.0.42 versions).
[--legend-position=(north|south|west|east)]
Place the legend at the given side of the graph. The default is south. In west or east position it is necessary to add line breaks manually.
[--legend-direction=(topdown|bottomup)]
Place the legend items in the given vertical order. The default is topdown. Using bottomup the legend items appear in the same vertical order as a stack of lines or areas.
Miscellaneous
[-z|--lazy]
Only generate the graph if the current graph is out of date or not existent. Note, that all the calculations will happen regardless so that the output of PRINT and graphv will be complete regardless. Note that the behavior of lazy in this regard has seen several changes over time. The only thing you can really rely on before RRDtool 1.3.7 is that lazy will not generate the graph when it is already there and up to date, and also that it will output the size of the graph.
[--daemon address]
Address of the rrdcached daemon. If specified, a flush command is sent to the server before reading the RRD files. This allows the graph to contain fresh data even if the daemon is configured to cache values for a long time. For a list of accepted formats, see the -l option in the rrdcached manual.
rrdtool graph [...] --daemon unix:/var/run/rrdcached.sock [...]
[-f|--imginfo printfstr]
After the image has been created, the graph function uses printf together with this format string to create output similar to the PRINT function, only that the printf function is supplied with the parameters filename, xsize and ysize. In order to generate an IMG tag suitable for including the graph into a web page, the command line would look like this:
--imginfo '<IMG SRC="/img/%s" WIDTH="%lu" HEIGHT="%lu" ALT="Demo">'
[-c|--color COLORTAG#rrggbb[aa]]
Override the default colors for the standard elements of the graph. The COLORTAG is one of BACK background, CANVAS for the background of the actual graph, SHADEA for the left and top border, SHADEB for the right and bottom border, GRID, MGRID for the major grid, FONT for the color of the font, AXIS for the axis of the graph, FRAME for the line around the color spots, and finally ARROW for the arrow head pointing up and forward. Each color is composed out of three hexadecimal numbers specifying its rgb color component (00 is off, FF is maximum) of red, green and blue. Optionally you may add another hexadecimal number specifying the transparency (FF is solid). You may set this option several times to alter multiple defaults.
A green arrow is made by: --color ARROW#00FF00
[--grid-dash on:off]
by default the grid is drawn in a 1 on, 1 off pattern. With this option you can set this yourself
--grid-dash 1:3 for a dot grid --grid-dash 1:0 for uninterrupted grid lines
[--border width]]
Width in pixels for the 3d border drawn around the image. Default 2, 0 disables the border. See SHADEA and SHADEB above for setting the border color.
[--dynamic-labels]
Pick the shape of the color marker next to the label according to the element drawn on the graph.
[-m|--zoom factor]
Zoom the graphics by the given amount. The factor must be > 0
[-n|--font FONTTAG:size:[font]]
This lets you customize which font to use for the various text elements on the RRD graphs. DEFAULT sets the default value for all elements, TITLE for the title, AXIS for the axis labels, UNIT for the vertical unit label, LEGEND for the graph legend, WATERMARK for the watermark on the edge of the graph.
Use Times for the title: --font TITLE:13:Times
Note that you need to quote the argument to --font if the font-name contains whitespace: --font "TITLE:13:Some Font"
If you do not give a font string you can modify just the size of the default font: --font TITLE:13:.
If you specify the size 0 then you can modify just the font without touching the size. This is especially useful for altering the default font without resetting the default fontsizes: --font DEFAULT:0:Courier.
RRDtool comes with a preset default font. You can set the environment variable RRD_DEFAULT_FONT if you want to change this.
RRDtool uses Pango for its font handling. This means you can to use the full Pango syntax when selecting your font:
The font name has the form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a comma separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace separated list of words where each WORD describes one of style, variant, weight, stretch, or gravity, and SIZE is a decimal number (size in points) or optionally followed by the unit modifier "px" for absolute size. Any one of the options may be absent.
[-R|--font-render-mode {normal,light,mono}]
There are 3 font render modes:
normal: Full Hinting and Anti-aliasing (default)
light: Slight Hinting and Anti-aliasing
mono: Full Hinting and NO Anti-aliasing
[-B|--font-smoothing-threshold size]
(this gets ignored in 1.3 for now!)
This specifies the largest font size which will be rendered bitmapped, that is, without any font smoothing. By default, no text is rendered bitmapped.
[-P|--pango-markup]
All text in RRDtool is rendered using Pango. With the --pango-markup option, all text will be processed by pango markup. This allows to embed some simple html like markup tags using
text
Apart from the verbose syntax, there are also the following short tags available.
b Bold
big Makes font relatively larger, equivalent to
i Italic
s Strikethrough
sub Subscript
sup Superscript
small Makes font relatively smaller, equivalent to
tt Monospace font
u Underline
More details on http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html.
[-G|--graph-render-mode {normal,mono}]
There are 2 render modes:
normal: Graphs are fully Anti-aliased (default)
mono: No Anti-aliasing
[-E|--slope-mode]
RRDtool graphs are composed of stair case curves by default. This is in line with the way RRDtool calculates its data. Some people favor a more 'organic' look for their graphs even though it is not all that true.
[-a|--imgformat PNG|SVG|EPS|PDF]
Image format for the generated graph. For the vector formats you can choose among the standard Postscript fonts Courier-Bold, Courier-BoldOblique, Courier-Oblique, Courier, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, Helvetica, Symbol, Times-Bold, Times-BoldItalic, Times-Italic, Times-Roman, and ZapfDingbats.
[-i|--interlaced]
(this gets ignored in 1.3 for now!)
If images are interlaced they become visible on browsers more quickly.
[-T|--tabwidth value]
By default the tab-width is 40 pixels, use this option to change it.
[-b|--base value]
If you are graphing memory (and NOT network traffic) this switch should be set to 1024 so that one Kb is 1024 byte. For traffic measurement, 1 kb/s is 1000 b/s.
[-W|--watermark string]
Adds the given string as a watermark, horizontally centered, at the bottom of the graph. Data and variables
DEF:vname=rrdfile:ds-name:CF[:step=step][:start=time][:end=time]
CDEF:vname=RPN expression
VDEF:vname=RPN expression
You need at least one DEF and one LINE, AREA, GPRINT, PRINT statement to generate anything useful.
See rrdgraph_data and rrdgraph_rpn for the exact format.
NOTE: Graph and print elements
You need at least one graph element to generate an image and/or at least one print statement to generate a report. See rrdgraph_graph for the exact format. graphv
Calling RRDtool with the graphv option will return information in the RRDtool info format. On the command line this means that all output will be in key=value format. When used from the Perl and Ruby bindings a hash pointer will be returned from the call.
When the filename '-' is given, the contents of the graph itself will also be returned through this interface (hash key 'image'). On the command line the output will look like this:
print[0] = "0.020833" print[1] = "0.0440833" graph_left = 51 graph_top = 22 graph_width = 400 graph_height = 100 graph_start = 1232908800 graph_end = 1232914200 image_width = 481 image_height = 154 value_min = 0.0000000000e+00 value_max = 4.0000000000e-02 image = BLOB_SIZE:8196 [... 8196 bytes of image data ...]
There is more information returned than in the standard interface. Especially the 'graph_*' keys are new. They help applications that want to know what is where on the graph. ENVIRONMENT VARIABLES
The following environment variables may be used to change the behavior of rrdtool graph:
RRDCACHED_ADDRESS
If this environment variable is set it will have the same effect as specifying the --daemon option on the command line. If both are present, the command line argument takes precedence.
SEE ALSO
rrdgraph gives an overview of how rrdtool graph works. rrdgraph_data describes DEF,CDEF and VDEF in detail. rrdgraph_rpn describes the RPN language used in the ?DEF statements. rrdgraph_graph page describes all of the graph and print functions.
Make sure to read rrdgraph_examples for tips&tricks. AUTHOR
Program by Tobias Oetiker <[email protected]>
This manual page by Alex van den Bogaerdt <[email protected]> with corrections and/or additions by several people
01/06/11 | Program by Tobias Oetiker | OETIKER+PARTNER AG
Cacti és una aplicació web que permet gestionar RRDTool sense conèixer els detalls de l'eina i de fet s'encarrega de seguir tots els passos del flux de treball habitual de RRDTool:
RRDTool utilitza RPN aka Reverse Polish Notation. Es tracta d'una notació matemàtica per a fer operacions.
Primer un exemple tonto però fàcil d'utilitzar (no cal esperar...)
Exemple tonto
Creem una carpeta de treball:
$ cd $ mkdir exempleRRD && cd exempleRRD
Ara creem una base de dades RRD:
$ sudo apt-get install rrdtool perl $ rrdtool create random.rrd \ --step 1 \ DS:random:GAUGE:5:U:U \ RRA:AVERAGE:0.5:1:60 \ RRA:AVERAGE:0.5:60:60
Estem creant una base de dades RRD al fitxer random.rrd, que espera dades cada segon i de tipus GAUGE. Els arxius RRA seran per a cada minut i cada hora
Ara creem un script per obtenir dades i actualitzar la base de dades RRD. L'script obtindrà valors enters aleatòries.
$ joe update.sh
#!/bin/bash a=0 while [ 1 ] do value=$RANDOM echo $value rrdtool update random.rrd N:$value sleep 1 done # end of while loop
$ sudo chmod +x update.sh $ ./update.sh &
Podeu monitoritzar l'estat de la base de dades amb:
$ watch -n 1 "rrdtool dump random.rrd"
Per crear la gràfica:
$ /usr/bin/rrdtool graph - --imgformat=PNG --start=-3600 --end=-300 --title='RANDOM' --base=1000 --height=120 --width=500 --alt-autoscale-max --lower- limit=0 --vertical-label= --slope-mode --font TITLE:12: --font AXIS:8: --font LEGEND:10: --font UNIT:8: DEF:a="random.rrd":random:AVERAGE LINE1:a#F5F800FF:"RANDOM" GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" > grafica.png
En resum:
Exemple més real
Creem una carpeta de treball:
$ cd $ mkdir exempleRRD1 && cd exempleRRD1
Ara creem una base de dades RRD:
$ 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
Estem creant una base de dades RRD al fitxer target.rrd, que espera dades cada 300 segons ( 5 minuts) i de tipus GAUGE. Els arxius RRA seran diaris i mensuals.
Ara cal obtenir les dades de forma periòdica i actualitzar la base de dades RRD amb les dades obtingudes. Podeu crear un script com el següent
#!/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
Per a crear una base de dades RRD:
$ /usr/bin/rrdtool create \ /var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd \ --step 300 \ DS:snmp_oid:COUNTER:600:0:100 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 \
Com podeu veure les bases de dades RRD es guarden en un fitxer de tipus binari (no podreu llegir el seu contingut amb un editor de text):
$ file /var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd target.rrd: RRDTool DB version 0003
$ rrdtool info /var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd filename = "/var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd" rrd_version = "0003" step = 300 last_update = 1300798510 ds[snmp_oid].type = "COUNTER" ds[snmp_oid].minimal_heartbeat = 600 ds[snmp_oid].min = 0,0000000000e+00 ds[snmp_oid].max = 1,0000000000e+02 ds[snmp_oid].last_ds = "U" ds[snmp_oid].value = NaN ds[snmp_oid].unknown_sec = 10 rra[0].cf = "AVERAGE" rra[0].rows = 600 rra[0].cur_row = 268 rra[0].pdp_per_row = 1 rra[0].xff = 5,0000000000e-01 rra[0].cdp_prep[0].value = NaN rra[0].cdp_prep[0].unknown_datapoints = 0 rra[1].cf = "AVERAGE" rra[1].rows = 700 rra[1].cur_row = 122 rra[1].pdp_per_row = 6 rra[1].xff = 5,0000000000e-01 rra[1].cdp_prep[0].value = NaN rra[1].cdp_prep[0].unknown_datapoints = 5 rra[2].cf = "AVERAGE" rra[2].rows = 775 rra[2].cur_row = 632 rra[2].pdp_per_row = 24 rra[2].xff = 5,0000000000e-01 rra[2].cdp_prep[0].value = NaN rra[2].cdp_prep[0].unknown_datapoints = 11 rra[3].cf = "AVERAGE" rra[3].rows = 797 rra[3].cur_row = 128 rra[3].pdp_per_row = 288 rra[3].xff = 5,0000000000e-01 rra[3].cdp_prep[0].value = NaN rra[3].cdp_prep[0].unknown_datapoints = 155 rra[4].cf = "MAX" rra[4].rows = 600 rra[4].cur_row = 334 rra[4].pdp_per_row = 1 rra[4].xff = 5,0000000000e-01 rra[4].cdp_prep[0].value = NaN rra[4].cdp_prep[0].unknown_datapoints = 0 rra[5].cf = "MAX" rra[5].rows = 700 rra[5].cur_row = 588 rra[5].pdp_per_row = 6 rra[5].xff = 5,0000000000e-01 rra[5].cdp_prep[0].value = NaN rra[5].cdp_prep[0].unknown_datapoints = 5 rra[6].cf = "MAX" rra[6].rows = 775 rra[6].cur_row = 81 rra[6].pdp_per_row = 24 rra[6].xff = 5,0000000000e-01 rra[6].cdp_prep[0].value = NaN rra[6].cdp_prep[0].unknown_datapoints = 11 rra[7].cf = "MAX" rra[7].rows = 797 rra[7].cur_row = 651 rra[7].pdp_per_row = 288 rra[7].xff = 5,0000000000e-01 rra[7].cdp_prep[0].value = NaN rra[7].cdp_prep[0].unknown_datapoints = 155
Exemple de gràfica de la última setmana (--start=86400 en segons són 24 hores)
/usr/bin/rrdtool graph - \ --imgformat=PNG \ --start=-86400 \ --end=-300 \ --title='SecImpressoraHPLJ2200 - Nmero de pgines' \ --base=1000 \ --height=120 \ --width=500 \ --alt-autoscale-max \ --lower-limit=0 \ --vertical-label= \ --slope-mode \ --font TITLE:12: \ --font AXIS:8: \ --font LEGEND:10: \ --font UNIT:8: \ DEF:a="/var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd":snmp_oid:AVERAGE \ AREA:a#F5F800FF:"Número de pàgines" \ GPRINT:a:LAST:"Current\:%8.2lf %s" \ GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \ GPRINT:a:MAX:"Maximum\:%8.2lf %s\n"
On:
$ file /var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd /var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd: RRDTool DB version 0003
és el fitxer que conté la base de dades circular
Es mostra la imatge per la sortida estàndard (veureu brossa per la terminal). Si us interessa guardar-la en un fitxer:
/usr/bin/rrdtool graph - \ --imgformat=PNG \ --start=-86400 \ --end=-300 \ --title='SecImpressoraHPLJ2200 - Nmero de pgines' \ --base=1000 \ --height=120 \ --width=500 \ --alt-autoscale-max \ --lower-limit=0 \ --vertical-label= \ --slope-mode \ --font TITLE:12: \ --font AXIS:8: \ --font LEGEND:10: \ --font UNIT:8: \ DEF:a="/var/lib/cacti/rra/secimpressorahplj2200_snmp_oid_371.rrd":snmp_oid:AVERAGE \ AREA:a#F5F800FF:"Número de pàgines" \ GPRINT:a:LAST:"Current\:%8.2lf %s" \ GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \ GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" > imatge.png
http://stackoverflow.com/questions/19412394/which-rrdtool-dst-data-source-type-to-use-for-a-0-1-value
Format:
RRA:CF:xff:steps:rows:
On:
The biggest issue to me was discover the right value to steps and rows. So reading, I came with this explanation:
1 day - 5-minute resolution 1 week - 15-minute resolution 1 month - 1-hour resolution 1 year - 6-hour resolution RRA:AVERAGE:0.5:1:288 \ RRA:AVERAGE:0.5:3:672 \ RRA:AVERAGE:0.5:12:744 \ RRA:AVERAGE:0.5:72:1480
Put in mind the our step is 300 seconds, so, the idea is very simple though: If I want to resolute one day which has 86400 seconds, as shown in first example, how many rows do I need ? The answer is 288 rows. Why ?
`86400 seconds [1 day] / 300 seconds [5 minutes`] = 288 rows
Another example, if I want to resolute:
1 week [ = 604800 seconds ] in 15 minutes [ = 900 seconds ] = 604800/900 = 672 rows
And so go on, for the other values, this way you gonna find out how many rows do you need. To find out how many steps do you need, is very simple, you just have to take the multiplier of your steps.
Let me explain, our steps are 300 seconds, right ?
So if we want to resolute 5 minutes [ = 300 seconds ], we just need multiply by 1, right ? So, 15 minutes means by 300 seconds x 3, 1 hour means 300 x 12, 6 hours mean 300 x 72 and so on.
In my case specific, I would like to my steps be 30 seconds, so I came up with these structure:
1 every time 30 seconds 1 * 30s = 30s 2 every second time 1 minute 2 * 30s = 1m 4 every third time 2 minutes 4 * 30s = 2m 10 every 10th time 5 minutes 10 * 30s = 5m 20 every 20th time 10 minutes 20 * 30s = 10m 60 every 60th time 30 minutes 60 * 30s = 30m 80 every 80th time 40 minutes 80 * 30s = 40m 100 every 100th time 50 minutes 100 * 30s = 50m 120 every 120th time 1 hour 120 * 30s = 1h 240 every 240th time 2 hours 240 * 30s = 2h 360 every 360th time 3 hours 360 * 30s = 3h
RRA:AVERAGE:0.5:1:120 \ RRA:AVERAGE:0.5:2:120 \ RRA:AVERAGE:0.5:4:120 \ RRA:AVERAGE:0.5:10:288 \ RRA:AVERAGE:0.5:20:1008 \ RRA:AVERAGE:0.5:60:1440 \ RRA:AVERAGE:0.5:80:3240 \ RRA:AVERAGE:0.5:100:5184 \ RRA:AVERAGE:0.5:120:8760 \ RRA:AVERAGE:0.5:240:8760 \ RRA:AVERAGE:0.5:360:8760 \
Which means:
1 hour - 30 seconds resolution 2 hours - 1 minute resolution 4 hours - 2 minutes resolution 1 day - 5 minutes resolution 1 week - 10 minutes resolution 1 month - 30 minutes resolution 3 months - 40 minutes resolution 6 months - 50 minutes resolution 1 year - 1 hour resolution 2 year - 2 hour resolution 3 year - 3 hour resolution
Well, I hope this helps someone, that's all.