keskiviikko 4. syyskuuta 2013

Server Monitoring and Munin (ubuntu 13.04)

Monitoring tools


First I am going to use some basic commands to find useful information about my server.

top 

this command shows a lot of information. Computer uptime, how long your server has been running, how many users. How many tasks are running, how much memory and cpu programs are using. WA is your computer disk waiting time. If it grows very big it means your hard drive isn't fast enough to serve. It may mean you have a slow/defective disk. Kill top with CTRL + C


free -m

this command shows how much memory your computer is using and how much is free. This is useful if you don't know how much memory your computer have or you have to look if the computer is running out of memory.


Next command is sudo iotop -oa before you can run this ocmmand you need to install iotop with sudo apt-get install iotop

Iotop shows your hard drive read and write speed. Both of these are recorded here. Kill it with CTRL + C


Stress test

In some cases you might want to stress your computer and see how it performances or will it overheat. For example you have just bought new pc. Stress it for few hours and see if it breaks. If not you can be sure it won't overheat in first pike. Start by installing stress.

sudo apt-get install stress

Start with the example stress test and then increase time if wanted. Open a new terminal at the same time and type top to see how it will stress the cpu.

stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s



Munin

"Munin is a networked resource monitoring tool that can help analyze resource trends and "what just happened to kill our performance?" problems. It is designed to be very plug and play. A default installation provides a lot of graphs with almost no work."

In this post we are going to look how our server is doing. Server administrator should know what is normal behavior and what is not. We are going to use Munin which prints some graphics for us and stress the computer little bit.

First install apache2 so we can get some graphs online. Update your repositories first.

sudo apt-get update  
sudo apt-get install apache2

Start by installing Munin.

sudo apt-get install munin

we want to see Munin graphs from anywhere so we need to edit its config file.

sudoedit /etc/munin/munin.conf

Outcomment these lines and also edit htmldir to your wanted folder. I am going to create that munin folder specified here:

dbdir /var/lib/munin
htmldir /var/www/munin
logdir /var/log/munin
rundir /var/run/munin

tmpldir /etc/munin/templates



Next we create the directory /var/www/munin and change its ownership to the user and group munin, otherwise munin cannot place its output in that directory. Then we restart munin:

mkdir -p /var/www/munin
chown munin:munin /var/www/munin
/etc/init.d/munin-node restart 


Now wait a few minutes so that munin can produce its first output, and then go to http://localhost/munin in your browser, and you see the first statistics.


Password protection!

You should protect your statistics unless you want that everyone can see every little details about your server.

We are going to create .htaccess file in /var/www/munin

To do that type sudoedit /var/www/munin/ .htaccess

copy paste this to the .htaccess file: 


AuthType Basic
AuthName "Admin Only"
AuthUserFile /var/www/munin/.htpasswd
<limit GET PUT POST>
require valid-user
</limit>



Then we must create the password file /var/www/munin/.htpasswd.

Pick your admin name, for example admin. and type into terminal:
sudo htpasswd -c /var/www/munin/ .htpasswd admin 

Enter a password for admin, and then we are going to change apache2 settings.
Edit apache default settings by adding this:


sudoedit /etc/apache2/sites-available/default

<Directory /var/www/munin/>
        AllowOverride AuthConfig
        AuthName "Please insert your login data."
        AuthType Basic
        AuthUserFile /var/www/munin/.htpasswd
        AuthGroupFile /dev/null
        require user admin
    </Directory>

 sudo service apache2 restart

Now try localhost/munin and it asks login details!



Original instructions:
http://www.howtoforge.com/server_monitoring_monit_munin

Graphs

Go to Munin page, select localdomain and eth0 traffic. This graph shows the traffic of the eth0 network interface. Means how much traffic your network has.


My "server" was online about 1,5 hours and this is the graph I got. Not very much traffic.

Next we are picking CPU usage. This graph shows how CPU time is spent.


If I understood this graph well, the cpu is not doing very much. There is small 100% pike which is because of the stress test. Very useful information. 

Last one is Memory usage. As we can see this graph shows average, current and max memory usage. Very useful graph to see at what times your server is using more ram and is it enough.





1 kommentti: