Monitoring Dedicated Server Performance

I recently moved from a VPS to a dedicated server and its great, I’m getting a lot more server for the same money as a maxed out VPS.

However I’m having trouble working out the best way to monitor the server’s status, how much disc space / RAM is used / available etc. I’ve managed to hack together a load graph using PHP and ‘/proc/loadavg’ and Google graphs but that’s about it.

Does anyone have any ideas or experience with monitoring a Dreamhost dedicated server? I see some vague references to ‘Munin’ around the web and have talked to support about same but here’s not a lot of information available.

Anyone got any ideas about this?

Very simple suggestion, you probably already know, but from the shell

will give you hard drive space available and used. I’ve used this on sites before to give live info on hard drive status (only to those who need to know, obviously). Combined with a cron job that cuts the output and writes the avail/used (and therefore calculates the free) to a data file you can end up with a table of data from which you can build a chart.

There are undoubtedly similar commands to fetch the same stats for RAM but I don’t know them off the top of my head. The DreamHost panel has RAM usage charts for VPS. Is it not the same for dedicated?

The corresponding command for memory is “free -m”.

@Andrew F: Is that how you build the source data for your VPS memory charts?

We gather memory data through a slightly different path (we’re using a tool which runs on the VPS host machine), but it’s the same numbers.

You might want to take a look at the sar command.

Thanks for that, the dedicated servers don’t have any usage charts so I’m building my own with PHP/JS. (So as to stay in my comfort zone for this little job :slight_smile:

The shell command works fine thanks, not sure I can run shell_exec() to store the data but it’s good for a quick look via putty.

That works fine also :slight_smile:

I’ve run into that page before cos of reading about ‘/proc/loadavg’ which is what I’m using to store the load data, via PHP’s native file_get_contents(), very simple solution.

Can I get the other data I need, RAM, disc usage, etc via the proc filesystem ?

I will do my own research on this but any pointers gratefully received :slight_smile:

There are several ways you can store the data using these commands, but two basic approaches suggest themselves:

One is to put the command(s) in a shell script and have a cron job execute that on a regular basis. Use the cron job or the shell script itself to write the data to a file. Then your PHP script can read the data from that file.

Another is to use one of the PHP functions that allows you to capture the output of a shell command to a string - I think shell_exec() does this - and either use the data there and then or write it to your data file using PHP.

As an example, the following shell command will output a single row of CSV data containing the total, used and free RAM (in MB):

The cells in the row are date and time (YYYY-MM-DD HH:MM), total ram, used ram and free ram, e.g.

So you can either redirect the output of this command to a file to build up a CSV file of your data (note the double “>>”, that appends the output of the command to the file rather than overwriting it):

Or you can capture the data directly in your PHP script and do what you want with it from there (present it, email it, store it in a datafile, whatever):

[code]$memCsv = trim(shell_exec(‘free -m | grep Mem | sed “s/ */,/g” | sed "s/Mem:/$(date +’"%Y-%m-%d %H:%M"’)/" | cut -d"," -f1-4’));

$memStats = str_getcsv($memCsv);
$date = $memStats[0];
$totalMb = $memStats[1];
$usedMb = $memStats[2];
$availMb = $memStats[3];

You can use a similar approach with the df -hm command to get the disk space usage stats.

You can do almost anything you want - even from PHP. DreamHost are seriously killer when it comes to this kinda stuff.

They might not give direct instruction on how to tie the noose, but they do supply enough rope to hang ourselves :smiley:

They sure do, I had assumed that PHP ‘safe_mode’ was on, but i just double checked and it’s off, shell_exec() should be available. Looks like I do have enough rope and I’ll try some of the suggestions above.

Awesome, thank you, I went for the PHP option cos that’s closest to how I’d done the load graph already, stored the values in a MySQL data table and now I have a memory graph :slight_smile: