Если периодически нужно замерять канал, можно это делать, загружая определённые файлы со стороннего сервера с хорошим каналом. Например, есть файл на 1МБ по ссылке http://wikiadmin.net/file
Мониторим количество соединений на отдельных портах
Можно мониторить любые порты. например 25,110 или 143 для тех же почтовиков. У меня была задача получать кол-во соединений на 80 порту (Nginx) и на 8080 (Apache). Это несложно. Добавляем в конфиг следующее:
123456789101112
Target[connect]: `/etc/mrtg/mrtg.connect`
Title[connect]: connect to our web in sec
MaxBytes[connect]: 100000
PageTop[connect]: <H1> connect to our web </H1>
Suppress[connect]: y
LegendI[connect]: 80 port
LegendO[connect]: 8080 port
Legend1[connect]: connect in sec
Legend2[connect]: connect in sec
YLegend[connect]: connects
ShortLegend[connect]:connects
Options[connect]: growright, nopercent, gauge
где указаны нужные нам порты. Делаем скрипт исполняемым
1
chmod +x /etc/mrtg/mrtg.connect
Мониторим нагрузку процессора
Добавим в конфиг mrtg.cfg следующее
12345678910
Target[cpu]: `/etc/mrtg/cpuinfo.pl localhost linux`
MaxBytes[cpu]: 100
Options[cpu]: gauge, nopercent, growright
Unscaled[cpu]: dwym
YLegend[cpu]: % of CPU used
ShortLegend[cpu]: %
LegendO[cpu]: CPU System:
LegendI[cpu]: CPU User:
Title[cpu]: cpu name
PageTop[cpu]: <H1>CPU usage for cpu name</H1>
#!/usr/bin/perl
# ============================================================================
# CPU Usage script for mrtg
#
# ============================================================================
# setup local vars
my($machine, $os);
# ============================================================================
# == Enter your rsh program here here ==
$rsh = "/usr/local/bin/ssh -x"; # Enter your rsh command here
# == You shouldn't need to edit anything below this line ==
#========================================================
# This checks for options passed cpuinfo.pl from the cmd line
if (scalar(@ARGV) < 2)
{
print("USAGE: cpuinfo.pl {machine} {os}\n");
exit(-1);
}
if ($ARGV[0] ne '' && $ARGV[0] ne '#')
{
$machine = $ARGV[0];
}
if ($ARGV[1] ne '' && $ARGV[1] ne '#')
{
$os = $ARGV[1];
}
# Validate the os
SWITCH:
{
if ($os =~ /^sun$/){last SWITCH;}
if ($os =~ /^linux$/){last SWITCH;}
# DEFAULT: Die if we can't figure out what the os is
die "Can't figure out which OS the machine is.\n";
}
# Execute the appropriate subroutine based on the os
&$os;
exit(0);
#=======================================================
# Subroutines: names of subroutines are supported OSs.
#========================================================
sub sun
{
# Run commands
if ($machine =~ 'localhost')
{
$getcpu = `sar -u 1 10 | grep Average`;
$getuptime = `uptime`;
}
else
{
$getcpu = `$rsh $machine "sar -u 1 10" | grep Average`;
$getuptime = `$rsh $machine "uptime"`;
}
# Parse though getcpu and get data
$getcpu =~ /^Average\s+(\d+)\s+(\d+)\s+/;
$outputusr = $1;
$outputsys = $2;
# Print getcpu data for mrtg
print $outputusr."\n";
print $outputsys."\n";
# Parse though getuptime and get data
$getuptime =~ /^\s+\d{1,2}:\d{2}..\s+up\s+(\d+)\s+(......),/;
# Print getuptime data for mrtg
print $1." ".$2."\n";
# Print machine name for mrtg
print $machine."\n";
}
sub linux
{
# Run commands
if ($machine =~ 'localhost')
{
$getcpu = `/usr/bin/sar -u 1 10 | grep Average`;
$getuptime = `/usr/bin/uptime`;
}
else
{
$getcpu = `$rsh $machine "/usr/local/bin/sar -u 1 10 | grep Average"`;
$getuptime = `$rsh $machine "/usr/bin/uptime"`;
}
# Parse though getcpu and get data
$getcpu =~ /^Average:\s+all\s+(\d+)\.\d+\s+\d+\.\d+\s+(\d+)\.\d+\s+\d+\.\d+/;
$getcpuusr = $1;
$getcpusys = $2;
# Print getcpu data for mrtg
print $getcpuusr."\n";
print $getcpusys."\n";
# Parse though getuptime and get data
$getuptime =~ /^\s+\d{1,2}:\d{2}..\s+up\s+(\d+)\s+(\w+),/;
# Print getuptime data for mrtg
print $1." ".$2."\n";
# Print machine name for mrtg
print $machine."\n";
}
exit(0);
Делаем его исполняемым
1
chmod +x /etc/mrtg/cpuinfo.pl
Мониторим NGINX
Задача: видеть кол-во активных соединений и ожидающих. В конфиг любого виртуального хоста добавляем это: