User Tools

Site Tools


informatica:linux:generar_graficos

This is an old revision of the document!


RRDTOOL

Crear la Base de datos

Por ejemplo queremos hacer una gráfica de tiempo de respuesta de una servicio Los datos serían estos:

Día: 26/11/2010

Horamsecs
08001245
0830807
09001876
0930572
1000549
1030590
1100410
1130611
12000
1230788
1300349
1330542
1400576
1430661
1500659

La fecha tiene que estar en UNIX time, que son los segundos que han pasado desde el 1 enero de 1970, para convertir una fecha a unixtime usamos:

# date +%s -d"2010-11-26 08:00:00"
1290754800

Para crear la Base de Datos seguimos el siguiente formato:

rrdtool create <fichero>.rrd --start <tiempo_inicio> --step=<tiempo_medicion> DS:<nombre_variable>:<DST>:<heartbeat>:<min>:<max>  RRA:CF:xff:step:rows
  • tiempo_inicio= tiempo de la primera medición en UNIX TIME
  • tiempo_medicion= cada cuanto tiempo se toma una muestra en segundos. Si se omite esta opción, son 300 (5 minutos)
  • nombre_variable= nombre del campo en la base de datos
  • DST= puede ser COUNTER, DERIVE, ABSOLUTE, GAUGE
  • heartbeat= cada cuanto se fuerza la medida. Si por ejemplo son 300 segundos y el heartbeat es de 600, esperarà 600 segundos y sinó pondrá un UNKNOWN
  • min y max: si no se sabe se pone U y lo cálcula

Falta traducir y resumir de http://oss.oetiker.ch/rrdtool/tut/rrd-beginners.en.html

RRA:CF:xff:step:rows

Lets have a look at the example above. For the first RRA, 12 (steps) PDPs (DS variables) are AVERAGEed (CF) to form one CDP. 24 (rows) of theses CDPs are archived. Each PDP occurs at 300 seconds. 12 PDPs represent 12 times 300 seconds which is 1 hour. It means 1 CDP (which is equal to 12 PDPs) represents data worth 1 hour. 24 such CDPs represent 1 day (1 hour times 24 CDPs). This means, this RRA is an archive for one day. After 24 CDPs, CDP number 25 will replace the 1st CDP. The second RRA saves 31 CDPs; each CPD represents an AVERAGE value for a day (288 PDPs, each covering 300 seconds = 24 hours). Therefore this RRA is an archive for one month. A single database can have many RRAs. If there are multiple DSs, each individual RRA will save data for all the DSs in the database. For example, if a database has 3 DSs and daily, weekly, monthly, and yearly RRAs are declared, then each RRA will hold data from all 3 data sources.

  • CF= AVERAGE, MINIMUM, MAXIMUM, and LAST

Ponemos que empieza 30 minutos antes que la primera medición:

rrdtool create tiempo_respuesta.rrd --start 1290753000 --step=1800 DS:respuesta:GAUGE:1800:0:10000 RRA:LAST:0.5:1:24

Introduciendo los datos

Cambiamos las fechas a UNIX Time, queda tal que así: Con lo que los datos nos quedarían:

Horamsecs
12907548001245
1290756600807
12907584001876
etc…
rrdtool update tiempo_respuesta.rrd 1290754800:1245 1290756600:807 1290758400:1876 1290760200:572 1290762000:549 1290763800:590 1290765600:410 1290767400:611 1290769200:0 1290771000:788 1290772800:349 1290774600:542 1290776400:576 1290778200:661 1290780000:659

Crear el gráfico

rrdtool graph tiempo_respuesta.png --start 1290754800 --end 1290780000 DEF:respuesta=tiempo_respuesta.rrd:respuesta:LAST LINE2:respuesta#FF0000

Ejemplos

Max, min y media

rrdtool create min.rrd --start 1290753000 --step=1800 DS:respuesta:GAUGE:1800:0:10000 RRA:LAST:0.5:1:24
rrdtool create max.rrd --start 1290753000 --step=1800 DS:respuesta:GAUGE:1800:0:10000 RRA:LAST:0.5:1:24
rrdtool create avg.rrd --start 1290753000 --step=1800 DS:respuesta:GAUGE:1800:0:10000 RRA:LAST:0.5:1:24

rrdtool update min.rrd 1290754800:1245 1290756600:807 1290758400:1876 1290760200:572 1290762000:549 1290763800:590 1290765600:410 1290767400:611 1290769200:0 1290771000:788 1290772800:349 1290774600:542 1290776400:576 1290778200:661 1290780000:659

rrdtool update avg.rrd 1290754800:2345 1290756600:1407 1290758400:2176 1290760200:672 1290762000:749 1290763800:790 1290765600:810 1290767400:611 1290769200:123 1290771000:988 1290772800:649 1290774600:742 1290776400:976 1290778200:671 1290780000:959

rrdtool update max.rrd 1290754800:2845 1290756600:1607 1290758400:2276 1290760200:772 1290762000:949 1290763800:1090 1290765600:1010 1290767400:811 1290769200:423 1290771000:1488 1290772800:949 1290774600:942 1290776400:1376 1290778200:871 1290780000:1559

rdtool graph tiempo_respuesta.png --start 1290754800 --end 1290780000 DEF:min=min.rrd:respuesta:LAST LINE1:min#002A97FF DEF:avg=avg.rrd:respuesta:LAST LINE1:avg#000000 DEF:max=max.rrd:respuesta:LAST LINE1:max#FF0000

XGRAPH

Se instala la aplicación xgraph

Salida por las X

Genera una gráfica en entorno gráfico.
Se crea un fichero.txt con estos datos:

       TitleText: Sample Data
       0.5 7.8
       1.0 6.2
       "set one
       1.5 8.9

       "set two"
       -3.4 1.4e-3
       -2.0 1.9e-2
       move -1.0 2.0e-2
       -0.65 2.2e-4

       2.2 12.8
       2.4 -3.3
       2.6 -32.2
       2.8 -10.3

Y se ejecuta:

xgraph fichero.txt

Salida en un fichero

Da error:

# xgraph -device ps -o prueba.ps pruebaxgraph.txt 
Fallo de segmentación
informatica/linux/generar_graficos.1387209766.txt.gz · Last modified: 2015/04/13 20:19 (external edit)