What is load average?

Load average is an indicator that represents the load status of the entire system. It is represented by “the number of processes waiting for “the number of processes waiting for execution per unit time and disk I/O waiting for one CPU”.

If yuo want to increase the throughput of the system, the goal is to reduce the load average.

The Linux kernel has a process descriptor for each process, and manages the state of the process in its state member. The state of the process is distinguished as follows.

TASK_RUNNING: Possible state. It can be run if the CPU is free.
TASK_UNINTERRUPTABLE: Uninterruptible wait state. Those that return in a short time, such as waiting for disk I/O.
TASK_INTERRUPTABLE: An interruptible wait state. The return time can not be predicted, such as waiting for user input.
TASK_STOPPED: Execution has been suspended. It will not be scheduled until it is resumed.
TASK_ZOMBIE: Zombie process. The child process has not exited and has not been waited on by the parent process.

ロードアベレージを確認するコマンド
[vagrant@localhost ~]$ uptime
08:42:40 up 1 day, 16:57, 1 user, load average: 0.00, 0.00, 0.00
[vagrant@localhost ~]$ uptime
08:43:36 up 1 day, 16:58, 2 users, load average: 0.13, 0.03, 0.01

[vagrant@localhost ~]$ w
08:44:33 up 1 day, 16:59, 2 users, load average: 0.05, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
vagrant pts/1 192.168.35.1 08:43 1:08 0.42s 0.24s php -S 192.168.
vagrant pts/0 192.168.35.1 23:24 1.00s 7.38s 0.01s w

[vagrant@localhost ~]$ top
top – 08:45:38 up 1 day, 17:00, 2 users, load average: 0.02, 0.02, 0.00
Mem: 501796k total, 493992k used, 7804k free, 6144k buffers
Swap: 1015804k total, 419948k used, 595856k free, 30000k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6854 vagrant 20 0 100m 700 468 S 51.0 0.1 0:00.34 sshd
9368 vagrant 20 0 15020 1308 1008 R 51.0 0.3 0:00.28 top
1 root 20 0 19232 192 60 S 0.0 0.0 0:00.90 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:01.62 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.63 watchdog/0
7 root 20 0 0 0 0 S 0.0 0.0 3:13.04 events/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events/0
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_long/0
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_power_ef
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
16 root 20 0 0 0 0 S 0.0 0.0 0:01.11 sync_supers
17 root 20 0 0 0 0 S 0.0 0.0 0:00.02 bdi-default

おおおおおおおおおお、なんかわかった気になってきた。すげえ。

Take a look at the MySQL binary log

The binary log has not been output yet.
[vagrant@localhost ~]$ ls /var/lib/mysql/
addb count equity ibdata1 mysql.sock zeus
auto.cnf demo ib_logfile0 laravel57 performance_schema
click dev ib_logfile1 mysql test

Add log-bin and configure to output binary log.
log-binを足します。
[vagrant@localhost ~]$ sudo vi /etc/my.cnf
[vagrant@localhost ~]$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

character_set_server=utf8
default-storage-engine=InnoDB
innodb_file_per_table

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql

# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so

# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1

# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
log-bin

[vagrant@localhost ~]$ sudo service mysqld restart
mysqld を停止中: [ OK ]
mysqld を起動中: [ OK ]
[vagrant@localhost ~]$ ls /var/lib/mysql/
addb count equity ibdata1 mysql.sock zeus
auto.cnf demo ib_logfile0 laravel57 performance_schema
click dev ib_logfile1 mysql test

あれ、、、、、、、、、、、、 bin-log出てないやんけ。おかしいな。。

mysql> create database sample;
Query OK, 1 row affected (0.02 sec)

mysql> quit
Bye
[vagrant@localhost ~]$ ls /var/lib/mysql/

log-binの追加する位置が悪いか。。

eval – catch exceptions, execute string dynamically

You can use the eval function to catch exceptions in the case of block syntax. For string syntax, you can execute strings dynamically.

eval 

eval $string;

The one called eval string is the syntax to execute the string dynamically. Passing a string to eval will execute that string as a Perl executable statement. Errors that occur at runtime are stored in $@.

As an example, you can define a subroutine at runtime. The following example defines an eval string and a typeglob at runtime for a subroutine that return 5 foo: Temporarily allow symbolic references with no string refs.

#!/usr/bin/perl --

{
	no strict = 'refs';
	*{"foo"} = eval "sub {return 5}";
}
print "Content-type:text/html\n\n";
print $foo;

Internal Server Error

あれ?? 全然違う?? 

Carbonを使ってみよう

require "vendor/autoload.php";

use Carbon\Carbon;

$dt = new Carbon();
echo $dt . "<br>";

$dt = Carbon::now();
echo $dt . "<br>";

$dt = new Carbon("2019-05-09");
echo $dt . "<br>";

$dt = Carbon::today();
echo $dt . "<br>";

$dt = Carbon::tomorrow();
echo $dt . "<br>";

$dt = Carbon::yesterday();
echo $dt . "<br>";

$dt = Carbon::parse("2019-05-07 10:30:30");
echo $dt . "<br>";

2019-05-07 20:54:17
2019-05-07 20:54:17
2019-05-09 00:00:00
2019-05-07 00:00:00
2019-05-08 00:00:00
2019-05-06 00:00:00
2019-05-07 10:30:30

なるほどー、確かに使いやすいかもね~

Carbon and php

Carbon is a package that extends PHP’s DataTime class, making it possible to manipulate dates and times more intuitively and more simply.

なるほど、道理でLaravelに使われている訳だ。

composerを入れます。

[vagrant@localhost test]$ curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.8.5) successfully installed to: /home/vagrant/local/app/test/composer.phar
Use it: php composer.phar

続いて、carbonを入れます。
[vagrant@localhost test]$ php composer.phar require nesbot/carbon
No composer.json in current directory, do you want to use the one at /home/vagrant/local/app? [Y,n]? y
Using version ^2.17 for nesbot/carbon
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
– Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
– Installing symfony/contracts (v1.0.2): Loading from cache
– Installing symfony/translation (v4.2.8): Downloading (100%)
– Installing nesbot/carbon (2.17.1): Downloading (100%)
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
symfony/translation suggests installing psr/log-implementation (To use logging capability in translator)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files


Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.

ん、間違えたか。jsonの使うところが違うな。

やり直します。
[vagrant@localhost test]$ php composer.phar require nesbot/carbon
No composer.json in current directory, do you want to use the one at /home/vagrant/local/app? [Y,n]? n
Using version ^2.17 for nesbot/carbon
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
– Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
– Installing symfony/contracts (v1.0.2): Loading from cache
– Installing symfony/translation (v4.2.8): Loading from cache
– Installing nesbot/carbon (2.17.1): Loading from cache
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
symfony/translation suggests installing psr/log-implementation (To use logging capability in translator)
Writing lock file
Generating autoload files

OK、上手くいきましたね^^
では早速使っていきましょう~

CloudWatchを使っていこう

まずコンソールにログインします。

ダッシュボードに入ります。

なるほど、確かに魅力あるね。

メトリクスを押下します。

ほほう、インフラエンジニアが好きそうや。

ログも見れますよ、と。なるほどねー

CloudWatch

CloudWatch is a monitoring service for AWS resources and applications running on AWS. You can collect and monitor metrics and log files of various AWS services and set alarms. When you start the corresponding AWS service, data points are regularly sent to CloudWatch, so you can view and analyze the metrics on a graphical screen without being particularly aware. With custom metrics, you can use graphical graphs for metrics collected from your own application. Using the alarm function, not only notification using SNS, addition of EC2 instance by Auto Scaling, or recovery of EC2 instance is also possible.

Data points, metrics
When you start a supported AWS service, data points (monitoring data) are sent to CloudWatch stores data points in metrics.
Metrics can be thought of as monitored variables, and data points can be thought of as the values of variables over time. Data points are not necessarily related to AWS services. It may be the data sent by the script created by the user. In other words, the metric may be the CPU utilization of an EC2 instance, or it may be the response speed of the application or room temperature.
Metrics are identified by name, namespace, and one or more dimensions. Metrics are stored for two weeks.

Name space
Namespaces store metrics. The metric name [CPUUtilization] is used in EC2 and RDS. The namespace [AWS/EC2] or [AWS/RDS] is used as one element to identify metrics.

Dimension
Dimensions are categories of metrics. Statistical monitoring is possible using dimensions. Use the dimension [InstanceId] to check the metrics of an instance. You can use the dimension [AutoScalingGroupName] to monitor data for each autoscaling group.

EC2 Metrics Dimension

AutoScalingGroupName
ImageId
InstanceId
InstanceType

では早速触っていきましょう。

PHP Excel download

$template_path = "entrysheet.xlsm";
$filename = "職務経歴書.xlsm";
$extension = pathinfo($template_path)['extension'];
$file_size = filesize($template_path);

header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Length: {$file_size}");
header("Content-Disposition: attachment; filename={$filename}");
readfile($template_path);

openxmlformatsを使うのかー
なるほどねー これでトップ側はOKかな。

Phone number

The size attribute specifies the width of the input field in characters.
The width of 17 characters is specified.

<p>
								電話番号(必須)<br>
								<input class="long-text" value="080-1234-5678" type="tel" size="17" required>
							</p>

うん、よい感じ。