Witam,
Ja mam skonfigurowane następująco:
Cyklicznie co 10 min odpalam sobie skrypt generujący statystyki
za pomocą wget podłączam się do www i generuję obrazki
można generować obrazki bezpośrednio za pomocą rrdtool, na podstawie plików z danymi (znajdującymi się w DataDir), ale ja wybrałem rozwiązanie jak poniżej
Konfiguracja /etc/collectd.conf , w którym skonfigurowałem DataDir do odkładania się plików ze statystykami (baz danych RRDtool)
BaseDir "/var/run/collectd"
Include "/etc/collectd/conf.d"
PIDFile "/var/run/collectd.pid"
PluginDir "/usr/lib/collectd"
TypesDB "/usr/share/collectd/types.db"
Interval 30
ReadThreads 2
LoadPlugin iptables
LoadPlugin df
<Plugin df>
IgnoreSelected false
MountPoint "/hdd"
MountPoint "/overlay"
</Plugin>
LoadPlugin interface
<Plugin interface>
IgnoreSelected false
Interface "eth0.2"
Interface "br-lan"
</Plugin>
LoadPlugin ping
<Plugin ping>
TTL 127
Host "www.google.pl"
Host "www.onet.pl"
</Plugin>
LoadPlugin rrdtool
<Plugin rrdtool>
DataDir "/root/statistic"
RRARows 100
RRASingle true
RRATimespan 600
RRATimespan 3600
RRATimespan 86400
RRATimespan 604800
RRATimespan 2678400
RRATimespan 31622400
</Plugin>
Zawartość pliku konfiguracyjnego cron'a /etc/crontabs/root
0,10,20,30,40,50 * * * * /root/skrypty/getstat.sh
Zawartość skryptu pobierającego statystyki /root/skrypty/getstat.sh
RRDIMG - miejsce w którym generują się obrazki i html, ja podlinkowałem (ln -s) sobie ten katalog w katalogu, który udostępniam po https z autoryzacją
Jeśli potrzebujesz to wystawić bez hasła, to w konfiguracji /etc/config/uhttpd możesz dodać kolejny serwer dla statystyk
Na samym początku skrypt tworzy strukturę html i w zależności od czasu generuje obrazki
#!/bin/sh
# Configuration Start
# Directory for storing webpages / images
RRDIMG=/tmp/rrdimg/server/
# Configuration End
#Output date for log...
date
#600 10 min
#3600 1h
#86400 24h
#604800 1w
#2678400 1m
#31622400 1y
# $1 = html file, $2 = Period, $3 = text
CreateHTML ()
{
echo "<HTML><HEAD><TITLE>STAT</TITLE></HEAD><BODY>" > "${1}"
echo "<center><h3>Graphs - ${3}</h3></center>" > "${1}"
echo "<center><a href='10min.html'>10min</a> | <a href='1hour.html'>1hour</a> | <a href='1day.html'>1day</a> | <a href='1week.html'>1week</a> | <a href='1month.html'>1month</a> | <a href='1year.html'>1year</a>" >> "${1}"
echo "<br>" >> "${1}"
echo "<br><img src='interface/1eth0.2.${2}.png'>" >> "${1}"
echo "<br><img src='interface/1br-lan.${2}.png'>" >> "${1}"
echo "<br><img src='df/1hdd.${2}.png'>" >> "${1}"
echo "<br><img src='df/1overlay.${2}.png'>" >> "${1}"
echo "<br><img src='ping/1.${2}.png'>" >> "${1}"
echo "<br><img src='iptables-filter-input_rule/1.${2}.png'>" >> "${1}"
echo "<br></CENTER></BODY></HTML>" >> "${1}"
echo "Create started..."
}
if [ ! -d "${RRDIMG}" ]
then
echo "RRD Image / web dir: $RRDIMG does not exist....Creating Now...."
mkdir -p "${RRDIMG}"
#chmod -R 666 "${RRDIMG}"
chmod -R 777 /tmp/rrdimg/
fi
if [ ! -f "${RRDIMG}/index.html" ]
then
echo "Create index.html"
CreateHTML "${RRDIMG}/index.html" 86400 1day
fi
if [ ! -f "${RRDIMG}/10min.html" ]
then
echo "Create 10min.html"
CreateHTML "${RRDIMG}/10min.html" 600 10min
fi
if [ ! -f "${RRDIMG}/1hour.html" ]
then
echo "Create 1hour.html"
CreateHTML "${RRDIMG}/1hour.html" 3600 1hour
fi
if [ ! -f "${RRDIMG}/1day.html" ]
then
echo "Create 1day.html"
CreateHTML "${RRDIMG}/1day.html" 86400 1day
fi
if [ ! -f "${RRDIMG}/1week.html" ]
then
echo "Create 1week.html"
CreateHTML "${RRDIMG}/1week.html" 604800 1week
fi
if [ ! -f "${RRDIMG}/1month.html" ]
then
echo "Create 1month.html"
CreateHTML "${RRDIMG}/1month.html" 2678400 1month
fi
if [ ! -f "${RRDIMG}/1year.html" ]
then
echo "Create 1year.html"
CreateHTML "${RRDIMG}/1year.html" 31622400 1year
fi
# $1 = period
CreateGraph ()
{
wget -q 'http://192.168.1.1/cgi-bin/luci/admin/statistics/graph/interface/?timespan='${1}'&username=twojlogin&password=twojehaslo' -O /dev/null
wget -q 'http://192.168.1.1/cgi-bin/luci/admin/statistics/graph/df/?timespan='${1}'&username=twojlogin&password=twojehaslo' -O /dev/null
wget -q 'http://192.168.1.1/cgi-bin/luci/admin/statistics/graph/ping/?timespan='${1}'&username=twojlogin&password=twojehasloa' -O /dev/null
wget -q 'http://192.168.1.1/cgi-bin/luci/admin/statistics/graph/iptables/?timespan='${1}'&username=twojlogin&password=twojehaslo' -O /dev/null
}
# Set time-variables
MTIME=`date "+%M"`
HTIME=`date "+%H"`
echo "MTIME: "${MTIME}
echo "HTIME: "${HTIME}
# Update Daily graphs every 10 mins
if [ "${MTIME}" = 00 ] || [ "${MTIME}" = 10 ] || [ "${MTIME}" = 20 ] || [ "${MTIME}" = 30 ] || [ "${MTIME}" = 40 ] || [ "${MTIME}" = 50 ];
then
# 1 Day Graph
echo "Daily Graphs created....."
CreateGraph 10min
CreateGraph 1hour
CreateGraph 1day
fi
# Update Weekly graph once an hour
if [ "${MTIME}" = 00 ];
then
# 1 Week Graph
echo "Weekly Graphs created....."
CreateGraph 1week
fi
# Update Monthly and Yearly graphs once a day (maby twice a day on 12h settings)
if [ "${HTIME}" = 14 ] && [ "${MTIME}" = 40 ];
then
# 1 Month Graph
echo "Monthly Graphs Created...."
CreateGraph 1month
# 1 Year Graph
echo "Yearly Graphs Created...."
CreateGraph 1year
fi
rm /tmp/luci-sessions/*
echo "end"
p.s. do generowania statystyk można użyć surowego RRDtool, bez potrzeby instalowania luci i collected, ale to wymaga oskryptowania pobierania liczników, więcej roboty, więcej grzebania.... z tego też powodu powstało collected, czy cacti http://www.cacti.net
Pozdrawiam
Piotr