Getting Started

Servers

Sites

APIs

Need Help…

Modifying shell scripts

For many users, the commands for the default monitors within the shell script will work fine. However, since Linux is not homogeneous, it may be necessary to alter some of the commands that are being used in order for the script to function.

As such, we'll examine each of the commands used by the default monitors and consider any changes that you might need to make. The corresponding shell script variables for each command are shown in brackets beside the below headers.

The fastest way to confirm the existence of any issues, is to run the script directly within a terminal. Other than some messages, you shouldn't see any output indicating errors.

Uptime (up_time)

In order to retrieve the total uptime of the system, the uptime -s command is used. This command is native to many Linux distributions, so it often won't be a problem. However, if it is unavailable, you'll need to install the procps package to use it.

Alternatively, you can try: cat /proc/uptime or: who -b | awk '{print($3" "$4)}' or: sysctl kern.boottime However, please note that the output from these commands may be in a different format to what Pulse expects, so you may need to modify it. The expected output is a date / time string in the format YYYY-MM-DD HH:MM:SS, for example: 2019-02-28 15:16:09

CPU Usage (cpu)

In order to retrieve the current CPU usage of the system, the top command is used several times to gauge the average over time. This command is native to almost all Linux distributions, so it shouldn't present a problem. However, if it is unavailable, you'll need to install the procps package to use it.

Alternatively, there are many utilities that provide the same information. However, modifying the command to suit these tools may be more cumbersome than simply installing the package. Regardless of which tool you use, Pulse expects a whole number between 0 - 100 indicating the percentage of CPU being used.

Memory / RAM (memory)

In order to retrieve the current memory usage of the system, the free command is used several times to gauge the average over time. This command is native to almost all Linux distributions, so it shouldn't present a problem. However, if it is unavailable, you'll need to install the procps package to use it.

Alternatively, there are many utilities that provide the same information. However, modifying the command to suit these tools may be more cumbersome than simply installing the package. Regardless of which tool you use, Pulse expects a whole number between 0 - 100 indicating the percentage of memory being used.

Average Load (load)

In order to retrieve the current system load, Pulse reads the value from: /proc/loadavg It then divides the value by the number of CPUs on the server: /proc/cpuinfo Finally, the result is converted to a percentage.

No particular tools are used to obtain the above numbers, however the script expects to find 'loadavg' & 'cpuinfo' and be able to read them. If these values are unavailable from these sources, you will have to use other means to retrieve them.

Regardless of which command you use, Pulse expects a whole number indicating the percentage of system load. This can be more than 100.

Disk Storage (storage)

In order to retrieve the current amount of used disk space, the df command is used. This command is native to almost all Linux distributions, so it shouldn't present a problem. However, if it is unavailable, you'll need to install an alternative.

By default, the command performs its calculation on the total available disk space of the server (derived from all available disks). This approach is ideal for environments deployed on single disk, however for servers with multiple disks, you may wish to adjust the command to monitor a specific one. Alternatively, you may opt to leave the command as is and create separate, custom monitors for each disk.

Regardless of your approach, for the default disk storage monitor, Pulse expects a whole number between 0 - 100 indicating the percentage of space being used.

Networking (network_in, network_out)

In order to retrieve the current rates of inbound and outbound network traffic, Pulse reads the two sets of values from:

/sys/class/net/eth0/statistics/rx_bytes /sys/class/net/eth0/statistics/tx_bytes

This action is performed several times to gauge the average over time.

For many VPS environments, the above commands are often appropriate, as the server will likely have a single virtual networking interface identified as 'eth0'.

However, the network interface may also be something completely different. To confirm if your server has a default interface, run the following command:

ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)'

If the command returns an identifying string e.g. 'eth0', that's what should be used. Alternatively, run the following command to retrieve the full server routing table:

ip -4 route ls

The first line should be labelled 'default', while the next line or lines may be indented. Make a note of the identifier(s) between 'dev' and 'weight'. You can then use 'cat' to verify if the identifier is correct e.g.

cat /sys/class/net/identifier/statistics/rx_bytes

If the output is not zero, it is likely the correct network device. You should now replace the four 'eth0' references in the shell script with the correct identifier.

If you are unable to find the correct device, contact your system administrator or hosting company for further assistance.

For both inbound and outbound monitors, Pulse expects a whole number indicating the number of megabits per second transferred (Mbps). As a result, you will need to perform a conversion on the byte figures (divide them by 625000).