Articles RSS Feed

Blite Blog

Blite : a lightweight blog app

OpenVZ Server Status Script

Posted 21 Jan 2011, 1:54 pm in Scripts

This script generates an HTML report that provides a status overview of an OpenVZ VPS.

This version of the script is no longer maintained. A new version is available here.

The script is written in bash and is designed to be run as a cronjob by the root user. It generates a simple HTML page as shown in the screenshot at left. There are a few gazillion scripts floating around the web that perform a similar function, and I don't claim this script is any better :)

Actually, I didn't even set out to write a 'server status' script. The project began as an exercise in bash scripting, doing such things as creating and iterating through arrays and using functions. And because of this the script does lots of things the hard way :)

For instance, we could easily write a script that generates an 'uptime' report like this:

#!/bin/bash
echo `uptime` > report

The hard way of doing it is to read /proc/uptime, perform the arithmetic and format the output. That's what I've done -- not because I like doing things the hard way but as a learning exercise.

If you'd like to view the code, here's a link: /files/scripts/status.sh.txt.

Setup

Decide where you want to put the script. I usually create a directory /root/scripts for things like this. Then, to install the script:

[root@vps] cd /root/scripts
[root@vps] wget http://linux.dashed.ca/files/scripts/status.sh.txt
[root@vps] mv status.sh.txt status.sh
[root@vps] chmod 700 status.sh
[root@vps] vi status.sh

...and edit the script settings. The only thing you must change is the path for the HTML report. Comments in the script explain the other settings.

Next, create a root cronjob to run the script:

[root@vps] crontab -e

...and add a line like this to run it every 5 minutes:

*/5 * * * * /root/scripts/status.sh

You can adjust the interval to your liking -- every 10 minutes, or 30 minutes, etc.

Comments and suggestions for improvement are welcome!

4 Comments
Comments RSS Feed
M.M:
Wow that great work even though I don't think that I need to use currently. If u need suggestions it's almost perfect actually, just if you find it useful might want to add QOS report to the bottom, or check which QOS limits have fail count and only display them in the bottom of this report.

But what this does is really a nice job. I like the seperate html file.

Good luck.
8 Feb 2011, 8:15 am · Permalink
Doug:
Thanks M.M! If you mean checking user_beancounters for failures, the script does that -- at least for privvmpages and oomguarpages. If either of those parameters has a fail count it's display to the right of the usage %.
9 Feb 2011, 9:34 pm · Permalink
As a suggestion, what about converting this to an script for cgi? Well, just need to comment 2 lines :P and add another.

Another thing, if this is a cgi, maybe we can accumulate the results over time. Particularly the traffic information, maybe we can get the traffic since boot time.
11 Feb 2011, 8:19 am · Permalink
Doug:
Yomero, my preference is to have it static, but feel free to modify the script however you want. Let us know how it goes!
13 Feb 2011, 1:55 pm · Permalink
Comments are closed for this post.