Ubuntu network monitoring tool usage

Source: Internet
Author: User
Tags config mkdir rrdtool snmp cpu usage perl script

Network Monitoring commands I found during learning

Netstat-an view the current network status

Sudo netstat-anp

Traceroute

Ubuntu network monitoring tool

Nethogs is a network traffic monitoring tool on a terminal. It displays the bandwidth usage of each process, so that the network usage can be obtained more intuitively. It supports IPv4 and IPv6 protocols, local NICs, and PPP connections.

The code is as follows: Copy code

Sudo apt-get install nethogs


Usage:

Sudo nethogs Nic

This program requires the root permission. By default, the eth0 Nic is monitored. Therefore, you can directly enter sudo nethogs. If there are multiple NICs, you must specify them. If you do not know the name of your Nic, run the ifconfig command.

Next, I will organize a network monitoring system that integrates Cacti and Nagios.

The installation process is divided into six parts.

1. Install necessary software
2. Install Cacti
3. Install Cacti Plugins Arch
4. Install NPC, Settings, and Thold
5. Install Nagios
6. Install NDoutils


1. Install necessary software

Let's talk about my installation environment first.
The Dell PowerEdge 1750 Server that I use is an empty company. The Ubuntu version is Ubuntu Server 8.0.4.

After logging on with root
Apt-get update
Apt-get install apache2 mysql-server php5 php5-cli php5-mysql php5-snmp libapache2-mod-php5 snmp rrdtool
Specifically, apache, mysql, php5, snmp, rrdtool, and some required mod or extension are installed.
After the installation is complete, install Cacti.


2. Install Cacti

Mkdir ~ /Cacti I used to put all downloaded items under home
Cd ~ /Cacti
The wget http://www.cacti.net/downloads/cacti-0.8.7b.tar.gz downloads the latest version of Cacti, which is 0.8.7b now
Tar xzf cacti-0.8.7b.tar.gz decompression
Mv ~ /Cacti/cacti-0.8.7b/usr/share/cacti move cacti under/usr/share

Cd/usr/share/cacti
Chown-R root: wwwdata rra/log/The official writing method is wwwdata: wwwdata. Here I changed it to root: wwwdata for a while.

Edit/etc/crontab and add the following line // 111cn. Net
*/5 * root php/usr/share/cacti/poller. php>/dev/null 2> & 1
It is not officially run as a root user, but when I try to use other users several times to perform the downed device detection on the host using ICMP Ping, the following error occurs:
Warning: socket_create () [function. socket-create]: Unable to create socket [1]: Operation not permitted in/usr/share/cacti/lib/ping. php on line 158
Warning: socket_set_block () expects parameter 1 to be resource, boolean given in/usr/share/cacti/lib/ping. php on line 160
After the query, it is found that php can run only with the root permission, and php is not familiar with it, so I simply run the entire poller with the root, which is why chown was changed to root: wwwdata above.

Edit/etc/apache2/sites-avaliable/default and add the content.
Alias/cacti/"/usr/share/cacti /"
<Directory "/usr/share/cacti/">
AllowOverride None
Order Allow, Deny
Allow from all
</Directory>
Restart apache
/Etc/init. d/apache2 restart

Next is the mysql configuration.
Create a user cacti
Mysqladmin-u root-p create cacti
Import SQL files
Mysql-u root-p cacti <cacti. SQL
Go to mysql to set permissions
Mysql-u root-p
Mysql> grant all on cacti. * To cacti @ localhost identified by 'cacti ';
Mysql> flush privileges;
Mysql> exit;

Finally, modify the cacti config file.
Vi/usr/share/cacti/include/config. php
Change the following content // www.111cn.net
$ Database_username = "cacti ";
$ Database_password = "cacti ";

Here, cacti is installed on the server
Enter
Http: // yourserver/cacti/
We will see the cacti installation interface and perform new install. There is basically nothing to modify. Just take a look at it and click next.
When you log on for the first time, the user name and password are both admin, and you will be prompted to change the password.

4. Install NPC, Settings, and Thold

This part is relatively simple.
First, download these plug-ins.
Cd/usr/share/cacti/plugins
Wget http://cactiusers.org/downloads/settings.tar.gz
Wget http://cactiusers.org/downloads/thold.tar.gz
Wget http://www.assembla.com/spaces/n... c-2.0.0b.166.tar.gz
Decompress the package separately.
Tar xzf settings.tar.gz
Tar xzf thold.tar.gz
Tar. xzf npc-2.0.0b.166.tar.gz

Next, load settings and thold in global. php.
Vi/usr/share/cacti/include/global. php
Add the following content
$ Plugins [] = 'Settings ';
$ Plugins [] = 'thold ';
Go back to the webpage and remember to go to user managerment and give the permissions to the corresponding User. The specific method is to click user Managerment in the menu on the left of the page, and then click a User (such as admin) on the right ), then select the corresponding options in Realm Permissions.

The NPC directly enters the webpage, click Plugin Management on the left, and then install the NPC in Uninstalled on the right. enable NPC in Installed.
This may be a bit abstract. I will take the time to cut down the graph and upload it.

Let's talk about the plug-in of Thold. The function of this plug-in is to set a range for a data item. If the range is exceeded, the plug-in will be removed from alarm. For example, I am monitoring the cpu, if the cpu usage is greater than 90% or less than 10%, mail it to me. This is very useful for traffic monitoring. It is mainly used to monitor the company's network traffic and the hard disk space of file server.


5. Install Nagios

This part is relatively more complicated, because it is very easy to compile the program by yourself.
First, install the two packages required by Nagios.
Apt-get install build-essential libgd2-xpm-dev

Add and edit users and groups
Useradd nagios
Groupadd nagios
Groupadd nagcmd
Usermod-G nagcmd nagios
Usermod-G nagcmd www-data

Download and compile and install Nagios
Mkdir ~ /Nagios
Cd ~ /Nagios
Wget http://osdn.dl.sourceforge.net/s... nagios-3.0.2.tar.gz
I used 3.0.2 and now there is 3.0.3.
Tar nagios-3.0.2.tar.gz
Cd ~ // Nagios/nagios-3.0.2
./Configure -- with-command-group = nagcmd
Make all
Make install
Make install-init
Make install-config
Make install-commandmode
Make install-webconf

Then give nagios a web password.
Htpasswd-c/usr/local/nagios/etc/htpasswd. users nagiosadmin

Restart apache
/Etc/init. d/apache2 restart

The following is a link. I don't know what I use, but I don't have to. Please let me know.
Ln-s/etc/init. d/nagios/etc/rcS. d/S99nagios

Then install nagios plugins, which contains many files used to check the host and service.
Cd ~ /Nagios
Wget http://osdn.dl.sourceforge.net/s... ugins-1.4.11.tar.gz
Tar xzf nagios-plugins-1.4.11.tar.gz
./Configure -- with-nagios-user = nagios -- with-nagios-gourp = nagios
Make
Make install

Finally, I tried the mail alarm of nagios, but it never succeeded in sending it on the local machine. So I went to our smtp server and used a perl script to send it:

#! /Usr/bin/perl

Use Getopt: Std;
Use Net: SMTP;

# F: mail from s: subject t: rcpt
Getopt: Std: getopts ('F: s: t: ', % options );

My $ from = $ options {f };
My $ subject = $ options {s };
My $ to = $ options {t };

While (defined ($ line = <STDIN> ;)){
$ Content. = $ line;
}

Open (LOG, ">/var/log/logs Y. log ");

$ Smtp = Net: SMTP-> new ('yoursmtpserveraddress ');

$ Smtp-> mail ($ from );
$ Smtp-> to ($ );

$ Smtp-> data ();
$ Smtp-> datasend ("To: $ ton ");
$ Smtp-> datasend ("Subject: $ subjectn ");
$ Smtp-> datasend ("Content-Type: text/plain; charset = utf-8n ");
$ Smtp-> datasend ("n ");
$ Smtp-> datasend ("$ contentn ");
$ Smtp-> dataend ();
$ Smtp-> quit;

My $ date_command = "/bin/date ";
My $ date = '$ date_command'; chop ($ date );
Print LOG "$ date: Sent Msg $ content to $ ton ";
Close (LOG );
Exit (0 );

The following is the command of policy-host-by-email used in Nagios:

/Usr/bin/printf "% B" "****** Nagios ***** nnNotification Type: $ icationicationtype $ nHost: $ HOSTNAME $ nState: $ HOSTSTATE $ nAddress: $ HOSTADDRESS $ nInfo: $ HOSTOUTPUT $ nnDate/Time: $ LONGDATETIME $ n "| perl/usr/local/nagios/etc/mail1.pl-f nagios@infor.com-s" ** $ icationicationtype $ Host Alert: $ HOSTNAME $ is $ HOSTSTATE $ ** "-t $ CONTACTEMAIL $

About alarm of Naigos, I have studied whether short messages can be used, but only for mobile users. I can also use the Fetion software in linux. I will post it later.


6. Install NDoutils

NDoutils is the mysql mod of Nagios. You can synchronize the Nagios situation to mysql, which is also the most important part of the installation process. This is because NPCs can obtain relevant information only when synchronized to mysql.

Install a package first, because NDoutils needs some mysql source files.
Apt-get install libmysql ++-dev

Download NDoutils and compile
Mkdir ~ /Ndoutils
Cd ~ /Ndoutils
Wget http: // ****/ndoutils-1.4b7.tar.gz today I can not connect to sourceforge, can not give the specific address, you can go here to find, pay attention to be 1.4b7.
Tar xzf ndoutils-1.4b7.tar.gz
Cd ~ /Ndoutils/ndoutils-1.4b7
./Configure
Make

Next install, instead of using make install
Cd ~ /Ndoutils/ndoutils-1.4b7/src
Cp ndomod-3x.o ndo2db-3x log2ndo file2sock/usr/local/nagios/bin
Cd ~ /Ndoutils/ndoutils-1.4b7/config
Cp ndomod. cfg ndo2db. cfg/usr/local/nagios/etc/

Modify related configurations
Vi/usr/local/nagios/etc/ndo2db. cfg
Change the following content
Db_name = cacti
Db_prefix = npc _
Db_user = cacti
Db_pass = cacti
Debug_level = 1
Here is the user and password used by Cacti in mysql and the database, because we use this npc plug-in cacti.

Modify the config file of Nagios so that NDoutils can load data in Nagios.
Vi/usr/local/nagios/etc/nagios. cfg
Change
Check_external_commands = 1
Command_check_interval =-1
Event_broker_options =-1
Add
Broker_module =/usr/local/nagios/bin/ndomod-3x.o config_file =/usr/local/nagios/etc/ndomod. cfg

Then enable NDoutils and Nagios respectively.
/Usr/local/nagios/bin/ndo2db-3x-C/usr/local/nagios/etc/ndo2db. cfg
/Etc/init. d/nagios start

The final task is to configure the NPC in the Web
In Cacti, click Settings on the left and click the NPC tab to check Remote Commands. In Nagios Command File Path, enter/usr/local/nagios/var/rw/nagios. run cmd and enter http: // yourserver/Nagios/in the nagios URL, and Save it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.