#author("2018-08-29T17:29:40+09:00","","")

#author("2018-08-29T17:30:29+09:00","","")



[[CentOS7]]



*性能統計グラフ追加(Nagios+PNP4Nagios) [#b99c5cd9]
[[Nagios>Nagiosインストール]]のアドオン[[PNP4Nagios>http://docs.pnp4nagios.org/start]]を導入して、Nagios監視項目の性能統計データをグラフ化する。

&color(red){※[[Nagios>Nagiosインストール]]導入済であることが前提};



*PNP4Nagiosインストール [#w808a914]
|BGCOLOR(black):COLOR(white):|c
|[root@localhost ~]# yum -y install rrdtool php-gd &color(lime){← PNP4Nagiosに必要なパッケージインストール};|
|[root@localhost ~]# wget http://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.25.tar.gz &color(lime){← PNP4Nagiosダウンロード};|
|&color(lightpink){※最新版のURLは[[ダウンロードページ>http://sourceforge.net/project/showfiles.php?group_id=191615]]で確認すること};|
|[root@localhost ~]# tar zxvf pnp4nagios-0.6.25.tar.gz &color(lime){← PNP4Nagios展開};|
|[root@localhost ~]# cd pnp4nagios-0.6.25/ &color(lime){← PNP4Nagios展開先ディレクトリへ移動};|
|[root@localhost pnp4nagios-0.6.25]# ./configure && make all && make fullinstall &color(lime){← PNP4Nagiosインストール};|
|[root@localhost pnp4nagios-0.6.25]# cd &color(lime){← PNP4Nagios展開先ディレクトリを抜ける};|
|[root@localhost ~]# rm -rf pnp4nagios-0.6.25 &color(lime){← PNP4Nagios展開先ディレクトリを削除};|
|[root@localhost ~]# rm -f pnp4nagios-0.6.25.tar.gz &color(lime){← ダウンロードしたファイルを削除};|
|[root@localhost ~]# systemctl restart httpd &color(lime){← Apache再起動};|

http://サーバー名/pnp4nagios/へアクセスして全項目グリーン表示されることを確認
|BGCOLOR(black):COLOR(white):|c
|[root@localhost ~]# rm -f /usr/local/pnp4nagios/share/install.php &color(lime){← インストールスクリプト削除};|



*PNP4Nagios設定 [#y8f61bcb]
**PNP4Nagios設定 [#l680463f]
|BGCOLOR(black):COLOR(white):|c
|[root@localhost ~]# vi /usr/local/pnp4nagios/etc/config_local.php &color(lime){← PNP4Nagios設定ファイル編集};|
|# &br; # Date format &br; # &br; $conf['date_fmt'] = "Y.m.d G:i"; &color(lime){← 日付形式をYYYY.MM.DDにする};|
|[root@localhost ~]# wget "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=4174&cf_id=24" -O check_mem &color(lime){← check_memプラグインのPNPテンプレートダウンロード};|
|[root@localhost ~]# /bin/mv check_mem.php /usr/local/pnp4nagios/share/templates.dist/ &color(lime){← check_memプラグインのPNPテンプレートを所定のディレクトリへ移動};|
|[root@localhost ~]# wget "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=4105&cf_id=29" -O check_traffic.php &color(lime){← check_traffic_pnp4naiosプラグインのPNPテンプレートダウンロード};|
|[root@localhost ~]# mv check_traffic.php /usr/local/pnp4nagios/share/templates.dist/ &color(lime){← check_traffic_pnp4naiosプラグインのPNPテンプレートを所定のディレクトリへ移動};|
|[root@localhost ~]# vi /usr/local/pnp4nagios/share/templates.dist/check_traffic.php &color(lime){← check_traffic_pnp4naiosプラグインのPNPテンプレート編集};|
|<?php &br; $ds_name[1] = "Traffic Usage"; &color(lime){← 追加(表タイトル) &br; $opt[1] = "--vertical-label bits/s --title \"Traffic for $hostname / $servicedesc\" ";};|



**Nagios設定 [#bd530718]
|BGCOLOR(black):COLOR(white):|c
|[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg &color(lime){← nagios.cfg編集};|
|process_performance_data=1 &color(lime){← パフォーマンスデータ取得を有効化}; &br;  &br; host_perfdata_command=process-host-perfdata &color(lime){← ホストパフォーマンスデータ取得コマンドを有効化}; &br; service_perfdata_command=process-service-perfdata &color(lime){← サービスパフォーマンスデータ取得コマンドを有効化}; &br;  &br; &color(lime){以下を最終行へ追加}; &br; # &br; # service performance data &br; # &br; service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata &br; service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET:: \  &br; $TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA:: \  &br; $SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE:: \  &br; $HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE:: \  &br; $SERVICESTATETYPE$ &br; service_perfdata_file_mode=a &br; service_perfdata_file_processing_interval=15 &br; service_perfdata_file_processing_command=process-service-perfdata-file &br;  &br; # &br; # host performance data starting with Nagios 3.0 &br; #  &br; host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata &br; host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME:: \  &br; $HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE:: \  &br; $HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ &br; host_perfdata_file_mode=a &br; host_perfdata_file_processing_interval=15 &br; host_perfdata_file_processing_command=process-host-perfdata-file|
|[root@localhost ~]# vi /usr/local/nagios/etc/objects/commands.cfg &color(lime){← commands.cfg編集};|
|&color(lime){--削除(ここから)--};|
|# 'process-host-perfdata' command definition &br; define command{ &br;        command_name    process-host-perfdata &br;        command_line    /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\ \ t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out &br;        }|
|# 'process-service-perfdata' command definition &br; define command{ &br;        command_name    process-service-perfdata &br;        command_line    /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out &br;        }  &br; &color(lime){--削除(ここまで)--};|
|&color(lime){以下を最終行へ追加};|
|define command{ &br;        command_name    process-service-perfdata-file &br;        command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$ &br; }|
|define command{ &br;        command_name    process-host-perfdata-file &br;        command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$ &br; }|
|[root@localhost ~]# vi /usr/local/nagios/etc/objects/templates.cfg &color(lime){← templates.cfg編集};|
|############################################################################### &br; ############################################################################### &br; # &br; # HOST TEMPLATES &br; # &br; ############################################################################### &br; ############################################################################### &br;  &br; # Generic host definition template - This is NOT a real host, just a template! &br;  &br; define host{ &br;         name                            generic-host    ; The name of this host template &br;         notifications_enabled           1               ; Host notifications are enabled &br;         event_handler_enabled           1               ; Host event handler is enabled &br;         flap_detection_enabled          1               ; Flap detection is enabled &br;         failure_prediction_enabled      1               ; Failure prediction is enabled &br;         process_perf_data               1               ; Process performance data &br;         retain_status_information       1               ; Retain status information across program restarts &br;         retain_nonstatus_information    1               ; Retain non-status information across program restarts &br;         notification_period             24x7            ; Send host notifications at any time &br;         register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! &br;         action_url /pnp4nagios/graph?host=$HOSTNAME$' onmouseover="get_g('$HOSTNAME$','_HOST_')" onmouseout="clear_g()" &color(lime){← 追加(Nagios画面からPNP画面へのリンク表示(ホスト)) &br;         } &br;  &br; ############################################################################### &br; ## SERVICE TEMPLATES &br; # &br; ############################################################################### &br; ############################################################################### &br;  &br; # Generic service definition template - This is NOT a real service, just a template! &br;  &br; define service{ &br;         name                            generic-service         ; The 'name' of this service template &br;         active_checks_enabled           1                       ; Active service checks are enabled &br;         passive_checks_enabled          1                       ; Passive service checks are enabled/accepted &br;         parallelize_check               1                       ; Active service checks should be parallelized (disabling this can lead to major performance problems) &br;         obsess_over_service             1                       ; We should obsess over this service (if necessary) &br;         check_freshness                 0                       ; Default is to NOT check service 'freshness' &br;         notifications_enabled           1                       ; Service notifications are enabled &br;         event_handler_enabled           1                       ; Service event handler is enabled &br;         flap_detection_enabled          1                       ; Flap detection is enabled &br;         failure_prediction_enabled      1                       ; Failure prediction is enabled &br;         process_perf_data               1                       ; Process performance data &br;         retain_status_information       1                       ; Retain status information across program restarts &br;         retain_nonstatus_information    1                       ; Retain non-status information across program restarts &br;         is_volatile                     0                       ; The service is not volatile &br;         check_period                    24x7                    ; The service can be checked at any time of the day &br;         max_check_attempts              3                       ; Re-check the service up to 3 times in order to determine its final (hard) state &br;         normal_check_interval           10                      ; Check the service every 10 minutes under normal conditions &br;         retry_check_interval            2                       ; Re-check the service every two minutes until a hard state can be determined &br;         contact_groups                  admins                  ; Notifications get sent out to everyone in the 'admins' group &br;         notification_options            w,u,c,r                 ; Send notifications about warning, unknown, critical, and recovery events &br;         notification_interval           60                      ; Re-notify about service problems every hour &br;         notification_period             24x7                    ; Notifications can be sent out at any time &br;          register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! &br;         action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' onmouseover="get_g('$HOSTNAME$','$SERVICEDESC$')" onmouseout="clear_g()" &color(lime){← 追加(Nagios画面からPNP画面へのリンク表示(サービス)) &br;         }|
|[root@localhost ~]# /etc/rc.d/init.d/npcd start &color(lime){← NPCD起動};|
|[root@localhost ~]# chkconfig npcd on &color(lime){← NPCD自動起動設定};|
|[root@localhost ~]# /etc/rc.d/init.d/nagios restart &color(lime){← Nagios再起動};|



*PNP確認 [#b3887a99]
http://サーバー名/nagios/へアクセスし、「ホスト」または「サービス」でをクリックして性能統計グラフが表示されることを確認。

&color(red){※一部監視項目はパフォーマンスデータを出力しないため、グラフ表示できない};

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS