Skip to main content
  1. All Posts/

server-stats

Tools PHP

Statsy

Statsy is an easy to use open source PHP tool for developers, that allows you to return various types of information about your server. It can be used to retrieve static information or can be set up to auto refresh any data that is needed for your project, however you can still use Statsy and Statsy Auto together at the same time. Statsy makes it very easy to create dashboards and server monitoring apps.
To use Statsy you can either call the function or get the information from an array. This allows you to do much more, as all the data is in an array making it easier to implement into your project and give you more flexibility.

UPDATE

The OO composer version of statsy will be released soon ETA: 1st August.

Table Of Contents

What Information Can Statsy Get?

Memory Stats

All memory stats can be returned as Kilobytes, Megabytes, or Gigabytes.

Disk Stats

All disk stats can be returned as Kilobytes, Megabytes, or Gigabytes.

CPU Stats

Misc

How To install Statsy

To install Statsy all you need to do is simply download the Statsy.php file from the Statsy folder and include the file on whatever file you want to call the functions using the following code:

<?php include 'directory-to-Statsy-file/Statsy.php'; ?>

Now you’re ready to start using Statsy! List of functions

How To install Statsy Auto

Using Statsy Auto is a little different then the normal Statsy. Instead of just calling the function or using the array you will need to set the location where you want the information to be shown then it will automatically be pulled in and refreshed. When using the normal Statsy you will only need to call the function or use the array however Statsy and Statsy Auto can be used together at the same time.

Step 1: Download The relevant files And jQuery

To install Statsy Auto you will need to download the three files in the Statsy Auto folder Statsy.php, Statsy.jsand stats_json.php. You will also need to make sure you have jQuery installed (jQuery will not be needed much longer).

Step 2: Configure the Statsy.js file (Most important step)

To configure this file you just need to set the variables so that Statsy knows where to find the stats_json.php and also knows where to display the data on your page/pages.
First set the var for the stats_json.php file location this can be either a directory path or a URL, this is shown in the example below:

var stats_json_url = "https://www.example.com/Statsy/stats_json.php";

Next set the var for the auto refresh delay. This is set in milliseconds (1000 milliseconds = 1 second), This is shown in the example below where the delay is set to 2 seconds:

var auto_refresh_delay = 2000;

Finally you just need to set where Statsy will display the information on your page by adding the class/ID names. The example below shows 2 examples one with a class snd one with an ID make sure to set all of the vars that you want to use.

var total_mem_loc = ".example-class";
var available_mem_loc = "#example-id";

Step 3: Configure the stats_json.php file (Only necessary if you want to customise the return kb, mb, gb)

To configure this file all you need to do is change the args in the arrays to whatever you want Statsy Auto to return. The example below shows how it is setup by default this will return all values in megabytes:

$mem = array(
    'total' => get_total_mem('mb'),
    'available' =>  get_available_mem('mb'),
    'cached' => get_cached_mem('mb'),
    'swap' => get_swap_mem('mb'),
    'buffer' => get_butffer_mem('mb'),
    'shmem' => get_shmem_mem('mb'),
    'sreclaimable' => get_sreclaimable_mem('mb'),
    'sunreclaim' => get_sunreclaim_mem('mb'),
    'free' => get_free_mem('mb'),
    'realfree' => get_realfree_mem('mb'),
    'used' => get_used_mem('mb'),
    'percent' => get_used_mem2()
  );

  $disk = array(
    'total' => get_disk_total('mb'),
    'free' => get_disk_free('mb'),
    'used' => get_disk_used('mb'),
    'percent' => get_disk_used2()
  );

There is no need to change anything else in this file unless you know what you are doing.This is all the configuration needed to use Statsy Auto.

List Of Functions And How To Use Them

Below is a list of all the functions in Statsy and how to call them using the function or array. Both the array and function will return the same thing its just preference. When using Statsy Auto you can also use these functions at the same time if you want to.

Memory

Total Memory

Examples of how to get total memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_total_mem('kb');
get_total_mem('mb');
get_total_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['totalkb'];
get()['mem']['totalmb'];
get()['mem']['totalgb'];

Available Memory

Examples of how to get available memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_available_mem('kb');
get_available_mem('mb');
get_available_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['availablekb'];
get()['mem']['availablemb'];
get()['mem']['availablegb'];

Cached Memory

Examples of how to get cached memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_cached_mem('kb');
get_cached_mem('mb');
get_cachede_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['cachedkb'];
get()['mem']['cachedmb'];
get()['mem']['cachedgb'];

Swap Memory

Examples of how to get swap memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_swap_mem('kb');
get_swap_mem('mb');
get_swap_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['swapkb'];
get()['mem']['swapmb'];
get()['mem']['swapgb'];

Buffer Memory

Examples of how to get buffer memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_buffer_mem('kb');
get_buffer_mem('mb');
get_buffer_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['bufferkb'];
get()['mem']['buffermb'];
get()['mem']['buffergb'];

Shmem Memory

Examples of how to get Shmem memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_shmem_mem('kb');
get_shmem_mem('mb');
get_shmem_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['shmemkb'];
get()['mem']['shmemmb'];
get()['mem']['shmemgb'];

SReclaimable Memory

Examples of how to get SReclaimable memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_sreclaimable_mem('kb');
get_sreclaimable_mem('mb');
get_sreclaimable_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['sreclaimablekb'];
get()['mem']['sreclaimablemb'];
get()['mem']['sreclaimablegb'];

SUnreclaim Memory

Examples of how to get SUnreclaim memory to display the value you will need to use echo:

Call using function:

To return value in kb, mb or gb:

get_sunreclaim_mem('kb');
get_sunreclaim_mem('mb');
get_sunreclaim_mem('gb');

Call using array:

To return value in kb, mb or gb:

get()['mem']['sunreclaimkb'];
get()['mem']['sunreclaimmb'];
get()['mem']['sunreclaimgb'];

Free Memory

Please bare in mind this is the free memory value from the /proc/meminfo/ file and is not the real free memory for that please see the Real Free