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
すご。

vmstat

“vmstat” is a command to display statistics of virtual memory, CPU, and disk I/O.

By default, the average value from startup(result) is displayed. You can display the value in real time by specifying the update interval like “vmstat 1”.

[vagrant@localhost ~]$ vmstat
procs ———–memory———- —swap– —–io—- –system– —–cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 1 584880 46328 36088 82136 20 21 94 28 46 97 0 0 97 3 0

procs -> process
 r -> 実行中と実行待ち中のプロセス数
 b -> 割り込み不可能なスリープ状態にあるプロセス数
memory -> memory
 swpd -> 仕様中の仮想メモリの量
 free -> 空きメモリの量
 buff -> バッファとして使用しているメモリの量
 cache -> キャッシュに使用している量
swap -> swap
 si -> ディスクからスワップインしているメモリの量
 so -> スワップアウトしている量
io -> input out
 bi -> HDDのようなブロック型デバイスから受けっとたブロック数
 bo -> ブロック型デバイスに送ったブロック数
system -> system
 in -> 1秒あたりの割り込み回数
 cs -> コンテクストスイッチの回数
CPU -> CPU
 us -> カーネルコード以外の実行に使用した時間
 sy -> カーネルコードの実行に使用した時間(システム時間)
 id -> 空転していたアイドル時間
 wa -> I/O待ち時間
 st -> 仮想マシンから盗まれた時間

メモリの単位ってなんだ?kバイト?

mailgun

Transactional Email API Service for Developersと書いてある。
APIベースのメール配信サービスとのこと。
Mailgunでは、毎月10,000通までのメール送信が無料で使えるとのこと。
Google Cloud PlatformのCompute Engineのサードパーティメールサービスとしても提供。

DNSを設定して、Laravelに導入するのね。
うむ、これはテストしないとあかんやつやね。

Laravelでindexを作成、追加する方法

Schma::create('books', function(Blueprint $table){
	$table->increments('id');
	$table->string('title')->index();
	$table->string('isbn')->unique();
	$table->integer('price');
	$table->integer('author_id');
	$table->timestamps();
});


Schema::table('books', function(Blueprint $table){
	$table->index('title');
});

Schema::table('author_book', function(Blueprint $table){
	$table->index(['author_id', 'book_id']);
});

$table->dropIndex('books_title_index');

mysql: group by

mysql> select * from staff;
+——+——–+——–+
| id | name | deptid |
+——+——–+——–+
| 1 | yamada | 1 |
| 2 | honda | 4 |
| 3 | kudou | 6 |
| 4 | nishi | 1 |
| 5 | tagawa | 3 |
+——+——–+——–+
5 rows in set (0.00 sec)

mysql> select deptid, sum(id) from staff grop by deptid;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘by deptid’ at line 1
mysql> select deptid, sum(id) from staff group by deptid;
+——–+———+
| deptid | sum(id) |
+——–+———+
| 1 | 5 |
| 3 | 5 |
| 4 | 2 |
| 6 | 3 |
+——–+———+
4 rows in set (0.02 sec)

なるほど、あるカラムの値に重複がある場合に、group byでまとめて計算できるのね。

なんとなくわかってきた。

mysql select count: レコード数のカウント

mysql> select count(*) from kawasaki;
+———-+
| count(*) |
+———-+
| 69 |
+———-+
1 row in set (0.00 sec)

mysql> select * from staff;
+——+——–+——–+
| id | name | deptid |
+——+——–+——–+
| 1 | yamada | 1 |
| 2 | honda | 4 |
| 3 | kudou | 6 |
| 4 | nishi | 1 |
| 5 | tagawa | 3 |
+——+——–+——–+
5 rows in set (0.00 sec)

mysql> select count(deptid) from staff;
+—————+
| count(deptid) |
+—————+
| 5 |
+—————+
1 row in set (0.00 sec)

データ量なので、重複したデータも+1とカウントされるんですね。

mysql show index;

show indexは、indexが貼られているか確認

mysql> show index;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1

あれ、、

mysql> show index from staff;
Empty set (0.00 sec)

あら、fromが必要でしたね。