New Relic Infrastructure - ポート監視の設定と運用
はじめに
ネットワークサービスの可用性監視において、ポートの開閉状態やレスポンス時間の監視は重要です。New Relic Infrastructure のPort Monitoring Integrationを使用すると、TCP/UDPポートの状態を継続的に監視し、異常を迅速に検知できます。
この記事では、Port Monitoring Integrationのインストールから設定、実践的な運用方法まで詳しく解説します。
Port Monitoring Integrationの概要
監視できる項目
Port Monitoring Integrationは以下の情報を収集します:
- ポートの開閉状態 (up/down)
- レスポンス時間 (ミリ秒単位)
- 接続成功/失敗の状態
- TCP/UDPプロトコルの対応
- タイムアウト検知
アーキテクチャ
インストール手順
前提条件
Port Monitoring Integrationを使用するには、以下の要件を満たす必要があります:
- Infrastructure Agent がインストール済み(バージョン 1.0.0 以降)
- Linux環境(現在のところLinuxのみサポート)
- 監視対象ポートへのネットワークアクセス権限
1. Infrastructure Agentのインストール確認
# Agentのバージョン確認
newrelic-infra --version
# Agentが実行中か確認
sudo systemctl status newrelic-infra2. Port Monitoring Integrationのダウンロード
GitHubからのダウンロード
# 最新リリースのダウンロード
cd /tmp
wget https://github.com/newrelic/nri-port-monitor/releases/latest/download/nri-port-monitor-linux-amd64.tar.gz
# 展開
tar -xzf nri-port-monitor-linux-amd64.tar.gz
# バイナリの配置
sudo cp nri-port-monitor /var/db/newrelic-infra/newrelic-integrations/bin/
# 定義ファイルの配置
sudo cp port-monitor-definition.yml /var/db/newrelic-infra/newrelic-integrations/
# 実行権限の付与
sudo chmod +x /var/db/newrelic-infra/newrelic-integrations/bin/nri-port-monitorパッケージマネージャーでのインストール(推奨)
Ubuntu/Debian:
# New Relicリポジトリが設定済みの場合
sudo apt-get update
sudo apt-get install nri-port-monitorCentOS/RHEL:
# New Relicリポジトリが設定済みの場合
sudo yum install nri-port-monitor3. 設定ファイルの作成
# サンプル設定ファイルをコピー
sudo cp /var/db/newrelic-infra/newrelic-integrations/port-monitor-config.yml.sample \
/etc/newrelic-infra/integrations.d/port-monitor-config.yml
# 設定ファイルの編集
sudo vim /etc/newrelic-infra/integrations.d/port-monitor-config.yml4. Infrastructure Agentの再起動
sudo systemctl restart newrelic-infra
# ログで動作確認
sudo journalctl -u newrelic-infra -f | grep -i port設定ファイルの詳細
基本的な設定例
# /etc/newrelic-infra/integrations.d/port-monitor-config.yml
integrations:
- name: nri-port-monitor
env:
# タイムアウト設定(秒)
TIMEOUT: 5
interval: 30s # チェック間隔
config:
# 監視対象ポートの定義
instances:
# HTTPポート監視
- name: http_port
address: localhost:80
network: tcp
timeout: 5
labels:
service: web
protocol: http
# HTTPSポート監視
- name: https_port
address: localhost:443
network: tcp
timeout: 5
labels:
service: web
protocol: https
# SSHポート監視
- name: ssh_port
address: localhost:22
network: tcp
timeout: 3
labels:
service: ssh
critical: true高度な設定例
Webサーバーの監視
integrations:
- name: nri-port-monitor
interval: 30s
config:
instances:
# フロントエンドWebサーバー
- name: frontend_http
address: 10.0.1.10:80
network: tcp
timeout: 5
labels:
environment: production
tier: frontend
server: web-01
- name: frontend_https
address: 10.0.1.10:443
network: tcp
timeout: 5
labels:
environment: production
tier: frontend
server: web-01
# バックエンドAPIサーバー
- name: api_server
address: 10.0.2.10:8080
network: tcp
timeout: 10
labels:
environment: production
tier: backend
service: apiデータベースサーバーの監視
integrations:
- name: nri-port-monitor
interval: 60s # DBは頻繁にチェックしない
config:
instances:
# MySQLマスター
- name: mysql_master
address: 10.0.3.10:3306
network: tcp
timeout: 5
labels:
database: mysql
role: master
critical: true
# MySQLスレーブ
- name: mysql_slave_01
address: 10.0.3.11:3306
network: tcp
timeout: 5
labels:
database: mysql
role: slave
# PostgreSQL
- name: postgres_main
address: 10.0.3.20:5432
network: tcp
timeout: 5
labels:
database: postgres
# Redis
- name: redis_cache
address: 10.0.3.30:6379
network: tcp
timeout: 3
labels:
database: redis
role: cacheUDPポートの監視
integrations:
- name: nri-port-monitor
interval: 30s
config:
instances:
# DNSサーバー
- name: dns_server
address: 10.0.4.10:53
network: udp
timeout: 3
labels:
service: dns
# Syslogサーバー
- name: syslog_server
address: 10.0.4.20:514
network: udp
timeout: 5
labels:
service: syslog
# NTPサーバー
- name: ntp_server
address: 10.0.4.30:123
network: udp
timeout: 2
labels:
service: ntp外部サービスの監視
integrations:
- name: nri-port-monitor
interval: 60s
config:
instances:
# 外部APIエンドポイント
- name: external_api
address: api.example.com:443
network: tcp
timeout: 10
labels:
type: external
vendor: example
# サードパーティサービス
- name: payment_gateway
address: payment.provider.com:443
network: tcp
timeout: 15
labels:
type: external
service: payment
critical: trueデータクエリと可視化
NRQLクエリ例
ポート状態の現在値
SELECT latest(status) AS 'Status'
FROM NetworkPortSample
FACET address, label.service
SINCE 5 MINUTES AGOポート状態の時系列グラフ
SELECT latest(status) AS 'Status'
FROM NetworkPortSample
WHERE address IN ('localhost:80', 'localhost:443', 'localhost:3306')
FACET address
TIMESERIES AUTO
SINCE 1 HOUR AGOレスポンス時間の監視
SELECT average(durationMs) AS 'Avg Response Time (ms)',
max(durationMs) AS 'Max Response Time (ms)'
FROM NetworkPortSample
WHERE status = 'up'
FACET address
TIMESERIES AUTO
SINCE 30 MINUTES AGOポート障害の検知
SELECT count(*) AS 'Failed Checks'
FROM NetworkPortSample
WHERE status = 'down'
FACET address, label.service
SINCE 1 HOUR AGOサービス別の可用性
SELECT percentage(count(*), WHERE status = 'up') AS 'Uptime %'
FROM NetworkPortSample
FACET label.service
SINCE 1 DAY AGOダッシュボードの作成
ポート監視概要ダッシュボード
New Relic UIで以下のウィジェットを含むダッシュボードを作成します:
1. 現在のポート状態(Billboard)
SELECT latest(status)
FROM NetworkPortSample
FACET address2. レスポンス時間(Line Chart)
SELECT average(durationMs) AS 'Response Time'
FROM NetworkPortSample
WHERE status = 'up'
FACET address
TIMESERIES
SINCE 1 HOUR AGO3. 可用性(Pie Chart)
SELECT count(*)
FROM NetworkPortSample
FACET status
SINCE 1 HOUR AGO4. サービス別ステータス(Table)
SELECT latest(status) AS 'Status',
average(durationMs) AS 'Avg Time',
latest(timestamp) AS 'Last Check'
FROM NetworkPortSample
FACET label.service, address
SINCE 5 MINUTES AGOアラート設定
基本的なアラート条件
ポートダウンの検知
アラート条件名: Critical - Port Down
条件タイプ: NRQL
NRQL Query:
SELECT latest(status)
FROM NetworkPortSample
WHERE label.critical = 'true'
FACET address
閾値:
- Critical: status = 'down' が 2 分間継続
- 評価間隔: 1 分ごとレスポンス時間の劣化
アラート条件名: Warning - High Response Time
条件タイプ: NRQL
NRQL Query:
SELECT average(durationMs)
FROM NetworkPortSample
WHERE status = 'up'
FACET address
閾値:
- Warning: 平均レスポンス時間が 1000ms を超える(5分間)
- Critical: 平均レスポンス時間が 3000ms を超える(5分間)断続的な接続障害
アラート条件名: Warning - Intermittent Connection Issues
条件タイプ: NRQL
NRQL Query:
SELECT percentage(count(*), WHERE status = 'down')
FROM NetworkPortSample
FACET address
閾値:
- Warning: 10% 以上の失敗率(15分間)
- Critical: 50% 以上の失敗率(15分間)高度なアラート設定
複数ポートの同時障害検知
-- アラートクエリ
SELECT uniqueCount(address) AS 'Down Ports'
FROM NetworkPortSample
WHERE status = 'down' AND label.environment = 'production'閾値:
- Critical: 3 個以上のポートが同時にダウン(5分間)ポート復旧の通知
-- リカバリー通知用クエリ
SELECT latest(status)
FROM NetworkPortSample
WHERE address = 'critical-service:443'条件:
- status が 'down' から 'up' に変化したときに通知実践的な運用パターン
マイクロサービス環境の監視
integrations:
- name: nri-port-monitor
interval: 30s
config:
instances:
# API Gateway
- name: api_gateway
address: api-gateway.internal:8080
network: tcp
timeout: 5
labels:
service: api-gateway
tier: edge
# Auth Service
- name: auth_service
address: auth-service.internal:8081
network: tcp
timeout: 5
labels:
service: auth
tier: backend
# User Service
- name: user_service
address: user-service.internal:8082
network: tcp
timeout: 5
labels:
service: users
tier: backend
# Order Service
- name: order_service
address: order-service.internal:8083
network: tcp
timeout: 5
labels:
service: orders
tier: backend地理的分散環境の監視
integrations:
- name: nri-port-monitor
interval: 60s
config:
instances:
# 東京リージョン
- name: tokyo_web
address: web.tokyo.example.com:443
network: tcp
timeout: 10
labels:
region: tokyo
datacenter: ap-northeast-1
# シンガポールリージョン
- name: singapore_web
address: web.singapore.example.com:443
network: tcp
timeout: 15
labels:
region: singapore
datacenter: ap-southeast-1
# 米国リージョン
- name: us_web
address: web.us.example.com:443
network: tcp
timeout: 20
labels:
region: us-west
datacenter: us-west-2ロードバランサーとバックエンドの監視
integrations:
- name: nri-port-monitor
interval: 30s
config:
instances:
# ロードバランサー
- name: lb_public
address: lb.example.com:443
network: tcp
timeout: 5
labels:
component: load-balancer
public: true
# バックエンドサーバー群
- name: backend_01
address: 10.0.10.11:8080
network: tcp
timeout: 5
labels:
component: backend
server: backend-01
- name: backend_02
address: 10.0.10.12:8080
network: tcp
timeout: 5
labels:
component: backend
server: backend-02
- name: backend_03
address: 10.0.10.13:8080
network: tcp
timeout: 5
labels:
component: backend
server: backend-03トラブルシューティング
データが表示されない
確認手順
# 1. Integrationがインストールされているか確認
ls -l /var/db/newrelic-infra/newrelic-integrations/bin/nri-port-monitor
# 2. 設定ファイルの存在確認
ls -l /etc/newrelic-infra/integrations.d/port-monitor-config.yml
# 3. 設定ファイルの構文チェック
sudo newrelic-infra -dry-run
# 4. Integrationの手動実行テスト
sudo /var/db/newrelic-infra/newrelic-integrations/bin/nri-port-monitor \
--config_path /etc/newrelic-infra/integrations.d/port-monitor-config.yml \
--verbose
# 5. Agentログの確認
sudo journalctl -u newrelic-infra -f | grep -i "port-monitor"よくある問題と解決方法
問題1: "Permission denied" エラー
# 実行権限の確認と付与
sudo chmod +x /var/db/newrelic-infra/newrelic-integrations/bin/nri-port-monitor問題2: "No such file or directory" エラー
# パスの確認
sudo find / -name nri-port-monitor 2>/dev/null
# 正しい場所に配置されているか確認
ls -la /var/db/newrelic-infra/newrelic-integrations/bin/問題3: 設定ファイルのYAML構文エラー
# YAMLの検証(yamllintがインストールされている場合)
yamllint /etc/newrelic-infra/integrations.d/port-monitor-config.yml
# インデントが正しいか確認(スペース2個)
cat -A /etc/newrelic-infra/integrations.d/port-monitor-config.yml特定のポートが監視されない
ネットワーク接続の確認
# TCPポートへの接続テスト
telnet localhost 80
# または netcat を使用
nc -zv localhost 80
# タイムアウト値の確認
timeout 5 bash -c "echo > /dev/tcp/localhost/80" && echo "Port is open"
# UDPポートの確認
nc -zvu localhost 53ファイアウォール設定の確認
# Linux iptables
sudo iptables -L -n -v | grep 80
# firewalld(CentOS/RHEL)
sudo firewall-cmd --list-all
# ufw(Ubuntu)
sudo ufw status verboseタイムアウトが頻発する
タイムアウト値の調整
# タイムアウトを延長
config:
instances:
- name: slow_service
address: slow-service.example.com:443
network: tcp
timeout: 30 # 30秒に延長ネットワークレイテンシの測定
# pingでレイテンシ確認
ping -c 10 slow-service.example.com
# traceroute で経路確認
traceroute slow-service.example.com
# curlでレスポンス時間測定
curl -w "@curl-format.txt" -o /dev/null -s https://slow-service.example.com/パフォーマンスとベストプラクティス
チェック間隔の最適化
| 監視対象 | 推奨間隔 | 理由 |
|---|---|---|
| クリティカルなサービス | 30秒 | 迅速な障害検知 |
| 通常のサービス | 60秒 | バランスの取れた監視 |
| 外部サービス | 120秒以上 | ネットワーク負荷軽減 |
| 開発環境 | 300秒 | コスト削減 |
ラベリング戦略
効果的なラベル付けにより、データの整理とアラート設定が容易になります:
labels:
# 環境の識別
environment: production # production, staging, development
# 重要度
critical: true # true, false
# サービス分類
tier: frontend # frontend, backend, database
service: api # api, web, cache, etc.
# 地理的位置
region: us-east # us-east, eu-west, ap-southeast
datacenter: dc-01 # データセンター識別子
# 所有チーム
team: platform # チーム名
owner: john.doe # 担当者コスト最適化
Port Monitoring Integrationのデータ量を最適化する方法:
1. 不要な監視の削減
# ✅ 良い例: 必要なポートのみ監視
instances:
- name: critical_services
address: api.example.com:443
labels:
critical: true
# ❌ 悪い例: すべてのポートを監視
# instances:
# - name: all_ports
# address: 0.0.0.0:1-65535 # これは実行できません2. 適切な間隔設定
# クリティカルでないサービスは間隔を長く
integrations:
- name: nri-port-monitor
interval: 300s # 5分間隔
config:
instances:
- name: dev_service
address: dev.example.com:80803. タイムアウトの最適化
# 不必要に長いタイムアウトを避ける
config:
instances:
- name: fast_service
address: localhost:80
timeout: 3 # 通常は3-5秒で十分セキュリティ考慮事項
ネットワークセグメンテーション
Port Monitoring Integrationを実行するホストは、監視対象ポートにアクセスできる必要があります:
# ネットワークアクセス権限の確認
sudo iptables -L -n -v
# 必要に応じてファイアウォールルールを追加
sudo iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT機密情報の保護
設定ファイルに機密情報(認証情報など)を含めないでください:
# ❌ 悪い例
config:
instances:
- name: database
address: db.example.com:3306
username: admin # 設定ファイルに認証情報を含めない
password: secret # 設定ファイルに認証情報を含めない
# ✅ 良い例
config:
instances:
- name: database
address: db.example.com:3306
# ポートの開閉のみを監視、認証は行わないファイル権限の設定
# 設定ファイルの権限を適切に設定
sudo chmod 600 /etc/newrelic-infra/integrations.d/port-monitor-config.yml
sudo chown root:root /etc/newrelic-infra/integrations.d/port-monitor-config.ymlまとめ
Port Monitoring Integrationを活用すると、ネットワークサービスの可用性を継続的に監視し、障害を迅速に検知できます。適切な設定とアラート条件により、サービスの信頼性を大幅に向上させることができます。
重要なポイント
- Infrastructure Agentが前提: Port監視にはAgentのインストールが必須
- 適切なタイムアウト設定: ネットワーク状況に応じた調整が重要
- ラベルの活用: 効果的なラベリングでデータ整理とアラート管理を効率化
- チェック間隔の最適化: サービスの重要度に応じた設定でコスト削減
- アラート設定: ポートダウンとレスポンス劣化の両方を監視
次のステップ
- プロセス監視の設定 - サービスプロセスの状態監視
- セキュリティログ監視 - OSのセキュリティイベント監視
- Linux環境でのエージェント導入 - Infrastructure Agentのインストール
- 設定ファイル完全リファレンス - 全設定オプションの詳細
関連記事: Infrastructure Agent概要とアーキテクチャGitHub: nri-port-monitor リポジトリ