sar -P all? (system admin reporter)

[vagrant@localhost ~]$ sar -q
-bash: sar: コマンドが見つかりません

あれ?インストールされてない?
インストールします。
[vagrant@localhost ~]$ sudo yum install -y sysstat
[vagrant@localhost ~]$ sudo vi /etc/cron.d/sysstat
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# 0 * * * * root /usr/lib64/sa/sa1 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A
え、デフォルトでOK?

[vagrant@localhost ~]$ sudo service sysstat start
Calling the system activity data collector (sadc)…

[vagrant@localhost ~]$ sar
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
[vagrant@localhost ~]$ sar -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
おお、なんか来た。

[vagrant@localhost ~]$ sar -P ALL
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
[vagrant@localhost ~]$ sar 1 1 -u -P ALL
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時43分53秒 CPU %user %nice %system %iowait %steal %idle
23時43分54秒 all 0.00 0.00 0.00 0.00 0.00 100.00
23時43分54秒 0 0.00 0.00 0.00 0.00 0.00 100.00

平均値: CPU %user %nice %system %iowait %steal %idle
平均値: all 0.00 0.00 0.00 0.00 0.00 100.00
平均値: 0 0.00 0.00 0.00 0.00 0.00 100.00

お、なんかCPU使用率が見えるっぽいですな。
[vagrant@localhost ~]$ sar 1 1 -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時44分46秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
23時44分47秒 0 227 0.04 0.16 0.09
平均値: 0 227 0.04 0.16 0.09

[vagrant@localhost ~]$ sar 1 1 -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時45分04秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
23時45分05秒 0 227 0.03 0.15 0.09
平均値: 0 227 0.03 0.15 0.09
すご。

Perform a simple test with PHPUnit

I already tried installing PHPUnit, so I will try simple samples.

message.php

class Message
{
	private $message;
	public function __construct(string $message){
		$this->message = $message;
	}

	public function get(){
		return $this->message;
	}
}

messageTest.php

require_once ('../vendor/autoload.php');
require_once (dirname(__FILE__) .'../src/message.php');

use PHPUnit\Framework\TestCase;

class MessageTest extends TestCase{
	public function testGet(){
		$message = new Message('hello, world');
		$this->assertEquals('hello, world', $message->get());
	}
}

command line
[vagrant@localhost app]$ vendor/bin/phpunit tests
PHP Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/local/app/tests/messageTest.php on line 3
PHP Fatal error: require_once(): Failed opening required ‘../vendor/autoload.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in /home/vagrant/local/app/tests/messageTest.php on line 3

fix

require_once ('./vendor/autoload.php');
require_once ('./src/message.php');

use PHPUnit\Framework\TestCase;

class MessageTest extends TestCase{
	public function testGet(){
		$message = new Message('hello, world');
		$this->assertEquals('hello, world', $message->get());
	}
}

[vagrant@localhost app]$ vendor/bin/phpunit tests
PHPUnit 7.1.4 by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: 35 ms, Memory: 4.00MB

OK (1 test, 1 assertion)

ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh^^

What is PHPUnit

Unit test is a test to check the operation in units such as classes and functions that are the constituent elements of the program. By using PHPUnit, it is possible to create a unit test procedure as a PHP program and execute it as a batch process from a command line or the like.

Speaking of PHP program testing, it is common to manually check the screen transition by manipulating the browser manually, enter values in the form and check the result with the eyes. However, it is quite tedious task to open the page many times during development, enter the test data in the same way, and manually do all the results correctly.

The advantage of using PHPUnit that can automate and repetitively execute troublesome test procedures manually.

Since you can run the test as many times as you like with a single command, you can improve test efficiency and eliminate manual errors as well. In addition, the created test program replaces the specifications, confirming that existing process works correctly in the process of continually improving the program, so-called “degrate” it can also be used to prevent. It can lead to maintenance and improvement of program quality.

class Hello
{
	public function getMessage()
	{
		return "Hello world";
	}
}

It assumes that composer is already installed.
[vagrant@localhost app]$ php composer.phar require phpunit/phpunit:7.1.4
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 29 installs, 0 updates, 0 removals
– Installing sebastian/version (2.0.1): Loading from cache
– Installing sebastian/resource-operations (1.0.0): Loading from cache
– Installing sebastian/recursion-context (3.0.0): Loading from cache
– Installing sebastian/object-reflector (1.1.1): Loading from cache
– Installing sebastian/object-enumerator (3.0.3): Loading from cache
– Installing sebastian/global-state (2.0.0): Loading from cache
– Installing sebastian/exporter (3.1.0): Loading from cache
– Installing sebastian/environment (3.1.0): Loading from cache
– Installing sebastian/diff (3.0.1): Loading from cache
– Installing sebastian/comparator (3.0.2): Loading from cache
– Installing doctrine/instantiator (1.1.0): Loading from cache
– Installing phpunit/php-text-template (1.2.1): Loading from cache
– Installing phpunit/phpunit-mock-objects (6.1.2): Downloading (100%)
– Installing phpunit/php-timer (2.0.0): Loading from cache
– Installing phpunit/php-file-iterator (1.4.5): Downloading (100%)
– Installing theseer/tokenizer (1.1.0): Loading from cache
– Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
– Installing phpunit/php-token-stream (3.0.1): Downloading (100%)
– Installing phpunit/php-code-coverage (6.0.5): Downloading (100%)
– Installing symfony/polyfill-ctype (v1.10.0): Loading from cache
– Installing webmozart/assert (1.4.0): Downloading (100%)
– Installing phpdocumentor/reflection-common (1.0.1): Loading from cache
– Installing phpdocumentor/type-resolver (0.4.0): Loading from cache
– Installing phpdocumentor/reflection-docblock (4.3.0): Loading from cache
– Installing phpspec/prophecy (1.8.0): Loading from cache
– Installing phar-io/version (1.0.1): Downloading (100%)
– Installing phar-io/manifest (1.0.1): Downloading (100%)
– Installing myclabs/deep-copy (1.8.1): Loading from cache
– Installing phpunit/phpunit (7.1.4): Downloading (100%)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating autoload files

[vagrant@localhost app]$ vendor/bin/phpunit –version
PHPUnit 7.1.4 by Sebastian Bergmann and contributors.

What!?

Nest step, the path to use the phpunit command.