Collectd is a data collection tool for a large number of Unix based services. The output of collectd is in rrd format. You can use tools such as collectd-web to graph the output and view via Apache. In this article I will show you on how install collectd on CentOS and use it for monitoring libvirt (KVM) as well as for Apache monitoring. Collectd does not do any alerting, just trend analysis, similar to MRTG or Cacti. Collectd is not a replacement for Nagios, which does alerting as well.
Install collectd
yum install collectd -y yum install collectd-virt -y yum install collectd-apache -y
In /etc/collectd.conf replace:
PluginDir "/usr/lib/collectd"
With:
PluginDir "/usr/lib64/collectd"
In /etc/collectd.conf uncomment the following lines, while replacing BaseDir with the location you want the rrd output files to go to
BaseDir "/usr/var/lib/collectd" PIDFile "/usr/var/run/collectd.pid" PluginDir "/usr/lib64/collectd" LoadPlugin logfile LogLevel info File "/var/log/collectd.log" Timestamp true PrintSeverity false
Also uncomment the following to load apache and libvirt plugins:
LoadPlugin apache LoadPlugin libvirt Connection "kvm:///" RefreshInterval 60 # Domain "name" # BlockDevice "name:device" # InterfaceDevice "name:device" # IgnoreSelected false # HostnameFormat name
Start collectd
/etc/init.d/collectd start
One way to view collectd stats is to use Apache with collectd-web.
Install collectd-web:
yum install collectd-web -y
Edit the collections file:
vim /etc/collections.conf Change DataDir to be: DataDir "/var/log/collectd/"
Also, rewrite HTTP to HTTPS for security:
Redirect HTTP to HTTPS: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Point your browser to http://localhost/collectd
——————————————————————————————————————————————————————————–
Nagios comes in two flavors, a commercial version and an open source free version. In this blog I will cover the basics of installing and setting Nagios up.
Download Nagios:
sudo wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.0rc1.tar.gz sudo wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
Install the needed development libraries:
sudo yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
Untar and build Nagios:
tar zxvf nagios-4.0.0rc1.tar.gz tar zxvf nagios-plugins-1.4.16.tar.gz cd nagios ./configure --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode make install-webconf
Set proper permission and verify if the config file is ok:
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Make sure you disable SELINUX, otherwise Nagios won’t work:
echo 1 > /selinux/enforce sed -e 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config > /etc/selinux/config.new mv /etc/selinux/config.new /etc/selinux/config
Configure Nagios plugins:
cd ../nagios-plugins-1.4.15 ./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Now you are ready to start Nagios:
/etc/init.d/nagios start /etc/init.d/httpd start chkconfig --add nagios chkconfig --add httpd chkconfig --level 3 nagios on chkconfig --level 3 httpd on
Create Nagios web user:
htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now you are ready to view: http://yourhost/nagios. Login with nagiosadmin as the user and the password you specified with htpasswd.
Next thing to do is configure the hosts you want to monitor. I normally uncomment the line cfg_dir=/usr/local/nagios/etc/servers in /usr/local/nagios/etc/nagios.cfg and put my server configs there. If you need assistance in creating a config file view additional documentation here http://nagios.sourceforge.net/docs/3_0/config.html.
Cacti is a very useful tool for graphing SNMP based data. If you have used MRTG, Cacti is MRTG on steroids. In this article I will cover the basics of installing Cacti. Some of the things you can graph with Cacti include load average, memory usage, and disk usage.
Install Apache
sudo yum install httpd httpd-devel -y
Install MySQL
sudo yum install mysql mysql-server
Install PHP
sudo yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-mysql -y
Install PHP-SNMP
sudo yum install php-snmp -y
Install Net-SNMP
sudo yum install net-snmp-utils net-snmp-libs -y
Install RRDTOOL
sudo yum install rrdtool
Enable EPEL repository in order to download and install cacti
sudo wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm sudo rpm -ivh epel-release-6-8.noarch.rpm
Download and install Cacti
sudo yum install cacti
Start MySQL, HTTPD, and SNMP
sudo service httpd start sudo service mysqld start sudo service snmpd start
Ensure that all 3 services start upon system boot
sudo /sbin/chkconfig --levels 345 httpd on sudo /sbin/chkconfig --levels 345 mysqld on sudo /sbin/chkconfig --levels 345 snmpd on
Create MySQL Cacti database
mysql -u root -p mysql> create database cacti; mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'your-password-here'; mysql> FLUSH privileges; mysql> quit;
Create the tables in the Cacti database
rpm -ql cacti | grep cacti.sql mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8a/cacti.sql
Configure database connection values:
sudo vi /etc/cacti/db.php /* make sure these values reflect your actual database/host/user/password */ $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "your-password-here"; $database_port = "3306"; $database_ssl = false;
Configure Cacti in Apache
sudo vi /etc/httpd/conf.d/cacti.conf Alias /cacti /usr/share/cacti Order Deny,Allow Deny from all Allow from
Restart Apache
sudo /etc/init.d/httpd restart
Add Cacti to cron
sudo vi /etc/cron.d/cacti #Uncomment the following line */5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
Next step is to install SNMPD on clients so that Cacti can poll the host, in the below example I am using Ubuntu client
sudo apt-get install snmpd sudo apt-get install snmp-mibs-downloader
Enable SNMPD to listen on all interfaces on the Ubuntu client:
sudo vi /etc/default/snmpd #Comment out the below line SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid' #Add the below line SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
Replace /etc/snmp/snmpd.conf with the following on the Ubuntu client:
$ cat /etc/snmp/snmpd.conf rocommunity public syslocation "Your Location" syscontact admin@domain.com iquerySecName internalUser rouser internalUser
On the client restart snmpd:
sudo /etc/init.d/snnmpd stop sudo /etc/init.d/snnmpd start
You are now ready to access Cacti with the URL of your host:
http://YOUR-IP-HERE/cacti/
At the Installer screen click on ‘Next’ and ‘Next’. Cacti will show you the path of rrdtool and other binaries, if they look ok, accept and click on Finish. For user login use admin as username and password as admin. You will have to select a new password after which you are ready to add hosts. For additional reference see http://www.cacti.net/.