[Oracle Cloud] monitoring 機能でリソース監視->アラーム->メール通知を行う

# モニタリング・メトリックの参照

ここではBaseDBの参照を行う
これは「DBシステムの詳細」画面

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/c9a408a5-fe10-678b-1cb0-550947242727.png)

これの下部にいくと、

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/d339c51f-d65b-7bc6-0d8f-3862a7e314bb.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/16c1dee8-21d1-b81b-c911-ef8ea7e00ce2.png)

6つのメトリックが確認できる
次に、「データベース詳細」画面で見られるメトリックを確認

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/a8cce6a6-e8e0-3bf8-0ce9-32fae3ca6f55.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/251e741e-6bcd-c7ac-238e-b3f6486e134e.png)

# モニタリング・メトリックの参照（サービス・メトリック画面での参照）

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/8bbbee32-d9cd-996e-f74f-d1b2c45bfeb2.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/6110e4f8-7680-2f5c-2e10-0e0508f1ade4.png)

「メトリック・ネームスペース」を「oci_database_cluster」に設定すると下図の通り

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/575cfc32-a757-0462-0761-580aabc66ddd.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/53fdf645-d5ea-81ea-6b01-4ee59d5341e8.png)

# アラーム通知先の作成

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/c316e10f-770d-93d7-9afb-a0b8fcecff7f.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/ec8e0275-f289-608b-9c6a-d150d6b4a2fb.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/d5cb7694-a5a9-dd1f-d98d-64bd43c0a8f5.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/df64f821-b657-b19c-6a87-a8c4cc8e63f7.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/5780b118-7fea-042e-1a4d-a6ebb03b9a37.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/190c7c4a-3472-7374-7bde-2ee359d6d96c.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/618429e0-5221-ead9-968e-d7eff8f614fa.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/f2d4980e-469f-f0e2-ee55-60b109df4977.png)

確認のメールが送信されてくる

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/815716e4-1a6f-c0c3-20e4-aa18639bedf0.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/33babf7c-7e55-d5c1-947f-418c88bf9b69.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/75cdf960-8337-ff50-c73b-d2465ee1b445.png)

# アラーム定義の作成

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/9648bb5b-c9e3-de2b-09a3-fd2a1b82de7f.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/a1098460-44ef-97c1-0d19-476157a6142d.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/77986ed1-1b7b-0917-57bb-11cb2850cf0f.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/3a6ad96e-d8ba-34ad-896b-b84ef8c8893a.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/580d39a8-ba58-1160-23f3-9ae9938fe895.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/891687c7-ac36-eaef-f8d8-d74f5eee4272.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/9ecbadf3-2f88-faab-d156-5777ec862135.png)

# メール通知されることを確認

サーバ側で負荷をかけるための準備

```
[root@db-se-sjis ~]# yum repolist all | grep -i epel
ol7_developer_EPEL/x86_64       Oracle Linux 7Server Develop disabled
[root@db-se-sjis ~]#
[root@db-se-sjis ~]# yum-config-manager --enable ol7_developer_EPEL
Loaded plugins: versionlock
=========================== repo: ol7_developer_EPEL ===========================
[ol7_developer_EPEL]
async = True
bandwidth = 0
（---略---）
timeout = 30.0
ui_id = ol7_developer_EPEL/x86_64
ui_repoid_vars = releasever,
   basearch
username =

[root@db-se-sjis ~]#
[root@db-se-sjis ~]# yum repolist all | grep -i epel
ol7_developer_EPEL/x86_64       Oracle Linux 7Server Develop enabled:    48883+7
[root@db-se-sjis ~]#
[root@db-se-sjis ~]#
```

```
[root@db-se-sjis ~]#
[root@db-se-sjis ~]# yum -y install stress
Loaded plugins: ulninfo, versionlock
Excluding 358 updates due to versionlock (use "yum versionlock status" to show them)
Resolving Dependencies
--> Running transaction check
---> Package stress.x86_64 0:1.0.4-16.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package      Arch         Version               Repository                Size
================================================================================
Installing:
 stress       x86_64       1.0.4-16.el7          ol7_developer_EPEL        39 k

Transaction Summary
================================================================================
Install  1 Package

（---略---）

Installed:
  stress.x86_64 0:1.0.4-16.el7

Complete!
[root@db-se-sjis ~]#
[root@db-se-sjis ~]#
[root@db-se-sjis ~]#
```

```
[root@db-se-sjis ~]# stress -c 2 &
[1] 19527
[root@db-se-sjis ~]# stress: info: [19527] dispatching hogs: 2 cpu, 0 io, 0 vm, 0 hdd

[root@db-se-sjis ~]#
[root@db-se-sjis ~]# ps -ef | grep stress
root     19527 11382  0 08:37 pts/0    00:00:00 stress -c 2
root     19528 19527 52 08:37 pts/0    00:02:00 stress -c 2
root     19529 19527 52 08:37 pts/0    00:02:00 stress -c 2
root     22476 11382  0 08:40 pts/0    00:00:00 grep --color=auto stress
[root@db-se-sjis ~]#
```


```
[root@db-se-sjis ~]# top -c

↓↓↓↓↓↓

top - 08:41:29 up 2 days,  3:45,  1 user,  load average: 3.24, 2.48, 1.37
Tasks: 559 total,   3 running, 556 sleeping,   0 stopped,   0 zombie
%Cpu(s): 92.8 us,  7.1 sy,  0.0 ni,  0.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 15133024 total,  1447708 free, 11031828 used,  2653488 buff/cache
KiB Swap: 16777212 total, 14356216 free,  2420996 used.  2261512 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
19528 root      20   0    7320     96      0 R  85.6  0.0   2:33.89 stress -c 2
19529 root      20   0    7320     96      0 R  77.1  0.0   2:33.48 stress -c 2
22879 root      20   0 5647228  62136  27712 S  20.6  0.4   0:00.63 /u01/app/1+
```
コンソールをチェックすると、

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/21a0970e-8982-34cd-e9fb-9a41c678525c.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/c939ee1d-ec79-f982-7a6a-95eb600923f7.png)

メールを確認する

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/6e870b6a-8b9a-ab93-638a-cd381dcccfd7.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/8328f21d-ef85-43aa-e57f-ef0a4281b17c.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/8a7c60d5-ea56-24ed-5438-c52ceb556f57.png)

正しくメールが送信された

# 参照資料

https://oracle-japan.github.io/ocitutorials/intermediates/monitoring-resources/

https://speakerdeck.com/ocise/ocimonitaringuji-neng-gai-yao