사이트 내 전체검색
PHP
ipfm 우분투 IP Flow Meter (IPFM) 네트워크 bandwidth 툴 (콘솔에서 가능)
로빈아빠
https://cmd.kr/php/773 URL이 복사되었습니다.

본문

ipfm

IP Flow Meter (IPFM) is a bandwidth analysis tool, that measures how much bandwidth specified hosts use on their Internet link.

Current Stable Version :- 0.11.5

Install ipfm in Ubuntu

sudo apt-get install ipfm

This will complete the installation

Now if you want to configure this for your network you need to copy example configuration file from /usr/share/doc/ipfm/examples if you want to check this file click here

once you configure this file you need to start the service using the following command

sudo /etc/init.d/ipfm start

If you want more details and available options check man page

설치후에 /etc/ipfm.conf 를 수정해야한다.

설정후에 두번째줄에 Disable 를 #으로 막아주면 끝..

ipfm 서비스 재시작.

기록은 /var/log/ipfm 에 모인다


It is great to use IP Flow Meter to create logs for every host in your network, but is greater to create a graph for all of them not only for box interfaces. 
I try to find this template but no luck, so I decided to create it myself... 
It is very useful for network administrators, sometimes clients require a chart with their bandwidth use, my boss also :D 

Image 

Tools I use: 
1) IPFM - v0.11.4 
2) Cacti - v0.8.7e 

IPFM Configuration 
Dumping statistics every 5 minutes. 
You can use also APPEND instead of REPLACE (Script is optimizad for that to but will slow down after few weeks of logging) 
Code:
cat /etc/ipfm/ipfm.conf | grep -vE "^#|^$"
DEVICE eth0
NOPROMISC
LOG 192.168.0.0/255.255.255.0 NOT WITH 192.168.0.0/255.255.255.0
FILENAME "/var/log/ipfm/ipfm-global.log"
DUMP EVERY 5 minutes
CLEAR ALWAYS
NORESOLVE
REPLACE


CACTI Cron Job
For this to work we must synchronize IPFM dump with cacti Cron job
Polling every 5 minutes with debug
Code:
crontab -e -u cacti
*/5 * * * * php /var/www/html/cacti/poller.php >> /var/log/cacti_pool.log 2>&1


Patch cacti php code
Because IPFM calculates bandwidth every 5 minutes and cacti believes that is per second, then we should divide it by 300.

1) File /var/www/cacti/lib/rrd.php
IPFM patch, modify the code at line 991, in the regex (bandwith summation) and add a new option ":ipfm".

Code:
if (preg_match_all("/\|sum:(\d|auto):(current|total|atomic):(\d):(\d+|auto)(:ipfm)?\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {


2) File /var/www/cacti/lib/graph_variables.php
IPFM patch, add this code (3 lines) after line 475, before transformation in (bytes,KB,MB,GB,TB)

Code:
if($regexp_match_array[5] == ":ipfm")
   {
    $summation /= 300;
   }


3) Usage of patch
Console -> Graph Templates -> "Graph Name" -> Graph Template Items -> Text Format
This is useful for [Graph Item Type] = "COMMENT"
Ex: "Total In: |sum:auto:current:2:auto:ipfm|<HR>"

Image

Script Code
It must be placed in "/var/www/cacti/scripts/ipfm_host" or in your cacti install path.
This script is use in Data Input Methods "sh <path_cacti>/scripts/ipfm_host <ip>"
Code:
cat ipfm_host
#!/bin/sh

#IPFM Log
FILE="/var/log/ipfm/ipfm-global.log"

#Debug
#echo `date` :: `pwd` :: $0 :: `whoami` :: $1 >> /server/ipfm/debug.log

awk -v host=$1 '
BEGIN{
DATA=0;
}
{
if($1==host)
    {
     DATA = "IPFM_Input:" $2 " IPFM_Output:" $3 " IPFM_Total:" $4;
    }
}
END{
if(!DATA)
    {
     print "IPFM_Input:0 IPFM_Output:0 IPFM_Total:0";
    }
else
    {
     print DATA;
    }
}
' $FILE


댓글목록

등록된 댓글이 없습니다.

PHP
871 (4/18P)

Search

Copyright © Cmd 명령어 3.133.135.8