Freifunk-Gateway aufsetzen/Statistik/mrtg: Unterschied zwischen den Versionen

Aus Freifunk Franken
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 77: Zeile 77:
Die mrtg traffic Config neu anlegen:
Die mrtg traffic Config neu anlegen:
<pre>
<pre>
/usr/bin/cfgmaker --output=/etc/mrtg/traffic.cfg  -zero-speed=100000000 --global "WorkDir: /var/www/mrtg" --ifdesc=name,ip,desc,type --ifref=name,desc --global "Options[_]: bits,growright" public@localhost
/usr/bin/cfgmaker --output=/etc/mrtg/traffic.cfg  -zero-speed=100000000 --global "WorkDir: /var/www/mrtg" --ifdesc=name,ip,desc,type --ifref=name,desc --global "Options[_]: bits,growright" public@localhost sed -i -e 's/^\(MaxBytes.*\)$/\10/g' /etc/mrtg/traffic.cfg
sed -i -e 's/^\(MaxBytes.*\)$/\10/g' /etc/mrtg/traffic.cfg
</pre>
</pre>



Version vom 13. November 2016, 19:12 Uhr

snmpd und mrtg installieren.

/etc/snmp/snmpd.conf: systemonly auskommentiert

 rocommunity public  default    #-V systemonly
 rocommunity6 public  default   #-V systemonly

snmpd restarten.

Ordner anlegen:

mkdir /etc/mrtg
mkdir /var/www/mrtg

Die mrtg CPU Config neu anlegen: vi /etc/mrtg/cpu.cfg und folgendes einfügen:

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
WorkDir: /var/www/mrtg
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1 + ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1 + ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1 + ssCpuRawSoftIRQ.0&ssCpuRawSoftIRQ.0:public@127.0.0.1 + ssCpuRawInterrupt.0&ssCpuRawInterrupt.0:public@127.0.0.1 + ssCpuRawKernel.0&ssCpuRawKernel.0:public@127.0.0.1
RouterUptime[localhost.cpu]: public@127.0.0.1
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: <h1>Active CPU Load %</h1>
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]:  Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent

Die mrtg dhcp config neu anlegen: vi /etc/mrtg/dhcp.cfg und folgendes einfügen:

WorkDir: /var/www/mrtg
Title[dhcpleasecount]: DHCP-Leases
PageTop[dhcpleasecount]: <H1>DHCP-Leases</H1>
Options[dhcpleasecount]: gauge,nopercent,growright,noinfo
Target[dhcpleasecount]: `/etc/mrtg/dhcp.sh`
MaxBytes[dhcpleasecount]: 255
YLegend[dhcpleasecount]: Lease Count
ShortLegend[dhcpleasecount]: x
Unscaled[dhcpleasecount]: ymwd
LegendI[dhcpleasecount]: Count
LegendO[dhcpleasecount]:

Hier muss der MaxBytes Parameter auf die maximale Zahl der DHCP Leases eingestellt werden.

Anschließend noch das Script anlegen: vi /etc/mrtg/dhcp.sh
chmod +x /etc/mrtg/dhcp.sh

#!/bin/bash
leasecount=$(/usr/sbin/dhcp-lease-list --parsable --lease /var/lib/dhcp/dhcpd.leases 2>&1  |wc -l)
echo "$leasecount"
echo "$leasecount"
echo 0
echo 0

Die mrtg traffic Config neu anlegen:

/usr/bin/cfgmaker --output=/etc/mrtg/traffic.cfg  -zero-speed=100000000 --global "WorkDir: /var/www/mrtg" --ifdesc=name,ip,desc,type --ifref=name,desc --global "Options[_]: bits,growright" public@localhost sed -i -e 's/^\(MaxBytes.*\)$/\10/g' /etc/mrtg/traffic.cfg

Den mrtg Index neu machen:

/usr/bin/indexmaker --output=/var/www/mrtg/index.html --title="$(hostname)" --sort=name --enumerat /etc/mrtg/traffic.cfg /etc/mrtg/cpu.cfg /etc/mrtg/dhcp.cfg

Den eigenen Index neu machen:

cat /var/www/mrtg/index.html | sed -e 's/SRC="/SRC="mrtg\//g' -e 's/HREF="/HREF="mrtg\//g' -e 's/<\/H1>/<\/H1><img src="topology.png">/g' > /var/www/index.html 

/etc/olsrd/dotDraw.pl:

#!/usr/bin/perl

use IO::Socket;

$TOPPATH = "/var/www";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";
$EXT = "png";

`touch $TOPPATH/$NAME.$EXT`;

$remote = IO::Socket::INET->new(
                        Proto    => "tcp",
                        PeerAddr => "localhost",
                        PeerPort => "2004",
                    )
                  or die "cannot connect to daytime port at localhost";

$f;

while ( <$remote> ) {

        $line = $_;
        if ( m/^[\{\\}]$|digraph|topology|^"10\.50\..*" -> "10\.50.*"|^"10\.50\.[0-9]+\.[0-9\/]+"\[/) {
                $f = $f . $line;
        }

        if ( $line =~ /}/i ) {
                print "* ";
                open DOTFILE, ">$FILENAME";
                print DOTFILE $f;
                close DOTFILE;
                $f = "";

                `neato -Tpng -Gsize=9,6 -Gbgcolor=white -Gsplines=true -Nstyle=filled -Nfontsize=15 -Ncolor=black -Nfillcolor=white -Nfontname=verdana -Ecolor=black -Elen=4 -Earrowsize=2 $FILENAME -o $TOPPATH/$NAME.new`;

                `mv $TOPPATH/$NAME.new $TOPPATH/$NAME.$EXT`;
                `cp $TOPPATH/$NAME.dot $TOPPATH/$NAME-\$(date +'%Y-%m-%d-%H-%M-%S').dot`;
                exit;
        }
}

/etc/olsrd/olsrd.conf:

LoadPlugin "olsrd_dot_draw.so.0.3"
{
}

eventuell wird noch "graphviz" benötigt um die png zu zeichnen:

apt-get install graphviz

Crontab:

*/5 *  *   *   *     perl /etc/olsrd/dotDraw.pl > /dev/null 2>&1
*/1 *  *   *   *     env LANG=C /usr/bin/mrtg /etc/mrtg/cpu.cfg > /dev/null 2>&1
*/1 *  *   *   *     env LANG=C /usr/bin/mrtg /etc/mrtg/traffic.cfg > /dev/null 2>&1
*/1 *  *   *   *     env LANG=C /usr/bin/mrtg /etc/mrtg/dhcp.cfg > /dev/null 2>&1