Saturday, October 12, 2013

Monitorix - a better way to monitor a server

Monitorix definitely is an easy and convenient way to monitor a server. Look at this pictures of how I monitor my Raspberry Pi:





It features an easy way to monitor daily, weekly, monthly and yearly periods.

Graphs include:
  • System load
  • Kernel usage
  • Filesystem usage
  • Disk I/O
  • Network (global and per service/port. And I want to emphasize that - per service and per port - very cool)
  • Users
  • Sensors
  • and a bunch more which I turned off :)
Every graph in there is clickable and gives you a bigger picture of one of your interest.

Why Monitorix is so cool?

Monirorix is cool because:
  • It's free and opensource. I (personally) don't care much about the later, but some of us like that
  • Once installed, it can be accessed from any web browser. I monitor my server even from phone.
  • It's lightweight
    • It doesn't require a web server and can be configured either to use a web-server or to run in a stand-alone mode
  • It shows the information in graphs which are configurable and easy to read
  • It can be configured to fire alarms on certain conditions (i.e. I use an alarm to send me an email once the System Load is above 75% for the last 15 minutes. The second alarm I use is when the free space on / reaches 75%)
  • It has a built-in Basic Access Authentication which is a very handy to have if combined with the access from the Internet
  • It can automatically send email reports (daily, weekly, monthly, early) with all the graphs in there

How does Monitorix work?

Monitorix is a bunch of Perl scripts. It can be installed either from the official web site or as a package on many modern Linux/Unix distributions.
It reads data from various places and saves it in database files. It reads frequently enough, though. And writes database files frequently enough as well. So, that's not good to keep on running on a hard drive or SSD all the time. The later wears off and the former is too slow to operate fast.
Here is the good news:

Monitorix causes too much of Disk I/O - I wanna optimize it

Anything-sync-daemon is your best friend there. A good fellow Graysky developed it for us and published on his GitHub page. Read up the documentation on Arch wiki - it is pretty straight forward. Few words - it works by pushing a desired directory into tmpfs, which is essentially, your RAM. That really sky rockets your Monitorix. It works orders of magnitude faster. And don't worry, your data survives reboots. When the daemon starts it copies a directory into the RAM and when it stops, it transfers the data back to the drive.

Too much RAM is consumed, I wanna optimize that

That is also achievable. Out of the box Monitorix eats more than 40Mb. While it may sound goofy for modern servers, it doesn't sound the same when you want to install it on a BeagelBone or Raspberry Pi like I did. After tuning my installation consumes only 19Mb.

To cut some memory off Monitorix which is never used on purpose back to the system you need to open your monitorix.conf:
# vim /etc/monitorix.conf
  • Go to <graph_enable> section and turn everything you don't want to see to "n" state.
  • For each of the sections which stood in "y" check man monitorix.conf or the official documentation and see if the section has a list associated with it, i.e. fs is a good example - the smaller the list, the smaller the resulting db file will be. Warning from man:
    WARNING: Every time the number of groups in this option changes, Monitorix will resize the fs.rrd file accordingly, removing all historical data.

Alerts

Alerts are implemented as hooks to shell commands. The end-point can be any, starting from sh, Python and ending wherever your imagination can bring you. Alerts are really easy to use and a good example is shown right here in Automated Email Alerts.

Finally

Finally, I'm giving away my monitorix.conf which I tuned for Raspberry Pi. Pay extra attention to alerts subsection under system and under fs which you most likely will want to change to your own hooks.

2 comments:

  1. a newbie question: why is it necessary that you run a server? I know you run cron jobs, but isn't a desktop ubuntu or windows capable of cron jobs also? I have a 10 year old pc that's been gathering dusts, if I want to convert it into a server, what kind of software do you recommend? thanks

    ReplyDelete
    Replies
    1. Your question is about Monitorix, right?

      A server generally is any remote computer which serves some kind of information. Your laptop may act as an SSH server to another laptop which would be a client connecting to your laptop.

      I don't see a good use-case of installing Monitorix on the computer you work from. Monitorix is good on a server when you don't want to or have no ability of connecting to the remote host, but you still want to see the state of the host.

      Windows has no inborn ability to run cron, so you'd want to install Cygwin if you really prefer Cron over Windows task scheduler.

      Delete