Инструменты пользователя

Инструменты сайта


freebsd:rrdtool-rrdcgi

Создание графика температуры с помощью RRDTool - rrdcgi

Веб-сервер, у меня Apache.
Добавляю в /usr/local/etc/apache22/httpd.conf следующие строки для обработки cgi скриптов

Alias /term "/usr/local/www/term/"
<Directory "/usr/local/www/term/">
    Options FollowSymLinks ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex index.cgi
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

Директория /usr/local/www/term – являеться корневой для термометра.
Создадю ее

# mkdir /usr/local/www/temperature

Назначаю права на созданную директорию

# chown www:www /usr/local/www/temperature

Рестартую apache

# apachectl restart

Т.к. RRDTool ставиться при установки cacti и отрисовка температуры у меня уже осуществляется, то я использую базу данных cacti.

Создаю cgi скрипт

  # cat > /usr/local/www/term/index.cgi
  #!/usr/local/bin/rrdcgi
 
  <HTML>
  <HEAD>
    <CONTENT="text/html; charset=UTF-8">
     <META HTTP-EQUIV=refresh content='300'>
     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    <TITLE>Температура воздуха в г.Георгиевск</TITLE>
  </HEAD>
  <BODY>
  <CENTER>
  <H2>Температура воздуха в г.Георгиевск</H2>
  <RRD::GRAPH /usr/local/www/term/png/temp1d.png --lazy --rigid --slope-mode --width 500 --heigh 200
  --title "Температура за сутки" --start -1d --font TITLE:13 --color BACK#164A4A
  --color SHADEA#444444 --color SHADEB#444444 --color CANVAS#2E7778
  --color FONT#ff7518 --slope-mode --imginfo
  '<IMG SRC=png/%s WIDTH=%lu HEIGHT=%lu>'
  DEF:temperature=/usr/local/share/cacti/rra/klotik_ru_snmp_oid_10.rrd:snmp_oid:AVERAGE
  CDEF:tp_34=temperature,0,GT,temperature,100,GT,34,temperature,IF,0,IF AREA:tp_34#FF0000
  CDEF:tp_33=temperature,0,GT,temperature,33,GT,33,temperature,IF,0,IF AREA:tp_34#FF0F00
  CDEF:tp_32=temperature,0,GT,temperature,32,GT,32,temperature,IF,0,IF AREA:tp_32#FF1700
  CDEF:tp_31=temperature,0,GT,temperature,31,GT,31,temperature,IF,0,IF AREA:tp_31#FF1F00
  CDEF:tp_30=temperature,0,GT,temperature,30,GT,30,temperature,IF,0,IF AREA:tp_30#FF2700
  CDEF:tp_29=temperature,0,GT,temperature,29,GT,29,temperature,IF,0,IF AREA:tp_29#FF2F00
  CDEF:tp_28=temperature,0,GT,temperature,28,GT,28,temperature,IF,0,IF AREA:tp_28#FF3700
  CDEF:tp_27=temperature,0,GT,temperature,27,GT,27,temperature,IF,0,IF AREA:tp_27#FF3F00
  CDEF:tp_26=temperature,0,GT,temperature,26,GT,26,temperature,IF,0,IF AREA:tp_26#FF4700
  CDEF:tp_25=temperature,0,GT,temperature,25,GT,25,temperature,IF,0,IF AREA:tp_25#FF4F00
  CDEF:tp_24=temperature,0,GT,temperature,24,GT,24,temperature,IF,0,IF AREA:tp_24#FF5700
  CDEF:tp_23=temperature,0,GT,temperature,23,GT,23,temperature,IF,0,IF AREA:tp_23#FF5F00
  CDEF:tp_22=temperature,0,GT,temperature,22,GT,22,temperature,IF,0,IF AREA:tp_22#FF6700
  CDEF:tp_21=temperature,0,GT,temperature,21,GT,21,temperature,IF,0,IF AREA:tp_21#FF6F00
  CDEF:tp_20=temperature,0,GT,temperature,20,GT,20,temperature,IF,0,IF AREA:tp_20#FF7700
  CDEF:tp_19=temperature,0,GT,temperature,19,GT,19,temperature,IF,0,IF AREA:tp_19#FF7F00
  CDEF:tp_18=temperature,0,GT,temperature,18,GT,18,temperature,IF,0,IF AREA:tp_18#FF8700
  CDEF:tp_17=temperature,0,GT,temperature,17,GT,17,temperature,IF,0,IF AREA:tp_17#FF8F00
  CDEF:tp_16=temperature,0,GT,temperature,16,GT,16,temperature,IF,0,IF AREA:tp_16#FF9700
  CDEF:tp_15=temperature,0,GT,temperature,15,GT,15,temperature,IF,0,IF AREA:tp_15#FF9F00
  CDEF:tp_14=temperature,0,GT,temperature,14,GT,14,temperature,IF,0,IF AREA:tp_14#FFA700
  CDEF:tp_13=temperature,0,GT,temperature,13,GT,13,temperature,IF,0,IF AREA:tp_13#FFAF00
  CDEF:tp_12=temperature,0,GT,temperature,12,GT,12,temperature,IF,0,IF AREA:tp_12#FFB700
  CDEF:tp_11=temperature,0,GT,temperature,11,GT,11,temperature,IF,0,IF AREA:tp_11#FFBF00
  CDEF:tp_10=temperature,0,GT,temperature,10,GT,10,temperature,IF,0,IF AREA:tp_10#FFC700
  CDEF:tp_09=temperature,0,GT,temperature,09,GT,09,temperature,IF,0,IF AREA:tp_09#FFCF00
  CDEF:tp_08=temperature,0,GT,temperature,8,GT,8,temperature,IF,0,IF  AREA:tp_08#FFD700
  CDEF:tp_07=temperature,0,GT,temperature,7,GT,7,temperature,IF,0,IF  AREA:tp_07#FFDF00
  CDEF:tp_06=temperature,0,GT,temperature,6,GT,6,temperature,IF,0,IF  AREA:tp_06#FFE700
  CDEF:tp_05=temperature,0,GT,temperature,5,GT,5,temperature,IF,0,IF  AREA:tp_05#FFEF00
  CDEF:tp_04=temperature,0,GT,temperature,4,GT,4,temperature,IF,0,IF  AREA:tp_04#FFF700
  CDEF:tp_03=temperature,0,GT,temperature,3,GT,3,temperature,IF,0,IF  AREA:tp_03#FFFF00
  CDEF:tp_02=temperature,0,GT,temperature,2,GT,2,temperature,IF,0,IF  AREA:tp_02#ffff6F
  CDEF:tp_01=temperature,0,GT,temperature,1,GT,1,temperature,IF,0,IF  AREA:tp_01#ffffAF
 
  CDEF:tm_17=temperature,0,LT,temperature,-100,LT,-34,temperature,IF,0,IF AREA:tm_17#0000FF
  CDEF:tm_16=temperature,0,LT,temperature,-32,LT,-32,temperature,IF,0,IF AREA:tm_16#0011FF
  CDEF:tm_15=temperature,0,LT,temperature,-30,LT,-30,temperature,IF,0,IF AREA:tm_15#0022FF
  CDEF:tm_14=temperature,0,LT,temperature,-28,LT,-28,temperature,IF,0,IF AREA:tm_14#0033FF
  CDEF:tm_13=temperature,0,LT,temperature,-26,LT,-26,temperature,IF,0,IF AREA:tm_13#0044FF
  CDEF:tm_12=temperature,0,LT,temperature,-24,LT,-24,temperature,IF,0,IF AREA:tm_12#0055FF
  CDEF:tm_11=temperature,0,LT,temperature,-22,LT,-22,temperature,IF,0,IF AREA:tm_11#0066FF
  CDEF:tm_10=temperature,0,LT,temperature,-20,LT,-20,temperature,IF,0,IF AREA:tm_10#0077FF
  CDEF:tm_09=temperature,0,LT,temperature,-18,LT,-18,temperature,IF,0,IF AREA:tm_09#0088FF
  CDEF:tm_08=temperature,0,LT,temperature,-16,LT,-16,temperature,IF,0,IF AREA:tm_08#0099FF
  CDEF:tm_07=temperature,0,LT,temperature,-14,LT,-14,temperature,IF,0,IF AREA:tm_07#00AAFF
  CDEF:tm_06=temperature,0,LT,temperature,-12,LT,-12,temperature,IF,0,IF AREA:tm_06#00BBFF
  CDEF:tm_05=temperature,0,LT,temperature,-10,LT,-10,temperature,IF,0,IF AREA:tm_05#00CCFF
  CDEF:tm_04=temperature,0,LT,temperature,-8,LT,-8,temperature,IF,0,IF AREA:tm_04#00DDFF
  CDEF:tm_03=temperature,0,LT,temperature,-6,LT,-6,temperature,IF,0,IF AREA:tm_03#00EEFF
  CDEF:tm_02=temperature,0,LT,temperature,-4,LT,-4,temperature,IF,0,IF AREA:tm_02#00FFFF
  CDEF:tm_01=temperature,0,LT,temperature,-2,LT,-2,temperature,IF,0,IF AREA:tm_01#CDFFFF
  LINE1:temperature "GPRINT:temperature:LAST:Сейчас\:%3.2lfC" "GPRINT:temperature:MAX:Максимальная\:%3.2lfC"   "GPRINT:temperature:MIN:Минимальная\:%3.2lfC">
  </BR>
  Данные на: <RRD::TIME::LAST  /usr/local/share/cacti/rra/klotik_ru_snmp_oid_10.rrd "%H:%M,  %d %b %Y">
  </BODY>
  </HTML>
  Ctrl+D

Создаю папку и установливаю владельца для хранения графиков

# mkdir /usr/local/www/term/png
# chown www:www /usr/local/www/term/png/

Захожу браузером на сервер: http://ip_адрес_сервера/term

Параметр –lazy – указывает не пересоздавать график если данные не обновились, для отладки лучше отключить или удалять график в ручную.

Ссылки:
http://dutyadmin.ru/content/rrdtool-teoriya-i-praktika

freebsd/rrdtool-rrdcgi.txt · Последние изменения: 2015/05/22 13:21 (внешнее изменение)