Showing posts with label Server Monitoring. Show all posts
Showing posts with label Server Monitoring. Show all posts

Sunday, 23 December 2012

How to install Cacti (Network graphing tool)


 Cacti is a network graphing tool. Cacti is a complete frontend to RRDTool, it stores all of the necessary information to create graphs and populate them with data in a MySQL database. The frontend is completely PHP driven. Along with being able to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering. There is also SNMP support for those used to creating traffic graphs with MRTG.

 Requirements
*****************
You need to install the following software on RHEL / Fedora / CentOS Linux:

    MySQL Server : Store cacti data.
    NET-SNMP server - SNMP (Simple Network Management Protocol) is a protocol used for network management.
    PHP with net-snmp module - Access SNMP data using PHP.
    Apache / lighttpd / ngnix webserver : Web server to display graphs created with PHP and RRDTOOL(acronym for round-robin database tool).

RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. RRDtool can be easily integrated in shell scripts, perl, python, ruby, lua or tcl applications.


Install the Following software
**************************
# yum install mysql-server mysql php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-snmp php-pear-Net-SMTP php-mysql httpd

Configure MySQL server
*********************
# mysqladmin -u root password NEWPASSWORD

Create cacti MySQL database
*************************
Create a database called cacti, enter:

# mysql -uroot -pmysql

mysql> create database cacti;

Create a user called "cacti" with a password called "redhat"

mysql> grant all on cacti.* to cacti@localhost identified by 'redhat';
mysql> flush privileges;
mysql> quit


Install snmpd
*************
# yum install net-snmp-utils php-snmp net-snmp-libs

Configure snmpd, open /etc/snmp/snmpd.conf

# vim /etc/snmp/snmpd.conf

com2sec local     localhost           public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
view all    included  .1                               80
access MyRWGroup ""      any       noauth    exact  all    all    none
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat


Save and close the file. Turn on snmpd service:

# /etc/init.d/snmpd start
# chkconfig snmpd on

Make sure you are getting information from snmpd:

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Sample ouptut:
IP-MIB::ipAdEntIfIndex.10.10.29.68 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.67.yy.zz.eee = INTEGER: 3
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1


Install cacti
***********
First, make sure EPEL repo is enabled. Type the following command to install cacti:

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

# yum install cacti


Install cacti tables
*****************
Type the following command to find out cacti.sql path:

# rpm -ql cacti | grep cacti.sql

/var/www/cacti/cacti.sql

Type the following command to install cacti tables

# mysql -uroot -pmysql cacti < /var/www/cacti/cacti.sql


Configure cacti
*************
Open /var/www/cacti/include/config.php file, enter:

# cd /var/www/cacti/include/
# vim config.php  -------> in some versions it is db.php

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "redhat";
$database_port = "3306";
$database_ssl = false;

Save and close the file.


Configure httpd
**************
Open /etc/httpd/conf.d/cacti.conf file, enter:

# vim /etc/httpd/conf.d/cacti.conf

You need to update allow from line. Either set to ALL or your LAN subnet to allow access to cacti:

Alias /cacti/ /var/www/cacti/
<Directory /var/www/cacti/>
    DirectoryIndex index.php
    Options -Indexes
    AllowOverride all
    order deny,allow
    deny from all
    allow from 192.168.1.0/24
    AddType application/x-httpd-php .php
    php_flag magic_quotes_gpc on
    php_flag track_vars on
</Directory>

Edit and Save the file.

Another option is create /usr/share/cacti/.htaccess file and password protect the directory. Finally, restart httpd:

# service httpd restart


Setup cacti cronjob for poller for data collection
*****************************************
Open /etc/cron.d/cacti file, enter:
# vim /etc/cron.d/cacti

*/5 * * * *     cacti   /usr/bin/php /var/www/cacti/poller.php &>/dev/null

Save and close the file. and start crond

# service crond restart

In Browser:- http://192.168.1.67/cacti/

Just follow on screen instructions. The default username and password for cacti is admin / admin. Upon first login, you will be force to change the default password.

Default Username & Passwd: admin/admin
Changed Username & Passwd: admin/cacati


How do I configure SNMP data collection
**********************************
SNMP can be used to monitor server traffic. Once installed login to cacti.

===> Click on Devices ==== Localhost

=> Make sure SNMP options are selected as follows:

 Version2---public---161---500---10

And Save it.


How do I create SNMP graphs
**************************
Click on "Create Graphs for this Host" link on top right side.

Select SNMP - Interface Statistics

Select a graph type (such as In/Out bytes with total bandwidth)


Create A Device In Chart
**********************
Either Click "Console" tab then you can see the below items on the screen

   * "Create devices" for network
   * "Create graphs" for your new devices
   * View your new graphs

Or Click on the "Devices" tab and do the below things, its same for both way.


-----> Click "Create devices" tab. Next Page will appear, on its right hand side click "Add" tab. After getting a new page fill the page with all the host details and click "create" at the bottom. It will add the host to cacati. And then Add "Associated Graph Templates" from the bottom of the page. select appropriate template and click add.

-----> And then add "Associated Data Queries"  and "Save". After saving create the graph for the Host. You can create the graph from the top of the current window OR click "Devices" there you can see the newly added host. click on it, At right side you can see "Create Graphs for this Host" link click on it. There you can select each 'Graph Templates' and select "create" to setup graph for each.
 

After that add chart for "Data Query" ( Interface Statistics ) and also for (Mounted Partitions ) this is up to each one, what they create.

-----> To Add the newly added host under the graph tree menu we already created(Pfx25) go to "Graph Trees" menu. There we can see the main tree Pfx25, click "Add"
        Parent Item              : root
        Tree Item Type         : Host
        Host                        : select the host we want
        Graph Grouping Style :
        Round Robin Archive  :


   After filling this give 'create' and then 'save'.

 Then to view the graph go to "graph" menu on top. there we can see the newly added host as well winder the main menu Pfx25.


To create A new User
*******************
Go to "User Management"

Create Graphs 

*************
Still in the device screen from above, click at the top right Create Graphs for this Host 

In this screen, you can select as many of the potential graphs as desired.

For the Virtual Server, you will need to create the Connection Rate, Connections/s, & the Traffic graphs in separate steps via the select box at the bottom
 

Click Create
 

Accept the Defaults, Click Create again

Note: Created graphs will be listed at the top of the screen


How do I view graphs
*******************
To view graphs click on Graphs tab.

Manage Graphs

  1.  In the GUI menu on the left under Management, click Graph Trees
  2.  Click Add
  3.  Under Name, I define the F5 device hostname, but it can be anything
  4.  Under Sorting Type, select your preference
  5.  Click Create
  6.  In the GUI menu on the left under Management, click Graph Management
  7.  Select the Host you created
  8.  Select the Graphs you created
  9.  In the Choose an Action select box, select Place a tree (your new tree)
  10. Click Go
  11. Click Yes
  12. Click the Graphs Tab at the top of the screen
  13. Select the Tree you created
  14. View your graphs!


snmp commands
***************
snmpwalk -Os -c mycommunity -v 1 localhost system
snmpwalk -Os -c public -v 1 localhost system


Configuring Client Machines
************************
 just install snmp on each client machines. Then configure the host in cacati.

This section is optional and for those looking to use Cacti to monitor additional devices. These steps are written for other CentOS-based distributions, but with modification, will work on any flavor of Linux. You will need to follow these instructions for each client machine you'd like to monitor with Cacti. Client machines need an SNMP daemon in order to serve Cacti information.

First, install snmp and snmpd on the client:

# yum install net-snmp-utils php-snmp net-snmp-libs

Configure snmpd, open /etc/snmp/snmpd.conf
# vi /etc/snmp/snmpd.conf

Append / modify it as follows (see snmpd.conf man page for details):

com2sec local     localhost           public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
view all    included  .1                               80
access MyRWGroup ""      any       noauth    exact  all    all    none
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root  (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

Save and close the file. Turn on snmpd service:

# /etc/init.d/snmpd start
# chkconfig snmpd on

Make sure you are getting information from snmpd:

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex





Monday, 11 June 2012

How to monitor active MySQL connections(ajaxmytop)

AjaxMyTop shows active MySQL connections. You get a data grid showing connections, each showing ID, user, duration, and so on. 

 AjaxMyTop currently requires PHP5 and it may not work properly with php 4.x versions. Get it to the exact web root directory which you want to run ajaxMyTop. In my case it is /var/www/html/

# cd /var/www/html

# wget http://downloads.sourceforge.net/project/ajaxmytop/ajaxmytop/ajaxMyTop-0.7.2/ajaxMyTop-0.7.2.tar.gz

 # tar zxvf ajaxMyTop-0.7.2.tar.gz

 # mv ajaxMyTop mytop# cd mytop

Configuring AjaxMyTop

You can configure ajaxMyTop by editing the config.php file. MySQL: It is highly recommended that you create a new user for ajaxMyTop with the SUPER and PROCESS privileges rather than configure ajaxMyTop with an admin user, or continue with the default details.

mysql> GRANT SUPER, PROCESS ON *.* to ‘ajaxmytop’@'localhost’ identified by ‘ajaxmytop’;

 mysql> GRANT SUPER, PROCESS ON *.* to ‘ajaxmytop’@'%’ identified by ‘ajaxmytop’;

Apparently you must also grant the SELECT privilege to the ajaxmytop user for all databases in which you may want to explain threads.

mysql> GRANT USAGE, SELECT ON test.* to ‘ajaxmytop’@'localhost’ identified by ‘ajaxmytop’;

mysql> GRANT USAGE, SELECT ON test.* to ‘ajaxmytop’@'%’ identified by ‘ajaxmytop’;

Edit the config.php and enter the user-name and password setting which you have setup. Access it via your server ip or domain based on your installation location.

http://192.168.1.67/mytop/
 
Make sure you have .htaccess folder permission enabled on the mytop folder or else everyone can access and view your mysql query usages etc.

Monitoring tcp connections using Tcptrack

Install Tcptrack to monitor TCP connections. Tcptrack is an excellent tool to monitor your server network connections and bandwidth quickly, installation is pretty easy and can be done either via rpm or source.

# cd /usr/src/

# wget http://packages.sw.be/tcptrack/tcptrack-1.1.5-1.2.el5.rf.i386.rpm

# rpm -ivh tcptrack-1.1.5-1.2.el5.rf.i386.rpm

 OR

 # tar zxvf tcptrack-1.3.0.tar.gz

 # cd tcptrack-1.3.0

 # ./configure ; make & make install

 tcptrack -h
 
 TCPtrack can monitor only one nic at once with only one parameter to run (if you have two nic ie.. eth0 & eth1 )

    # tcptrack -i eth0
   # tcptrack -i eth1

 
The following example will only show connections from host 68.36.45.78:

    # tcptrack -i eth0 src or dst 68.36.45.78

To monitor the specific ports (ie..port 80 and 22):

    # tcptrack -i eth0 port 80
   # tcptrack -i eth0 port 22



Network bandwidth monitoring bmon

bmon is a portable bandwidth monitor and rate estimator running on various operating systems.

# sudo apt-get install bmon

# bmon


Bandwidth monitoring using bwm-ng

small and simple console-based bandwidth monitor.Bandwidth Monitor NG is a small and simple console-based live bandwidth monitor. 

# sudo apt-get install bwm-ng

# bwm-ng

OR

# cd /usr/src      

# wget http://www.gropp.org/bwm-ng/bwm-ng-0.6.tar.gz

# tar zxvf bwm-ng-0.6.tar.gz

# cd bwm-ng-0.6

# ./configure && make && make install

Type bwm-ng -h and make sure you are able to see the command help menu.
* Network Monitoring using bwm-ng....
  # bwm-ng -u bits -d
  # bwm-ng -u bytes -d 

Options to see all the NIC status in bits and bytes and -d is for dynamic output which displays in the KB/s and MB/s dynamically.
 
 * Disk I/O monitoring using bwn-ng
    Monitoring disk I/O is pretty simple with bwn-ng

  # bwm-ng -u bytes  -i disk

Monitoring bandwidth using iftop

iftop does for network usage what top does for CPU usage. It listens to network traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts.

# iftop

Bandwidth Monitoring using cbm

the Color Bandwidth Meter — displays the current traffic on all network devices.

# sudo apt-get install cbm

$ cbm

Network monitoring using tcptrack

tcptrack is a sniffer which displays information about TCP connections it sees on a network interface. It passively watches for connections on the network interface, keeps track of their state and displays a list of connections in a manner similar to the unix ‘top’ command. It displays source and destination addresses and ports, connection state, idle time, and bandwidth usage.

# sudo apt-get install tcptrack

# tcptrack -i eth0

# tcptrack -i eth0 port 80


Monday, 30 April 2012

Checking the amount of memory use using Pmap

The pmap command reports the amount of memory that one or more processes are using. You can use this tool to determine which processes on the server are being allocated memory and whether this amount of memory is a cause of memory bottlenecks and it is also very useful for the administrators to find which of the libary / file is eating more memory on that pid.

# pmap <pid>

 To show in device format.

# pmap -d <pid>

Checking apache log files using ApacheTop

 ApacheTop watches a log-file generated by Apache (in standard common or combined logformat, and generates human-parsable output in realtime like the output of top command from shell. Several other options are also available as a syntax to get furnished results (ie..like results based of hits, query-strings, segments and protocols etc)

 # cd /usr/src
 # wget http://www.webta.org/apachetop/apachetop-0.12.6.tar.gz
 # cd apachetop-0.12.6
 # ./configure
 # make && make install

# wget http://packages.sw.be/apachetop/<select the latest version and arch>
# rpm -ivh apachetop-0.12.6-2.el6.rf.x86_64.rpm

 Apachetop is very much useful to monitor the stats if you have a combined access logs (iee..a common access_log for all your virtualhost). If you have separate access logs configured for your vhosts then you need to use the -f option to view the stats, For example.

# apachetop -f /var/log/httpd/gnutoolbox_com.access.log

Visual Apache Log Analyzer using goaccess

GoAccess is a real-time Open Source Apache log analyzer and interactive viewer for the Apache Web server.

# gunzip goaccess-0.4.2.tar.gz

 # tar -xvf goaccess-0.4.2.tar

 # cd goaccess-0.4.2

 # ./configure

 # make

 # make install
 
 # goaccess -f /var/log/httpd/access_log  -a -s -b


Sunday, 29 April 2012

Checking server health using htop

Is a very interactive gui based tool written in C program. Htop provides a full list of processes running, instead of the top resource-consuming processes. Htop uses color and gives visual information about processor, swap and memory status.
 
# yum install htop

# htop

Checking system load-average using tload

Runs in a terminal and displays a text-only “graph” of current system load averages, garnered from /proc/loadavg. It is part of the base installation on most GNU/Linux systems (comes under procps package). Which is extremely useful for watching a system’s performance over SSH, often within a GNU Screen session.

# tload

Traffic and bandwidth monitoring using nLoad

A simple and a real time network traffic and bandwidth console based monitoring tools which helps the administrators to monitor their server network traffic using simple command syntax.

Once you have installed the nload either using source or rpm. You can use any of the following syntax to monitor your bandwidth, 

# nload eth1

To monitor your specific Ethernet interface with MByte/s instead of the default KByte/s

# nload -u M eth1

Execute the following command to monitor the multiple ethernet interfaces in the server.

# nload -m eth0 eth1 -u M

Monday, 23 April 2012

server monitoring using dstat

DSTAT an excellent tool which combines the overall stats of vmstat, iostat, netstat and ifstat. Dstat allows us to view all of the system resources in the real-time including the network bandwidth, network I/O , IRQ etc which helps the administrator to get an clear picture of what is going on in their server. It also reduces the headache of opening a separate shell/terminal to view the stats during bench tests.

# yum install dstat

# dstat

fping for network admins to monitor

 Network administrators may need a command or tool that will display all the live hosts in their network/subnet to keep track of all the activities and for that you can try using fping tool which works based on the ICMP echo request.

# yum insall fping

# fping -g 192.168.1.0/24 | grep “alive”


atop for server monitoring

The program atop is an interactive monitor to view the load on a Linux system.  It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network.

It also shows which processes are responsible for the indicated load with respect to cpu- and memory load on process level. Disk load is shown if per  process  “storage accounting” is active in the kernel or if the kernel patch âcntâ has been installed.

Network load is only shown per process if the kernel patch âcntâ has been installed. Every interval (default: 10 seconds) information is shown about the resource occupation on system level (cpu, memory, disks  and  network  lay-ers),  followed  by a list of processes which have been active during the last interval (note that all processes that were unchanged during the last interval are not shown, unless the key âaâ has been pressed).

If the list of active processes does not entirely fit on the  screen,  only the top of the list is shown (sorted in order of activity). The intervals are repeated till the number of samples (specified as command argument) is reached, or till the key âqâ is pressed in interactive mode.

# yum insall atop

# atop



phpMyTop for server monitoring

Download and untar the source file inside the web directory which you like to access (ie.. for example /var/www/html )

# wget http://www.gnutoolbox.com/download/linux/dbserver/mysql/phpMyTop_1.0.1.tgz

# tar zxvf phpMyTop_1.0.1.tgz

# cd phpMyTop/

# mysql [-uyouruser] [-pyourpass] < install.sql
(you need to create a username and password on the mysql to dump the database)

Edit the config.php and modify the following lines with your username and password.

    $GLOBALS['mytop_dbuser'] = ‘root’;
    $GLOBALS['mytop_dbpass'] = ”;
    $GLOBALS['mytop_dbhost'] = ‘localhost’;
    $GLOBALS['mytop_db'] = ‘phpmytop’;

Saturday, 31 March 2012

Monitorix - A server monitoring tool

Monitorix is a free, open source, lightweight system monitoring tool designed to monitorize as many services as possible. It can be accessed via a web browser.

Monitorix has been designed to be used under production UNIX/Linux servers, but due its simplicity and small size you may also use it to monitor embedded devices.

You can install the package either via rpm or via yum

 # yum install monitorix

 # vim /etc/monitorix.conf

 # /etc/init.d/httpd reload

cd /etc/httpd/conf.d/

vim monitorix.conf
     Alias /monitorix /usr/share/monitorix
   ScriptAlias /monitorix-cgi /usr/share/monitorix/cgi-bin

<Directory /usr/share/monitorix/cgi-bin/>
        DirectoryIndex monitorix.cgi
        Options ExecCGI
        order deny,allow
        deny from all
 #        allow from 127.0.0.1
        allow from all    ------------ change above line like this
 </Directory>

# /etc/init.d/httpd reload

# service monitorix start

# chkconfig monitorix on

This version introduces two new major features. The first one refers to a new MySQL statistics multigraph which includes a complete and an overall state of the current performance of a MySQL server. The six nested graphs cover the most important and relevant status information which should help System Administrators to optimize their MySQL server accordingly.

This graph requires an unprivileged MySQL user (with password) in order to collect all the statistics. So it's strongly recommended to NOT grant any privilege to any database to this user.

The following are the two commands in order to create such unprivileged user:

mysql> CREATE USER ’user’@’localhost’ IDENTIFIED BY ‘password’;

mysql> FLUSH PRIVILEGES;

# service mysqld restart   

vim /etc/monitorix.conf
enable options of mysql to Y    --- to enable a fearture Y and to disable a feature N

# service monitorix restart

# service mysqld restart

# /etc/init.d/httpd reload

To access the interface http://192.168.1.67/monitorix/

























































Friday, 30 March 2012

Network & Bandwidth Monitoring Using Darkstat

Let check how can we monitor traffic using Darkstat in a machine. traffic grapher designed to run on a router, collect traffic statistics, export them to HTML pages.

$ sudo apt-get install darkstat

make some changes to Darkstat's configuration file, /etc/darkstat/init.cfg
 vim /etc/darkstat/init.cfg  ----- edit no to "yes"

# Turn this to yes when you have configured the options below.
START_DARKSTAT=yes

# Don't forget to read the man page.

# You must set this option, else darkstat may not listen to
# the interface you want
INTERFACE="-i eth0"
PORT="-p 666"
BINDIP="-b 127.0.0.1"
LOCAL="-l 192.168.1.0/24"
FIP="-f 127.0.0.1"
DNS="-n"

#SPY="--spy eth0"
# /etc/init.d/darkstat start
or
# darkstat -i eth0
 
Access the interface using  http://localhost:667/