0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OCI Compute のカスタムログ設定 - Linux/Windows

0
Last updated at Posted at 2026-03-25

001samune.png

はじめに

本記事では OCI Compute のカスタムログ設定を実施し、実際にログ出力されるまでをゴールにまとめていきます。
Linux / Windows それぞれで実施し、せっかくなのでミドルウェアをインストールして対応していきます。


概要

OCI Compute 内のログを OCI Logging に出力するには、インスタンスに Oracle Cloud Agent をインストールし、Custom Logs Monitoring Plugin を有効化する必要があります。

加えて、OCI Logging への通信とインスタンスへの権限を付与する必要があります。

OCI Logging 側では エージェント構成 を作成する必要がありますが、そちらは実際の検証時に触れていきます。


使用方法(デモ)

検証構成

検証構成図は以下の通りです。
なお、以下リソースは作成済みで進めていきます。

  • NWリソース
  • OCI Bastion
  • OCI Compute インスタンス
  • IAM ポリシー

architecture.drawio.png

検証では、以下実施していきます。

  • OCI Logging 作成
  • エージェント構成作成
  • 環境コードは以下 GitHub にあげてますので、よかったら覗いてみてください

前提条件確認

以下設定項目は、後述するエージェント構成に加えて設定する必要があります。

  • IAM ポリシー
  • Oracle Cloud Agent の Custom Logs Monitoring Plugin の有効化
  • OCI Logging への疎通性
IAM ポリシー

動的グループ ( Compute ) に、use log-content 権限を付与する必要があります。
本検証では以下のポリシーを作成しています。

allow dynamic-group Compute_Dynamic_Group_Oracle, Compute_Dynamic_Group_Windows to use log-content in compartment oci-compute-custom-logs
  • 権限とは関係ないですが、インスタンスごとに動的グループを分けています
  • というのも、後述するエージェント構成作成時に、関連付ける動的グループを指定する必要があり、インスタンスごとに設定項目が異なるので分けています
Oracle Cloud Agent の Custom Logs Monitoring Plugin の有効化

OS に関係なく、Custom Logs Monitoring Plugin が有効化されており、Running 状態である必要があります。
図1.png

OCI Logging への疎通性

インスタンス内で稼働している Custom Logs Monitoring Plugin からの ログ出力 及び エージェント構成の取得 をするためには、プラグインから Oracle Services Network に所属する OCI Logging への疎通性が必要となります。
本構成はインターネットに抜けられない構成となっているため、以下の通り、インスタンスが所属するプライベートネットワークのルートテーブルに Service Gateway をネクストホップとするルートを設定しています。
図2.png

余談ですが、インスタンスの Network Security GroupEgress は、Oracle Services Network CIDR 宛の TCP/443 のみ許可しています。
※ windows と書いてありますが、Linuxも同様にしています
図3.png

エージェント構成作成

Linux 編

OCI コンソール左上のハンバーガーマークをクリックし、Observability & ManagementAgent Configurations をクリックします。
図4.png

  • Agent Configurations が2つあります
  • 作成したエージェント構成自体は同期されていますが、それぞれ設定できる内容が異なるので注意

図2.png

Create agent config をクリックします。
図5.png

幾つか設定項目を入力していきます。
名前説明文 は必須なので適当な値を入力します。
コンパートメント は作成するエージェント構成を所属させる場所を選択します。
本構成では、特定のコンパートメントを対象に権限を付与しているので、そのコンパートメントを指定しています。
図6.png

Host groups では、エージェント構成を関連付ける動的グループを指定します。
Enable domain select はオフにし、対象と動的グループを指定します。
オンにした場合は、動的グループの選択時に Identity Domains も選択する必要があるだけで特に変わりはありません。
図7.png

  • 上図の Warning に記載されている Create を押すと、指定した動的グループ及びコンパートメントを対象とした IAM ポリシーが自動で作成されます
  • 今回は事前に作成しているので押していません

Agent configuration では、出力させたいログを指定します。
Input type では、現状 Windows event log 及び Log path を指定することができます。
Windows Server はどちらも利用可能で、LinuxLog path のみ利用可能です。
image.png

  • Windows ServerLog path を利用する際は、以下リンクの通り指定方法に注意点があります

今回は以下の通りとしています。

Input name は、OCI Logging のサービスページでログを確認するときのフィールド名になります。なので名前は適当で大丈夫です。

File paths は、実際に取得したいログファイルのパスを指定します。今回は /var/log/nginx 配下のログ全てを対象としています。

Parser は対象のログを OCI Logging に出力する際のフィルターみたいなものです。幾つか Oracle にて用意されていますが、今回は使用しないため NONE としています。

Message key は、ParserNONE にした場合のみ指定できるオプションです。OCI Logging に出力されるログは、実際のログデータに加え、幾つかフィールドが付与された json で出力されます。
その json データ内に記載される ログデータのキー名を定義する項目です。
オプションなので省略可能ですが、省略した場合は message となります。

図8.png

Select log destination は、出力先の Log Group 及び Custom Logs を指定します。
Logging agent operational metrics は、Custom Logs Monitoring Plugin のカスタムメトリクスを出力させたい場合に有効化します。
今回は無効化します。
図9.png

  • カスタムメトリクスを出力させる場合は、別途 IAM ポリシーを付与する必要がある点に注意
Windows Server 編

Linux 編 と同様の手順で作成します。
違いのみ以下に記載します。
ポイントは Agent configuration のところで、本構成では セキュリティイベントログを出力させます。
image.png
image.png
image.png

  • Input typeWindows event log の場合は、Parser の設定がありません

動作確認

Linux 編

対象インスタンスに入って確認してみましょう。
念の為、関連する各種サービスを確認します。

始めに、実際にログ出力をしてくれるサービスの状態を確認します。
問題なさそうですね。

[root@oracle-instance ~]# systemctl status unified-monitoring-agent
● unified-monitoring-agent.service - unified-monitoring-agent: Fluentd based data collector for Oracle Cloud Infrastructure
     Loaded: loaded (/usr/lib/systemd/system/unified-monitoring-agent.service; enabled; preset: disabled)
     Active: active (running) since Fri 2026-03-20 18:31:02 JST; 17min ago
       Docs: https://docs.cloud.oracle.com/
   Main PID: 8729 (fluentd)
      Tasks: 6 (limit: 46959)
     Memory: 57.5M (max: 5.0G available: 4.9G peak: 57.7M)
        CPU: 968ms
     CGroup: /system.slice/unified-monitoring-agent.service
             ├─8729 /opt/unified-monitoring-agent/embedded/bin/ruby /opt/unified-monitoring-agent/embedded/bin/fluentd --log /var/log/unified-monitoring-agent/unified-monitoring-agent.log --log-rotate-size 1048576 --log-rotate-age 10
             └─8743 /opt/unified-monitoring-agent/embedded/bin/ruby -Eascii-8bit:ascii-8bit /opt/unified-monitoring-agent/embedded/bin/fluentd --log /var/log/unified-monitoring-agent/unified-monitoring-agent.log --log-rotate-size 1048576 -->

 3月 20 18:31:02 oracle-instance systemd[1]: Started unified-monitoring-agent: Fluentd based data collector for Oracle Cloud Infrastructure.

続いて、エージェント構成をダウンロードしてくれるサービスの状態を確認します。
こちらは常時起動ではないため起動はしていません。

[root@oracle-instance ~]# systemctl status unified-monitoring-agent_config_downloader
○ unified-monitoring-agent_config_downloader.service - unified-monitoring-agent Fluentd configuration downloader.
     Loaded: loaded (/usr/lib/systemd/system/unified-monitoring-agent_config_downloader.service; enabled; preset: disabled)
     Active: inactive (dead) since Fri 2026-03-20 18:49:34 JST; 20s ago
TriggeredBy: ● unified-monitoring-agent_config_downloader.timer
    Process: 8938 ExecStart=/opt/unified-monitoring-agent/embedded/bin/ruby /opt/unified-monitoring-agent/embedded/bin/fluent_config_updater.rb -c /etc/unified-monitoring-agent/conf.d/ -b 10 (code=exited, status=0/SUCCESS)
   Main PID: 8938 (code=exited, status=0/SUCCESS)
        CPU: 1.802s

 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307296 #8938]  INFO -- : copy from /etc/unified-monitoring-agenttmp/fluentd.conf to /etc/unified-monitoring-agent/conf.d/fluentd_config/fluentd.conf
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307388 #8938]  INFO -- : The os is Linux, config updater does nothing, systemd will reload fluentd config later
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307487 #8938]  INFO -- : clean up files under tmp folder /etc/unified-monitoring-agenttmp
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307528 #8938]  INFO -- : Finish cleaning up backup under /etc/unified-monitoring-agent/conf.d
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307540 #8938]  INFO -- : finished cleaning up tmp config files /etc/unified-monitoring-agenttmp/fluentd.conf
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307565 #8938]  INFO -- : Finished running watchdog
 3月 20 18:49:34 oracle-instance ruby[8938]: I, [2026-03-20T18:49:34.307605 #8938]  INFO -- : Writing metadata to : /etc/unified-monitoring-agent/unified_monitoring.json
 3月 20 18:49:34 oracle-instance systemd[1]: unified-monitoring-agent_config_downloader.service: Deactivated successfully.
 3月 20 18:49:34 oracle-instance systemd[1]: Finished unified-monitoring-agent Fluentd configuration downloader..
 3月 20 18:49:34 oracle-instance systemd[1]: unified-monitoring-agent_config_downloader.service: Consumed 1.802s CPU time.

続いて、unified-monitoring-agent_config_downloader.service をトリガーするタイマー・ユニットの状態を確認します。
こちらも問題なさそうですね。

[root@oracle-instance ~]# systemctl status unified-monitoring-agent_config_downloader.timer 
● unified-monitoring-agent_config_downloader.timer - Run unified-monitoring-agent configuration automatic updater.
     Loaded: loaded (/usr/lib/systemd/system/unified-monitoring-agent_config_downloader.timer; enabled; preset: disabled)
     Active: active (waiting) since Fri 2026-03-20 18:31:02 JST; 21min ago
      Until: Fri 2026-03-20 18:31:02 JST; 21min ago
    Trigger: Fri 2026-03-20 19:10:01 JST; 17min left
   Triggers: ● unified-monitoring-agent_config_downloader.service

 3月 20 18:31:02 oracle-instance systemd[1]: Started Run unified-monitoring-agent configuration automatic updater..

続いて、エージェント構成の変更を検知した際に unified-monitoring-agent.service をリロードをトリガーするパス・ユニットの状態を確認します。
こちらも問題なさそうですね。

[root@oracle-instance ~]# systemctl status unified-monitoring-agent_restarter.path 
● unified-monitoring-agent_restarter.path - "Monitor the /etc/unified-monitoring-agent/conf.d/ directory for changes"
     Loaded: loaded (/usr/lib/systemd/system/unified-monitoring-agent_restarter.path; enabled; preset: disabled)
     Active: active (waiting) since Fri 2026-03-20 17:27:33 JST; 1h 29min ago
      Until: Fri 2026-03-20 17:27:33 JST; 1h 29min ago
   Triggers: ● unified-monitoring-agent_restarter.service

 3月 20 17:27:33 oracle-instance systemd[1]: Started "Monitor the /etc/unified-monitoring-agent/conf.d/ directory for changes".

続いて実際にエージェント構成がダウンロードされているか確認します。
ファイルは /etc/unified-monitoring-agent/conf.d/fluentd_config 配下にあります。
中身は割愛しますが、正常にダウンロードされていました。

[root@oracle-instance fluentd_config]# pwd
/etc/unified-monitoring-agent/conf.d/fluentd_config
[root@oracle-instance fluentd_config]# ll
合計 4
-rw-r--r-- 1 root root 2556  3月 20 18:49 fluentd.conf
  • コンソール側で変更があると自動的にエージェント構成ファイルはダウンロードされますが、即時ダウンロードをしたい場合は、unified-monitoring-agent_config_downloader.service を再起動してください

最後に、実際に unified-monitoring-agent.service がログを出力しているか確認をします。
実行ログは /var/log/unified-monitoring-agent 配下の unified-monitoring-agent.log ファイルです。
実はここで詰まったのですが、unified-monitoring-agent.service が起動していて、設定ファイルをダウンロードした状態から、出力対象ログファイルに変更が加わったタイミングで OCI Logging にプッシュされます。 そのため、起動前に対象ログファイルにログが記録されていても、対象ログファイルの変更を検知しないと、そのログは出力されません。

なので、以下コマンドで /var/log/nginx/access.log にログを記録します。

[opc@oracle-instance ~]$ curl localhost

そのタイミングで 以下コマンドにより実行ログを確認します。
以下色付けしているように、プッシュされた旨のログがあればOKです。

[root@oracle-instance unified-monitoring-agent]# tail -f unified-monitoring-agent.log 
~~~ 省略 ~~~
+ 2026-03-20 19:14:01 +0900 [info]: #0 Payload size : 180
+ 2026-03-20 19:14:01 +0900 [info]: #0 put_logs request with log_object_id ocid1.log.oc1.ap-tokyo-1.hogehogehogehoge
+ 2026-03-20 19:14:01 +0900 [info]: #0 log_batch_subject /var/log/nginx/access.log, hostname oracle-instance, default_log_entry_time 2026-03-20T10:10:51.649Z, batch_size 1, batch_type com.oraclecloud.logging.custom.nginxlog
+ 2026-03-20 19:14:01 +0900 [info]: #0 response 200 id: A4D9E06C6F6A43E7960C865BDFA5AB3D/BBF1069E3B4BC26BE91DBD694E52543A/063F27FB2153A23205559BFE841CEE0F time taken: 105.648961ms
  • curl を実行してから約2分くらいでプッシュしました

その後、ログ出力先として指定した Custom Logs を確認すると、ログが出力されているのが確認できます。
image.png

  • ちなみに エージェント構成作成 時に指定した Input nameMessage key はそれぞれ以下図の赤枠部分に対応しています

図10.png

Windows Server 編

Linux 編 と同様にサービスの確認からしてみましょう。

コマンドプロンプトに以下コマンドを実行します。
起動していないですね。

C:\Windows\System32>sc query unified-monitoring-agent

SERVICE_NAME: unified-monitoring-agent
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x7d0

サーバーマネージャーからサービスを見てみると、どうやら自動起動になっていないようです。
image.png

なので以下コマンドで起動します。
と思ったら、エラーになりました。

C:\Windows\System32>sc start unified-monitoring-agent
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

数分時間をおいて再度確認すると、起動していました。
依存関係で起動が遅れただけかもしれません。

C:\Windows\System32>sc query unified-monitoring-agent

SERVICE_NAME: unified-monitoring-agent
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

その後、設定ファイルが格納される C:\oracle_unified_agent\conf.d\fluentd_config 配下を確認すると、unified-monitoring-agent.conf がダウンロードされていました。
image.png

C:\oracle_unified_agent 配下にある 実行ログファイル (unified-monitoring-agent-0.log) を見ると、Linuxと同様にログ出力されている旨のログが確認できました。
image.png

その後、ログ出力先として指定した Custom Logs を確認すると、ログが出力されているのが確認できます。
image.png

図11.png


おわりに

本記事では OCI Compute のカスタムログ設定についてまとめました。
ログ監視は基本的に実装する内容ですので、是非本記事を参考にしてみてください。


🌟この記事が誰かの役に立てば幸いです!
また、ご質問やフィードバックもお待ちしています。


参考資料

リファレンス

ブログ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?