Outils pour utilisateurs

Outils du site


informatique:mrtg

MRTG

Docs

Softs dérivés

Data acquisition

External Monitoring Scripts

If you want to monitor something which does not provide data via snmp you can use some external program to do the data gathering.
The external command must return 4 lines of output:
  Line 1
      current state of the first variable, normally 'incoming bytes count'
  Line 2
      current state of the second variable, normally 'outgoing bytes count'
  Line 3
      string (in any human readable format), telling the uptime of the target.
  Line 4
      string, telling the name of the target.
Depending on the type of data your script returns you might want to use the 'gauge' or 'absolute' arguments for the Options keyword.

QMail

Agrégation de stats pour QMail avec QMailMRTG7

QMail Message

`/usr/local/bin/qmailmrtg7 m /var/log/qmail`

QMail Queue size

`/usr/local/bin/qmailmrtg7 q /var/qmail/queue`

Qmail Local/Remote concurrency

`/usr/local/bin/qmailmrtg7 c /var/log/qmail`

QMail messages status

`/usr/local/bin/qmailmrtg7 s /var/log/qmail`

QMail Bits transfered

`/usr/local/bin/qmailmrtg7 b /var/log/qmail`

QMail SMTP

`/usr/local/bin/qmailmrtg7 t /var/log/smtp`

QMail SMTP Total

`/usr/local/bin/qmailmrtg7 a /var/log/smtp`

QMail POP3 Concurrency

`/usr/local/bin/qmailmrtg7 t /var/log/pop3`

QMail POP3 Total

`/usr/local/bin/qmailmrtg7 a /var/log/pop3`

SMTP SSL Concurrency

`/usr/local/bin/qmailmrtg7 t /var/log/smtps`

SMTP SSL Totals

`/usr/local/bin/qmailmrtg7 a /var/log/smtps`

POP3 SSL Concurrency

`/usr/local/bin/qmailmrtg7 t /var/log/pop3s`

POP3 SSL Totals

`/usr/local/bin/qmailmrtg7 a /var/log/pop3s`

Other mail stuff

Clamd virus-scanner

`/usr/local/bin/qmailmrtg7 C /var/log/clamd`

Spammassassin

`/usr/local/bin/qmailmrtg7 S /var/spamd.log`

CPU, Mem & Disks

CPU0 Usage

`/usr/bin/awk '/cpu0 /{print $2+$3; print $2+$3+$4; print "quite some time"; print "home"}'</proc/stat`

memory used/free

`free | /usr/bin/awk '/Mem: /{print $3*1000; print $4*1000; print ""; print ""}'`

memory swap

`free | /usr/bin/awk '/Swap: /{print $3; print $3; print ""; print ""}'`

system load

`uptime | sed 's/,//g' | awk '{print $10*100; print $11*100 ; print ""}'`
#!/bin/sh
# Thierry Nkaoua tnkaoua@yahoo.fr
USED=`free -b|grep cache:|cut -d ":" -f2|cut -c1-11`
FREE=`free -b|grep cache:|cut -d ":" -f2|cut -c12-22`
echo $FREE
echo $USED

Checkdisk

#!/bin/sh
df="/bin/df"
cut="/usr/bin/cut"
grep="/bin/grep"
part=$1
line=`$df -m -x nfs| grep "$part"`
libre=`echo $line|$cut -d" " -f 4`
utilise=`echo $line|$cut -d" " -f 3`
echo $libre
echo $utilise

NIC

eth0 bytes

`grep eth0 /proc/net/dev | sed 's/eth0://' | awk '{print $1; print $9; print ""; print ""}'`

eth0 packets

`grep eth0 /proc/net/dev | sed 's/eth0://' | awk '{print $2; print $10; print ""; print ""}'`

Ping

#!/bin/sh
 
# Thierry Nkaoua tnka@linux-sottises.net
 
P=`ping -w6 -c3 -q 62.4.16.248|grep rtt|cut -d" " -f4`
MIN=`echo $P|cut -d"/" -f1`
MAX=`echo $P|cut -d"/" -f2`
echo $MAX
echo $MIN

Tcp Open

$l = `netstat -tn | grep ESTABLISHED | wc -l`;
$l =~ /(\d+)/;
$data = $1;

Tcp Count

#!/bin/bash
#
# Script MRTG - David Du SERRE-TELMON (daviddst@netcourrier.com)
# Indique le nombre de connexions TCP actives avec Netfilter
#
# Syntaxe : 
#
# ./tcpcount
#   => Nombre de connexions tcp totales traversant la passerelle
# ./tcpcount 21
#   => Nombre de connexions FTP
# ./tcpcount 80 dst www.linux-sottises.net
#    => Nombre de connexion web vers le serveur web www.linux-sottises.net
# ./tcpcount 1214 src 192.168.0.2
#   => Nombre de connexions Kazaa pour l'utilisateur 192.168.0.2
 
netstat="/bin/netstat"
grep="/bin/grep"
sed="/bin/sed"
wc="/usr/bin/wc"
cat="/bin/cat"
printf="/usr/bin/printf"
host="/usr/bin/host"
 
port=$1
filter="$2"
ip="$3"
 
ip_conntrack=`$cat /proc/net/ip_conntrack | $grep ESTABLISHED`
 
if [ -n "$port" ]
then
  if [ "$filter" = src ] || [ "$filter" = dst ]
  then
    ip=`$host "$3" | grep "has address" | cut -d" " -f4`
    res=`$printf "$ip_conntrack" | $grep "dport=$port " | $grep "$filter=$ip" | $wc -l | $sed s/" "//g`
  else
    res=`$printf "$ip_conntrack" | grep "dport=$port " | $wc -l | $sed s/" "//g`
  fi
else
  res=`$printf "$ip_conntrack" | $wc -l | $sed s/" "//g`
fi
printf "$res\n$res\n"

Netstat

#!/bin/sh
# Usage :
#  netstat lan eth0
#  netstat adsl ppp0
grep="/bin/grep"
cut="/usr/bin/cut"
uptime="/usr/bin/uptime"
devsta="/proc/net/dev"
# netstat name interface
name=$1
interface=$2
line=`/bin/cat $devsta | $grep "$interface"`
line=`echo $line | $cut -d":" -f 2`
ibytes=`echo $line | $cut -d" " -f 1`
obytes=`echo $line | $cut -d" " -f 9`
uptim=`$uptime | $cut -d"," -f1`
uptim=`echo $uptim | $cut -d" " -f3,4`
echo $ibytes
echo $obytes
echo $uptim
echo $name

Volume échangé

#! /bin/sh
in=`ifconfig $1|grep bytes|cut -d"(" -f2|grep Mb|cut -d"." -f1`
out=`ifconfig $1|grep bytes|cut -d"(" -f3|grep Mb|cut -d"." -f1`
if ! [ "$in" ]; then
in=0
fi
if ! [ "$out" ]; then
out=0
fi
echo $in
echo $out

Mysql

Mysql stats
Takes one argument (Variable name) and returns it's value.
http://www.cacti.net/downloads/scripts/sql_stat.php.txt

  #!/usr/local/bin/php -q
  <?php
  $var = $argv[1];
  mysql_connect("HOST", "USER", "PASS") or die ("0");
  $res = mysql_query("SHOW STATUS") or die("0");
  while ($a = mysql_fetch_row($res)) {
      $stat[$a[0]] = $a[1];
  }
  printf("%s", $stat[$var]);
  mysql_close();
  ?>

Mysql rows count
Counts rows in a MySQL table.
http://www.cacti.net/downloads/scripts/sql_cnt.php.txt

  #!/usr/local/bin/php -q
  <?php
  $db = $argv[1];
  $table = $argv[2];
  mysql_connect("HOST", "USER", "PASS") or die ("0");
  mysql_select_db("$db") or die("0"); 
  $res = mysql_query("SELECT HIGH_PRIORITY count(*) as cnt from $table") or die("0");
  $a = mysql_fetch_array($res) or die("0");
  printf("%s", $a[cnt]);
  mysql_close();
  ?>

Apache

Apache requests per second

$output = `/bin/bash -c 'wget --quiet -O - \"http:\/\/localhost\/server-status"'`; 
$output =~ /(.*) requests\/sec/; 
print $1." "; 
$output =~ /(.*) requests currently being processed/; 
print $1;

Apache stats

#!/usr/bin/perl
 
# depends on availability of status and extended status info from your
# Apache webserver -- your httpd.conf needs to include something like the
# following: (uncommented)
#<Location /server-status>
#    SetHandler server-status
#    Order allow,deny
#    Allow from localhost
#</Location>
#ExtendedStatus On
 
# can return hits or bytes (counters)
 
@res = `lynx -dump http://localhost:80/server-status`;
 
foreach $res (@res) {
    if ($res =~ /Server uptime: (.*)$/) { $up = $1; last } else { next }
    if ($res =~ /Server at/) { $server = $res; last } else { next }
}
 
@res = `lynx -dump http://localhost:80/server-status?auto`;
 
foreach $res (@res) {
    if ($res =~ /Total Accesses: (\d+)/) { $d1 = $1; next }
    if ($res =~ /Total kBytes: (\d+)/) { $d2 = $1 * 1024; next }
}
 
$d1 = int($d1);
$d2 = int($d2);
 
if ($ARGV[0] eq "hits") {
    print "$d1\n";
    print "$d1\n";
} elsif ($ARGV[0] eq "bytes") {
    print "$d2\n";
    print "$d2\n";
}
 
print "$up\n";
print "$server";

Divers

ftpd concurrency

`/usr/local/bin/qmailmrtg7 t /var/log/ftpd`

ftpd allow/deny

`/usr/local/bin/qmailmrtg7 a /var/log/ftpd`

Tinydns Queries

`/usr/local/bin/qmailmrtg7 l /var/log/tinydns`

Dnscache Queries

`/usr/local/bin/qmailmrtg7 Q /var/log/dnscache`
informatique/mrtg.txt · Dernière modification: 19/05/2012 00:18 (modification externe)