, (*1)
This is a simple script for retrieving information
about the host system that the code (typically web
application) is running on, so that it can be
presented on a web page, and/or graphed over time.
Or perhaps it can be used to detect situations
where the system is running low on resources., (*2)
It is made as part of an online course in web
development. So I was forced to make this available
on github and packagist. Maybe it can be useful
for someone., (*3)
Note that it is intended for Linux host systems
and no effort has been made to make it work for
other host operating systems., (*4)
HOW TO USE WITH ANAX-MVC, (*5)
Clone the Anax-MVC git repository using, (*6)
$ git clone https://github.com/mosbth/Anax-MVC.git Anax-MVC.git, (*7)
Then add the following line to the "require" property of
Anax-MVC.git/composer.json:, (*8)
"anpk12/sysinfo": "dev-master", (*9)
The part after the colon is the version requirement
and can optionally be changed to a fixed version such
as "1.0.0"., (*10)
Validate your composer.json file:, (*11)
$ composer validate, (*12)
If it succeeds, update:, (*13)
$ composer update, (*14)
Now, to see if it works, you need to integrate
anpk12\sysinfo into a route. We will take the
easiest route possible to create a working demo., (*15)
Make a copy of webroot/hello.php, call it
webroot/hello_sysinfo.php . After the line that
starts with "require", create an instance of
Anpk12\Sysinfo\Snapshot:, (*16)
$sysinfo = new Anpk12\Sysinfo\Snapshot();, (*17)
This will create a snapshot of the current system
status, which we can then use to generate html,
graphs/images or database entries etc., (*18)
The Snapshot class provides easy access to the various
types of system information it collects through
accessors., (*19)
But it can also generate a complete html report
using all the information. This is done using the
htmlReport() member function. Add the following
line to hello_sysinfo.php, just after the creation
of the Snapshot instance:, (*20)
$sysReport = $sysinfo->htmlReport(false), (*21)
The boolean argument controls whether or not to
create a short summary (true) or a full report (false)., (*22)
The variable $sysReport now holds a string of html markup,
which we can tell Anax-MVC to render. Simply change
the title and main variables of the theme:, (*23)
// Prepare the page content
$app->theme->setVariable('title', "Hello World Sysinfo")
->setVariable('main', $sysreport);, (*24)
Done! Try accessing
Anax-MVC.git/webroot/hello_sysinfo.php with a
web browser. You should see current memory usage etc., (*25)
In order to access the system information directly
instead of generating html, use the Snapshot member
functions meminfo(), memTotal(), memAvailable() and
loadavg() ., (*26)