Howto Install Cacti on Ubuntu

Recently I wrote a blogpost about Smokeping. Although Smokeping is good in what it does, I needed some more features than available in Smokeping.
The customer for who I am setting up this monitoring needs more information like cpu usage history or memory history. After some research I got to Cacti. Cacti is an open source solution that has many possibilities like latency polling, cpu usage, memory usage and bandwidth usage. Cacti can do a lot more, but for this customer the above things are the key features.
Cacti is available for Windows and Linux. For this kind of tools I always use Linux, beacause 9 out of 10 times the tools work on Linux “out-of-the-box” and the windows versions need a lot of tweaking and tuning.
Installing Cacti on Ubuntu:
  • First update your machine –> sudo apt-get update (If you are behind a proxy server use the following command: http_proxy=http://ip-adres:port-nr apt-get update )
  • Install Cacti –> sudo apt-get install cacti
  • During the install you have to give in some password e.d., just follow the installation and everthing will be fine
  • After installing give the following cli commando: rrdtool create datafile.rrd DS:mysource:ABSOLUTE:900:0:10000000 RRA:AVERAGE:0.5:1:9600 RRA:AVERAGE:0.5:4:9600 RRA:AVERAGE:0.5:24:6000
  • Now open a browser with: http://ip-adres/cacti, follow the instructions and the installation is done
  • To actually monitor a device follow the next steps:
  • Click Console–>Devices–>Add, make sure it looks like the picture below
  • Capture
  • Click Create
  • When the screen reloads some new options are available, “Associated Graph Template” and “Associated Data Queries”, this are options to monitor several different types of devices.
  • To monitor the CPU load and Latency add “Cisco – CPU Usage” and “Unix – Ping Latency” to “Associated Graph Templates”
  • To monitor interface bandwidth add “SNMP – Interface Statistics” to “Associated Data Queries”
  • Click Save
  • Click Devices again and check the box and choose “Place on a tree” and click Go
To create the actual graph follow the next steps
  • Click new Graphs
  • Check the checkboxes of the interfaces/processes you want to monitor and click Create
  • Wait for five minutes and click graphs

 

Now you can see the graphs, but they are not filled….. Damn!
This can be resolved by following the next steps:

 

  • Open the ping.pl script: sudo nano /usr/share/cacti/site/scripts/ping.pl, the output will look like this:

 

#!/usr/bin/perl
# take care for tcp:hostname or TCP:ip@
$host = $ARGV[0];
$host =~ s/tcp:/$1/gis;
open(PROCESS, “ping -c 1 $host | grep icmp_seq | grep time |”);
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;
if ($2 == “”) {
print “U”;  # avoid cacti errors, but do not fake rrdtool stats
}elsif ($3 eq “usec”) {
print $2/1000; # re-calculate in units of “ms”
}else{
print $2;
}

 

  • Change “icmp_seq” into “icmp_req” save the file and restart the server

Wait for a couple of minutes and you’ll see that the graphs are getting filled!
Advertisements

Repair sudoers file on Ubuntu 12.04 LTS

Not really a network blogpost, but during the installation of Smokeping I somehow managed to damage my sudoers file. As a result I was not able to login to my Ubuntu machine. Because of the lack of a snapshot, the ubuntu machine is a virtualmachine, I could not just jump back in time and start over. I almost started installing the machine all over again, but then I found the solution by using google.

Here the steps to repair the sudoers file on Ubuntu Linux.
  • Restart your machine and start your machine in “recovery mode”
  • Choose to login as “root”
  • The file-system is mounted as read-only, to mount it in read-write mode use the following command: “mount -o rw, remount /”
  • Now copy the sudoers file to a backup file “sudo cp /etc/sudoers /etc/sudoers.backup/”
  • Create a new sudoers file: “sudo nano /etc/sudoers” and copy the following in to the file:

#
# This file MUST be edited with the ‘visudo’ command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on “#include” directives:

#includedir /etc/sudoers.d

  • Now close and save the file by using “ctrl + X” and restart the machine by “sudo shutdown -r now”

Install and configure Smokeping on Ubuntu 12.04 LTS

Currently I’m designing a network for a customer. To ground my design I also need some network statistics like bandwidth usage and latency in the current network.

Despite some big payed network monitoring packets, I had to install some free opensource monitoring packets to get the statistics I needed.
For latency monitoring I chose “Smokeping” based on the RRD tool and written by Tobi Oetiker & Niko Tyni.
The installation and configuration was pretty straight forward on Linux. I also tried installing it on Windows (the customer is primarily focused on Windows), but after several hours of troubleshooting I gave up and switched to Ubuntu linux.
Even though the installation was easy, I wrote a blogpost about it for my own future reference and maybe it is useful for others too.
  • First install a Linux distribution, I used Ubuntu
  • For the ease of installation, use the “sudo su” commando
  • Install the following packets: “aptitude install smokeping curl libauthen-radius-perl libnet-ldap-perl libnet-dns-perl libio-socket-ssl-perl libnet-telnet-perl libsocket6-perl libio-socket-inet6-perl apache2”
  • The smokeping configuration files can be found in “etc/smokeping/config.d”
  • Before use u need make some configuration changes:

“nano /etc/smokeping/config.d/General”

*** General ***

@include /etc/smokeping/config.d/pathnames

# Please edit this to suit your installation
owner = <name>
contact =” email@email.com”
cgiurl =” http://<your ip or dns name>/cgi-bin/smokeping.cgi”
mailhost =” smtp.email.com”
syslogfacility =” local0″
concurrentprobes =” no ”

Make sure that mailhost contains the primary MX for your email domain

“nano /etc/smokeping/config.d/Alerts”

*** Alerts ***
to = me@email.com
from = smokeping@email.com
“nano /etc/smokeping/config.d/Targets”

remark = Welcome to the SmokePing website of ‘Example Company’

<output omitted>

+ Local

menu = Local
title = Local Network

++ LocalMachine

menu = Local Machine
title = This host
host = localhost

Save your changes by using “ctrl + X”

now restart the smokeping service:

“/etc/init.d/smokeping restart”
You can reach smokeping byhttp://<ip or dns>/cgi-bin/smokeping.cgi” and the output will look like this: