Let’s Build a Server: Part 2 – Monitoring

Monit

Last time, in Part 1, we discussed setting up a firewall and an email relay so notifications from the firewall could get to us.

Now, in Part 2, we’re going to talk about more signal. Server monitoring and alerting. Our primary software for monitoring is Monit.

Monit has a single configuration file, but many distributions, including mine, set up a /etc/monit.d folder so you can divide your monit configuration into different files.

Once it is running, you can monitor its status by running
monit status
It will show the status of whatever is monitoring. There is also an optional web component, if you want to check status in a web browser.

What can you monitor?

Monit can monitor any program and restart it if it crashes.
check process nginx with pidfile /var/run/nginx.pid
start program = "/bin/systemctl start nginx.service"
stop program = "/bin/systemctl stop nginx.service"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

As you can see, the simple scripting language allows you to not only restart, execute programs, but alert the user.

Not only can it make sure something is running, but it can monitor its resource usage, as well as system resource usage. It can monitor processes, network connections, programs and scripts, files, directories, etc.

An Alternative to Email Alerts

The default for an alert is to send an alert email, but for bigger emergencies, a phone push notification is also useful.

Monit provides a simple instruction on how to set it up for Pushover. There is also the alternative of PushBullet.

Pushover costs $5 per platform(Android, iOS, Desktop) to use on as many devices as you want. There is a per application limit of 7,500 messages per month. Pushbullet is, by comparison, free. The basic difference as I see it is that Pushbullet is more geared toward the consumer, and Pushover is more geared toward developers in how it was initially set up. They do have similar feature sets though.

Here is Monit’s suggested Pushover script, which can be run instead of an email alert.

/usr/bin/curl -s
-F "token=your_mmonit_or_monit_app_token"
-F "user=your_pushover_net_user_token"
-F "message=[$MONIT_HOST] $MONIT_SERVICE - $MONIT_DESCRIPTION"
https://api.pushover.net/1/messages.json

Here is an alternative version for Pushbullet

curl -u <your_access_token_here>: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "$MONIT_HOST", "body": "$MONIT_SERVICE - $MONIT_DESCRIPTION"}'

Conclusion

In all cases, monit allows you to monitor your system and take action based on a change in performance. The complexity of your rules is entirely up to you. But, if you give thought to their setup, you can not only be told when there is a server emergency, but the system can take action to fix it.

Trying to Build a Better Web Server

We’ve been working hard here, behind the scenes, upgrading the Weneca Media servers. The Weneca Media Group is the umbrella term for all the sites we collectively host together.

The Weneca server works on what is called a LEMP stack. Linux, Nginx, MySQL, PHP. Nginx(pronounced Engine-X) is a lightweight web server which powers about 10% of the world’s web servers, including sites like WordPress.com and Netflix. Most of you have probably heard of Linux, the MySQL database server, and the PHP scripting language.

Nginx has just announced SPDY support in its development version, which should speed things up more. SPDY is a Google developed protocol to reduce web page load time, and is implemented in both Chrome and Firefox. It can work concurrently with HTTP, the common standard for web serving.

So, with this, we have a solid footing for implementing a lightweight framework to serve a lot of web pages. However, Nginx does not have built in PHP support. You have to pass PHP to be handled by another program. In this case, we are using PHP-FPM, which is now part of the official PHP package. PHP-FPM is a FastCGI manager creates a pool of processes to process PHP scripts and return the results to the server.

To reduce load on this, Nginx supports FastCGI caching, so the results of any dynamically built page, with some deliberate exceptions, are cached for a few minutes, and can be served as static files. The duration of the caching is variable. If you want basically fresh content, you can microcache, cache in seconds. So, only when your server got hammered would it be seeing static content. If you have a bit less dynamic content, you can increase that to minutes, or even hours.

Now, we continue to tweak and improve the services. In future, we’ll be covering a little of the Nginx and PHP-FPM configuration settings you may find interesting.

 

 

Dvorak Likes Linux – Good or Bad?

Dvorak hosting Episode 19 of CrankyGeeks.
Image via Wikipedia

We like John C. Dvorak. He’s a well known tech pundit, very outspoken, and interesting to read. However, one of the most interesting aspects of reading Dvorak is how often we disagree with him.

Dvorak has finally discovered Ubuntu 8.10, four months after the current version was released.

Many of its problems, for me, stem from its inability to run on my overloaded hardware, or the occasional driver that makes the OS impossible to use without hand-tweaking something or other.

To disagree with Mr. Dvorak, Linux has made great strides in hardware support, with both independent developers and hardware manufacturers working to ensure support. The simplest way to ensure you don’t come across a device that isn’t supported under Linux is to check before you buy it. Most devices are. So far, since we switched to Linux, we’ve only found a noname GPS receiver, a Canon Scanner, and a Radio Shack postal scale failing to work under it. But we usually check before we buy. Most minor hardware issues can usually be resolved with a little online searching. Even he admits Linux support is increasing on new hardware.

He does point out many good things about Linux during his exploration of Ubuntu.

  • The lightweight nature of it makes it perfect for older machines. Many distributions offer lower memory(RAM or HD) alternatives to programs, such as Abiword instead of OpenOffice, XFCE or Sugar instead of Gnome or KDE, etc.
  • “There is probably a Linux program that will substitute for just about any Windows programs with as much or more functionality.” Not sure we agree with him on Photoshop vs. Gimp, but we’re not artists.
  • Linux is mostly immune to malware and viruses, as the bulk of such things are written for Windows.
  • The Windows registry is ultimately flawed. It is an increasingly unwieldy database that over time, slows Windows to a crawl.

He does note that the Linux desktops are not as polished as Windows. However, we’re not sure whether or not he tried Compiz Fusion, which enables all those nice windows animations. We loved watching them, but we loved speed more, and ultimately turned them off. For productivity use, we’d rather simplify.

Even the French police recognize the wonder of Linux. They’ve saved millions by migrating to Ubuntu. Currently, they are running Ubuntu on about 5,000 workstations with long term plans to have their entire organization (90,000 workstations) running Ubuntu by 2015. Their budget has been reduced by seventy percent without losing any functionality.

We’d love to hear your thoughts on this. Comment with your thoughts.

Reblog this post [with Zemanta]