4

Set up a server status script on a VPS or Dedicated server

 2 years ago
source link: https://help.dreamhost.com/hc/en-us/articles/215280068-Set-up-a-server-status-script-on-a-VPS-or-Dedicated-server
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Set up a server status script on a VPS or Dedicated server

Overview

If you have a VPS or Dedicated Server, you might be interested in finding the status of that server without having to wait at a terminal window. Instead, you can run a script that emails you this information about the status of your server.

It works by outputing HTML content containing information on your server, including:

  • load average
  • memory usage
  • open network connections
  • top 10 memory processes
  • top 10 CPU processes
  • netstat output
  • top snapshot of all running processes

This only applies to your web server. Shell access to MySQL VPS is not available.

Installing a server script

Download a copy of the script in one of two ways.

It's recommended you add the script into your user's home directory.

Click the following link to download the script to your computer:

You must then upload the file via FTP.

Log in to your server via SSH. You can then simply run the following command to download the script:

[server]$ curl -s -o status.rb https://cdn.jsdelivr.net/gh/watsonian/server-status-report@master/status.rb

Confirming if mailx is installed

Once you've downloaded the script successfully, you must make sure that the mailx package is installed. To find out, run the following command:

[server]$ dpkg -l | grep mailx

If installed, you'll see the following output.

ii  bsd-mailx     8.1.2-0.20180807cvs-1     simple mail user agent

If instead, you see the following output, you need to install it.

rc  mailx     8.1.2-0.20050715cvs-1     A simple mail user agent

admin user. This is because it requires. Once logged in, run the following command:

[server]$ sudo apt-get install mailx

Creating a cron job

View the Crontab article for details on how to create a cron job under your shell user. Enter the following command in the panel when creating the cron job:

[server]$ /usr/bin/ruby /path/to/script/status.rb | /usr/bin/mail -a "Content-type: text/html;" -s "Status Report: $HOSTNAME" "[email protected]"
  • If you added the script to your user's home directory, you can change the path to ~/status.rb.
  • Change the email address to where you’d like the cron job email sent to.
  • You can change the subject to anything you like.
  • If you want to CC the email to more email addresses, you can use the -c flag and pass it a comma separated list of email addresses.

Email

If you set everything up properly, then you should start getting emails that look roughly like this:

Server status script preview.png

See also

Did this article answer your questions?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK