Stars: 105
Forks: 9
Pull Requests: 4
Issues: 3
Watchers: 5
Last Updated: 2022-05-16 14:52:36
Statsy is a easy to use open source PHP tool for developers, that allows you to return various types of information about your server.
License: MIT License
Languages: PHP, JavaScript
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.
The OO composer version of statsy will be released soon ETA: 1st August.
All memory stats can be returned as Kilobytes, Megabytes, or Gigabytes.
All disk stats can be returned as Kilobytes, Megabytes, or Gigabytes.
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
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.
To install Statsy Auto you will need to download the three files in the Statsy Auto folder Statsy.php
, Statsy.js
and stats_json.php
. You will also need to make sure you have jQuery installed (jQuery will not be needed much longer).
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";
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.
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.
Examples of how to get total memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_total_mem('kb');
get_total_mem('mb');
get_total_mem('gb');
To return value in kb, mb or gb:
get()['mem']['totalkb'];
get()['mem']['totalmb'];
get()['mem']['totalgb'];
Examples of how to get available memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_available_mem('kb');
get_available_mem('mb');
get_available_mem('gb');
To return value in kb, mb or gb:
get()['mem']['availablekb'];
get()['mem']['availablemb'];
get()['mem']['availablegb'];
Examples of how to get cached memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_cached_mem('kb');
get_cached_mem('mb');
get_cachede_mem('gb');
To return value in kb, mb or gb:
get()['mem']['cachedkb'];
get()['mem']['cachedmb'];
get()['mem']['cachedgb'];
Examples of how to get swap memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_swap_mem('kb');
get_swap_mem('mb');
get_swap_mem('gb');
To return value in kb, mb or gb:
get()['mem']['swapkb'];
get()['mem']['swapmb'];
get()['mem']['swapgb'];
Examples of how to get buffer memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_buffer_mem('kb');
get_buffer_mem('mb');
get_buffer_mem('gb');
To return value in kb, mb or gb:
get()['mem']['bufferkb'];
get()['mem']['buffermb'];
get()['mem']['buffergb'];
Examples of how to get Shmem memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_shmem_mem('kb');
get_shmem_mem('mb');
get_shmem_mem('gb');
To return value in kb, mb or gb:
get()['mem']['shmemkb'];
get()['mem']['shmemmb'];
get()['mem']['shmemgb'];
Examples of how to get SReclaimable memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_sreclaimable_mem('kb');
get_sreclaimable_mem('mb');
get_sreclaimable_mem('gb');
To return value in kb, mb or gb:
get()['mem']['sreclaimablekb'];
get()['mem']['sreclaimablemb'];
get()['mem']['sreclaimablegb'];
Examples of how to get SUnreclaim memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_sunreclaim_mem('kb');
get_sunreclaim_mem('mb');
get_sunreclaim_mem('gb');
To return value in kb, mb or gb:
get()['mem']['sunreclaimkb'];
get()['mem']['sunreclaimmb'];
get()['mem']['sunreclaimgb'];
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 Function.
Examples of how to get free memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_free_mem('kb');
get_free_mem('mb');
get_free_mem('gb');
To return value in kb, mb or gb:
get()['mem']['freekb'];
get()['mem']['freemb'];
get()['mem']['freegb'];
The Real Free Memory function gets the correct amount of free memory by using the Used Memory function.
Examples of how to get SUnreclaim memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_realfree_mem('kb');
get_realfree_mem('mb');
get_realfree_mem('gb');
To return value in kb, mb or gb:
get()['mem']['realfreekb'];
get()['mem']['realfreemb'];
get()['mem']['realfreegb'];
The formula Statsy uses to get an accurate used memory value is (MemTotal - MemFree - Buffers - Cached - SReclaimable - Shmem)
Examples of how to get used memory to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_used_mem('kb');
get_used_mem('mb');
get_used_mem('gb');
To return value in kb, mb or gb:
get()['mem']['usedkb'];
get()['mem']['usedmb'];
get()['mem']['usedgb'];
Examples of how to get used memory as a percent to display the value you will need to use echo
:
To return value as a percent:
get_used_mem2()
To return value as a percent:
get()['mem']['percent'];
Examples of how to get total disk to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_disk_total('kb');
get_disk_total('mb');
get_disk_total('gb');
To return value in kb, mb or gb:
get()['disk']['totalkb'];
get()['disk']['totalmb'];
get()['disk']['totalgb'];
Examples of how to get free disk to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_disk_free('kb');
get_disk_free('mb');
get_disk_free('gb');
To return value in kb, mb or gb:
get()['disk']['freekb'];
get()['disk']['freemb'];
get()['disk']['freegb'];
Examples of how to get used disk to display the value you will need to use echo
:
To return value in kb, mb or gb:
get_disk_used('kb');
get_disk_used('mb');
get_disk_used('gb');
To return value in kb, mb or gb:
get()['disk']['usedkb'];
get()['disk']['usedmb'];
get()['disk']['usedgb'];
Examples of how to get used disk as percent to display the value you will need to use echo
:
To return value as a percent:
get_disk_used2();
To return value as a percent:
get()['disk']['percent'];
Examples of how to get the CPU model to display the value you will need to use echo
:
get_cpuinfo('model');
get()['cpu']['model'];
Examples of how to get the amount of CPU cores to display the value you will need to use echo
:
get_cpuinfo('cores');
get()['cpu']['cores'];
Examples of how to get the CPU clock speed to display the value you will need to use echo
:
To return value in MHz:
get_cpuinfo('speed');
To return value in MHz:
get()['cpu']['clock'];
Examples of how to get the CPU cache to display the value you will need to use echo
:
get_cpuinfo('cache');
get()['cpu']['cache'];
Examples of how to get the CPU load as a percent to display the value you will need to use echo
:
To return value as percent:
get_cpu_load();
To return value as percent:
get()['cpu']['load'];
The uptime can be called in 4 ways. Examples of how to get the server uptime to display the value you will need to use echo
:
To return just the amount of days '2 Days':
get_uptime('days');
get()['uptime']['days'];
To return just the amount of days and hours '2 Days 3 hours':
get_uptime('hours');
get()['uptime']['hours'];
To return just the amount of days, hours and minutes '2 Days 3 hours 12 Mins':
get_uptime('mins');
get()['uptime']['mins'];
To return just the full uptime days, hours, minutes and seconds '2 Days 3 hours 12 Mins 11 Secs':
get_uptime('secs');
get()['uptime']['secs'];
Examples of how to get the server ip to display the value you will need to use echo
:
get_ip();
get()['ip']['ip'];
This function is used to round up numbers and is very simple to use:
round_up ( $value, $precision )
Example:
round_up ( 12.3852324323, 2 )
This function is used by all other function to convert the memory types:
convert($input, $converstion)
Example:
convert(187374563765, 'mb')
NOTE: The example below are for normal Statsy as for Statsy Auto you will config the JS file to tell Statsy where you want the data to show, however Statsy and Statsy Auto can use used together at the same time.
Below is a small sample of what using some functions and arrays might look like being called in a html/php file:
<div class="server-stats">
<p><?php echo get_ip(); ?></p>
<p><?php echo get_total_mem('gb'); ?></p>
<p><?php echo get_disk_total('gb'); ?></p>
<p><?php echo get()['mem']['used']; ?></p>
<p><?php echo get()['cpu']['cores']; ?></p>
</div>
Here are some fetures that will be coming soon to Statsy!
Smaller Things:
If you have any ideas for improvements please contact me here: [email protected]
Arthor: Tom Rouse (Tms157)