File
ファイル監視
📚 情報ソース
このドキュメントは以下の情報源を基に作成されています:
主要ソース
補足ソース
- ログ監視のベストプラクティス: パターンマッチングと正規表現
- 実運用環境の設定例: セキュリティログとアプリケーションログの監視パターン
📚 公式ドキュメント: ファイル監視 (com.instana.plugin.filemonitoring)
ファイルシステムの変更を監視し、特定のイベントを検出します。ログファイル内の特定のパターン(エラー、警告など)を検出してイベントを生成できます。
基本設定
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 300 # 秒単位
- interval_2: 600
- interval_3: 1800
- interval_4: 3600
- path: '/var/log/application.log'
conditions:
- 'ERROR'
- 'CRITICAL'
name: 'Application Error Detection'
interval: 'interval_1'
severity: 'high'
checksum_file_size: 10 # チェックサムを計算するファイルサイズ上限(MB)
|
設定項目の詳細
| 項目 |
説明 |
デフォルト値 |
推奨値 |
取得方法 |
enabled |
センサーの有効化 |
false |
true |
- |
path |
監視対象ファイルパス |
- |
絶対パス |
監視したいファイルの絶対パス |
conditions |
検出条件(文字列パターン) |
- |
エラーキーワード |
ログ内で検出したいキーワード |
name |
イベント名 |
- |
識別可能な名前 |
任意の識別名 |
interval |
チェック間隔 |
- |
interval_1 |
event_intervalsで定義した間隔名 |
severity |
重要度 |
medium |
high/critical |
low/medium/high/critical |
checksum_file_size |
チェックサム計算の上限 |
10 |
10-50 |
MB単位(デフォルト10MB) |
event_intervals |
チェック間隔の定義 |
- |
用途に応じて |
秒単位で定義 |
実践的な使用例
1. セキュリティログ監視
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60 # 1分ごと(セキュリティイベント)
- interval_2: 300 # 5分ごと(一般ログ)
# SSH認証失敗の監視
- path: '/var/log/auth.log'
conditions:
- 'Failed password'
- 'authentication failure'
- 'Invalid user'
name: 'SSH Authentication Failures'
interval: 'interval_1'
severity: 'critical'
# sudoコマンドの監視
- path: '/var/log/auth.log'
conditions:
- 'sudo:'
- 'COMMAND='
name: 'Sudo Command Execution'
interval: 'interval_1'
severity: 'high'
|
2. アプリケーションエラー監視
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 30 # 30秒(クリティカル)
- interval_2: 60 # 1分(エラー)
- interval_3: 300 # 5分(警告)
# Javaアプリケーションエラー
- path: '/var/log/app/application.log'
conditions:
- 'OutOfMemoryError'
- 'StackOverflowError'
- 'NullPointerException'
name: 'Java Critical Errors'
interval: 'interval_1'
severity: 'critical'
# データベース接続エラー
- path: '/var/log/app/application.log'
conditions:
- 'Connection refused'
- 'Connection timeout'
- 'Unable to connect to database'
name: 'Database Connection Errors'
interval: 'interval_2'
severity: 'high'
# 一般的なエラー
- path: '/var/log/app/application.log'
conditions:
- 'ERROR'
- 'FATAL'
name: 'Application Errors'
interval: 'interval_2'
severity: 'high'
# 警告レベル
- path: '/var/log/app/application.log'
conditions:
- 'WARN'
- 'WARNING'
name: 'Application Warnings'
interval: 'interval_3'
severity: 'medium'
|
3. Webサーバーログ監視
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60 # 1分
- interval_2: 300 # 5分
# Nginx/Apache エラーログ
- path: '/var/log/nginx/error.log'
conditions:
- 'emerg'
- 'alert'
- 'crit'
name: 'Nginx Critical Errors'
interval: 'interval_1'
severity: 'critical'
# 502/503エラー
- path: '/var/log/nginx/access.log'
conditions:
- ' 502 '
- ' 503 '
- ' 504 '
name: 'Nginx Gateway Errors'
interval: 'interval_1'
severity: 'high'
# 404エラー(大量発生の検知)
- path: '/var/log/nginx/access.log'
conditions:
- ' 404 '
name: 'Nginx 404 Errors'
interval: 'interval_2'
severity: 'medium'
|
4. データベースログ監視
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60 # 1分
- interval_2: 300 # 5分
# PostgreSQLエラーログ
- path: '/var/log/postgresql/postgresql-14-main.log'
conditions:
- 'FATAL'
- 'PANIC'
- 'ERROR'
name: 'PostgreSQL Errors'
interval: 'interval_1'
severity: 'high'
# MySQLエラーログ
- path: '/var/log/mysql/error.log'
conditions:
- '[ERROR]'
- '[Warning]'
- 'Aborted connection'
name: 'MySQL Errors'
interval: 'interval_1'
severity: 'high'
# スロークエリログ
- path: '/var/log/mysql/slow-query.log'
conditions:
- 'Query_time:'
name: 'MySQL Slow Queries'
interval: 'interval_2'
severity: 'medium'
|
5. システムログ監視
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60 # 1分
- interval_2: 300 # 5分
# システムクリティカルエラー
- path: '/var/log/syslog'
conditions:
- 'kernel panic'
- 'Out of memory'
- 'segfault'
name: 'System Critical Errors'
interval: 'interval_1'
severity: 'critical'
# ディスクエラー
- path: '/var/log/syslog'
conditions:
- 'I/O error'
- 'disk error'
- 'read error'
name: 'Disk Errors'
interval: 'interval_1'
severity: 'high'
# サービス再起動
- path: '/var/log/syslog'
conditions:
- 'systemd.*Started'
- 'systemd.*Stopped'
name: 'Service State Changes'
interval: 'interval_2'
severity: 'medium'
|
ベストプラクティス
セキュリティ
-
ログファイルのアクセス権限
| # Instana Agentがログファイルを読めるように設定
chmod 644 /var/log/application.log
chown root:instana /var/log/application.log
# または、Agentをログファイルのグループに追加
usermod -a -G adm instana
|
-
機密情報のマスキング
| # ログに機密情報が含まれる場合は、条件を慎重に設定
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- path: '/var/log/app/application.log'
conditions:
- 'ERROR' # 具体的なエラーメッセージは避ける
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
|
パフォーマンス
-
チェック間隔の最適化
| # 重要度に応じて間隔を調整
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_critical: 30 # クリティカル: 30秒
- interval_high: 60 # 高: 1分
- interval_medium: 300 # 中: 5分
- interval_low: 900 # 低: 15分
|
-
ファイルサイズの制限
| com.instana.plugin.filemonitoring:
enabled: true
checksum_file_size: 50 # 大きなログファイルの場合は上限を上げる
file_events:
- path: '/var/log/large-application.log'
conditions:
- 'ERROR'
name: 'Large App Errors'
interval: 'interval_1'
severity: 'high'
|
-
条件の効率化
| # 正規表現は使用できないため、具体的なキーワードを使用
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- path: '/var/log/app/application.log'
conditions:
- 'ERROR'
- 'FATAL'
# 'ERR.*' のような正規表現は使用不可
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
|
運用
-
ログローテーション対応
| # logrotateの設定例
/var/log/application.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 app app
postrotate
# Instana Agentは自動的に新しいファイルを検出
endscript
}
|
-
複数環境の管理
| # 本番環境
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 30 # 本番は短い間隔
- path: '/var/log/app/production.log'
conditions:
- 'ERROR'
- 'CRITICAL'
name: 'Production Errors'
interval: 'interval_1'
severity: 'critical'
# ステージング環境
# com.instana.plugin.filemonitoring:
# enabled: true
# file_events:
# - event_intervals:
# - interval_1: 300 # ステージングは長い間隔
# - path: '/var/log/app/staging.log'
# conditions:
# - 'ERROR'
# name: 'Staging Errors'
# interval: 'interval_1'
# severity: 'medium'
|
パフォーマンスチューニング
1. 監視対象ファイルの選定
| # 必要最小限のファイルのみ監視
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60
# 重要なログのみ監視
- path: '/var/log/app/error.log' # エラーログのみ
conditions:
- 'ERROR'
- 'FATAL'
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
# アクセスログは監視しない(大量のI/Oが発生するため)
# - path: '/var/log/app/access.log'
|
2. チェック間隔の調整
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_critical: 30 # クリティカルエラー: 30秒
- interval_high: 120 # 高優先度: 2分
- interval_medium: 300 # 中優先度: 5分
- interval_low: 600 # 低優先度: 10分
# 優先度に応じて間隔を設定
- path: '/var/log/app/critical.log'
conditions:
- 'FATAL'
name: 'Critical Errors'
interval: 'interval_critical'
severity: 'critical'
- path: '/var/log/app/error.log'
conditions:
- 'ERROR'
name: 'Errors'
interval: 'interval_high'
severity: 'high'
- path: '/var/log/app/warning.log'
conditions:
- 'WARN'
name: 'Warnings'
interval: 'interval_medium'
severity: 'medium'
|
3. ファイルサイズの最適化
| com.instana.plugin.filemonitoring:
enabled: true
checksum_file_size: 100 # 大きなログファイルの場合
file_events:
- path: '/var/log/app/large.log'
conditions:
- 'ERROR'
name: 'Large Log Errors'
interval: 'interval_1'
severity: 'high'
|
トラブルシューティング
問題1: ファイルが監視されない
症状:
- イベントが検出されない
- ログにエラーが記録されない
原因と解決策:
-
ファイルパスの確認
| # ファイルが存在するか確認
ls -la /var/log/application.log
# 絶対パスを使用
# ❌ 相対パス: path: 'logs/app.log'
# ✅ 絶対パス: path: '/var/log/app/app.log'
|
-
ファイルアクセス権限
| # Instana Agentがファイルを読めるか確認
sudo -u instana cat /var/log/application.log
# 権限がない場合は修正
chmod 644 /var/log/application.log
# または
usermod -a -G adm instana
systemctl restart instana-agent
|
-
SELinux/AppArmorの確認
| # SELinuxの確認
getenforce
# Enforcingの場合、コンテキストを設定
chcon -t var_log_t /var/log/application.log
# AppArmorの確認
aa-status
# 必要に応じてプロファイルを調整
|
問題2: パフォーマンスへの影響
症状:
- Agentの CPU使用率が高い
- ディスクI/Oが増加
原因と解決策:
-
チェック間隔を長くする
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 300 # 60秒 → 300秒に変更
- path: '/var/log/application.log'
conditions:
- 'ERROR'
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
|
-
監視対象ファイルを減らす
| # 必要最小限のファイルのみ監視
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- path: '/var/log/app/error.log' # エラーログのみ
conditions:
- 'ERROR'
name: 'Errors Only'
interval: 'interval_1'
severity: 'high'
|
-
条件を絞り込む
| # 具体的な条件のみ設定
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- path: '/var/log/application.log'
conditions:
- 'FATAL'
- 'OutOfMemoryError'
# 'ERROR' のような広範な条件は避ける
name: 'Critical Errors Only'
interval: 'interval_1'
severity: 'critical'
|
問題3: イベントが重複する
症状:
- 同じイベントが複数回検出される
- アラートが大量に発生
原因と解決策:
-
ログローテーション後の重複
| # logrotateの設定を確認
cat /etc/logrotate.d/application
# copytruncateを使用している場合は注意
# copytruncate # これが原因の可能性
|
-
チェック間隔の調整
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 300 # 間隔を長くする
- path: '/var/log/application.log'
conditions:
- 'ERROR'
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
|
問題4: 大きなログファイルでの問題
症状:
- チェックサムエラー
- メモリ使用量の増加
原因と解決策:
-
チェックサムサイズの調整
| com.instana.plugin.filemonitoring:
enabled: true
checksum_file_size: 100 # デフォルト10MB → 100MBに増加
file_events:
- path: '/var/log/large-application.log'
conditions:
- 'ERROR'
name: 'Large Log Errors'
interval: 'interval_1'
severity: 'high'
|
-
ログローテーションの設定
| # ログファイルを小さく保つ
/var/log/application.log {
size 100M # 100MBでローテーション
rotate 5
compress
delaycompress
missingok
notifempty
}
|
問題5: 条件が検出されない
症状:
- ログにエラーがあるのにイベントが生成されない
原因と解決策:
-
条件の大文字小文字
| # 大文字小文字を正確に指定
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- path: '/var/log/application.log'
conditions:
- 'ERROR' # ログが "Error" の場合は検出されない
- 'Error' # 両方指定する
- 'error'
name: 'Application Errors'
interval: 'interval_1'
severity: 'high'
|
-
条件の確認
| # ログファイルで実際の文字列を確認
grep -i error /var/log/application.log | head -5
# 正確な文字列を条件に設定
|
-
正規表現は使用不可
| # ❌ 正規表現は使用できない
conditions:
- 'ERR.*'
- '[ERROR|FATAL]'
# ✅ 具体的な文字列を指定
conditions:
- 'ERROR'
- 'FATAL'
- 'ERR_CONNECTION'
|
FAQ
Q1: 複数のログファイルを同時に監視できますか?
A: はい、複数のファイルを監視できます。
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60
# 複数ファイルの監視
- path: '/var/log/app1/error.log'
conditions:
- 'ERROR'
name: 'App1 Errors'
interval: 'interval_1'
severity: 'high'
- path: '/var/log/app2/error.log'
conditions:
- 'ERROR'
name: 'App2 Errors'
interval: 'interval_1'
severity: 'high'
- path: '/var/log/nginx/error.log'
conditions:
- 'crit'
name: 'Nginx Critical'
interval: 'interval_1'
severity: 'critical'
|
Q2: ワイルドカードを使用してファイルを指定できますか?
A: いいえ、ワイルドカードは使用できません。各ファイルを個別に指定する必要があります。
| # ❌ ワイルドカードは使用不可
- path: '/var/log/app/*.log'
# ✅ 個別に指定
- path: '/var/log/app/error.log'
- path: '/var/log/app/access.log'
|
Q3: ログローテーション後も監視は継続されますか?
A: はい、Instana Agentは自動的に新しいファイルを検出します。
| # logrotateの設定例
/var/log/application.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 app app
# Instana Agentは自動的に新しいファイルを検出
}
|
Q4: リアルタイムで監視できますか?
A: ファイル監視は定期的なチェックベースです。最短で30秒間隔を推奨します。
| com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 30 # 最短30秒を推奨
- path: '/var/log/application.log'
conditions:
- 'CRITICAL'
name: 'Critical Errors'
interval: 'interval_1'
severity: 'critical'
|
リアルタイム監視が必要な場合は、アプリケーションレベルのトレーシングやメトリクスを使用してください。
Q5: 条件に正規表現を使用できますか?
A: いいえ、正規表現は使用できません。完全一致または部分一致の文字列のみ指定できます。
| # ❌ 正規表現は使用不可
conditions:
- 'ERR.*'
- '^ERROR:'
- '[0-9]+ errors'
# ✅ 具体的な文字列を指定
conditions:
- 'ERROR'
- 'ERR_CONNECTION'
- 'ERR_TIMEOUT'
- 'FATAL'
|
Q6: 監視によるパフォーマンスへの影響はどの程度ですか?
A: 適切に設定すれば影響は最小限です。以下のガイドラインに従ってください:
- 監視ファイル数: 10ファイル以下を推奨
- チェック間隔: 60秒以上を推奨
- ファイルサイズ: 100MB以下を推奨
- 条件数: ファイルあたり5個以下を推奨
| # パフォーマンスに配慮した設定例
com.instana.plugin.filemonitoring:
enabled: true
checksum_file_size: 50
file_events:
- event_intervals:
- interval_1: 60 # 1分間隔
# 重要なログのみ監視(5ファイル)
- path: '/var/log/app/error.log'
conditions:
- 'ERROR'
- 'FATAL'
name: 'App Errors'
interval: 'interval_1'
severity: 'high'
|
Q7: Dockerコンテナ内のログファイルを監視できますか?
A: はい、ホストからマウントされたボリューム内のログファイルを監視できます。
| # Dockerホスト上の設定
com.instana.plugin.filemonitoring:
enabled: true
file_events:
- event_intervals:
- interval_1: 60
# マウントされたボリューム内のログ
- path: '/var/lib/docker/volumes/app-logs/_data/application.log'
conditions:
- 'ERROR'
name: 'Container App Errors'
interval: 'interval_1'
severity: 'high'
|
または、コンテナ内にAgentをインストールして監視することもできます。
関連ドキュメント:
- ホスト監視設定
- プロセス監視設定
- トラブルシューティング