script day.log

大学生がなんとなく始めた、趣味やら生活のことを記録していく。

Zabbix3.0 + netdataでのリソース監視

前回の記事でログ監視を行ったので,
続いてリソース監視を行いました. 今回はリアルタイム監視と過去リソース監視の2つを導入しました. リアルタイム監視はnetdata,過去リソース監視はzabbixで行いました.

makose3p1229.hatenablog.com

1.Zabbix3.0

Since zabbix 3.0 is LTS, I selected it.

1.1 Zabbix(Server) install(Amazon Linux に Zabbix Server 3.0 をインストールする - らくがきちょう)

zabbix needs apache + php + MySQL

Step1: Apache2.4, PHP7.1 MySQL install

$ sudo yum check-update
$ sudo yum -y install mysql-server httpd24 php71 php71-gd php71-mbstring php71-mysqlnd php71-bcmath

Step2: Zabbix Server install

$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
$ sudo yum check-update
$ sudo yum -y install zabbix-get zabbix-server-mysql zabbix-web-japanese zabbix-web-mysql
Create DB on MySQL
$ sudo service mysqld start
$ sudo chkconfig mysqld on
$ mysql -u root
> CREATE USER zabbix;
> CREATE DATABASE zabbix;
> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY '<DB_PASSWORD>';
> FLUSH PRIVILEGES;
> quit;
Setting apache, php , etc...
$ cd /usr/share/doc/zabbix-server-mysql-3.0.5/
$ zcat create.sql.gz | mysql -u root zabbix
$ sudo cp /usr/share/doc/zabbix-web-3.0.5/httpd24-example.conf /etc/httpd/conf.d/zabbix.conf
$ sudo sed -i -e "s/;date.timezone =/date.timezone = Asia\/Tokyo/g" /etc/php.ini
$ sudo sed -i -e "s/;always_populate_raw_post_data/always_populate_raw_post_data/g" /etc/php.ini
$ sudo sed -i -e "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini
$ sudo sed -i -e "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini
$ sudo sed -i -e "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini

Step3: Launch Zabbix Server

setting DBpassword at /etc/zabbix/zabbix_server.conf

DBPassword=<DB_PASSWORD>

setup finished! launch zabbix server.

$ sudo service zabbix-server start
$ sudo service httpd start
$ sudo chkconfig zabbix-server on
$ sudo chkconfig httpd on

Step4: Access Zabbix Server

access to http://(server_ip)/zabix/
Follow the installation guide. Install everything missing every time.

Step5: Login

default ID and Password

UserName: Admin
Password: zabbix

1.2 Zabbix(Client) install(Amazon Linux に Zabbix エージェントをインストールする - らくがきちょう)

Step1: Zabbix Agent install
$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
$ sudo yum -y install zabbix-agent
Step2: conf setting

Change /etc/zabbix/zabbix_agentd.conf.

item description
Server Specify the host name of the Zabbix server
ServerActive Specify the host name of the Zabbix server
Hostname Specify the host name of the Zabbix agent
Server=server.example.local
ServerActive=server.example.local
Hostname=agent.example.local
Step3: start Zabbix Agent, Auto start setting
service zabbix-agent start
chkconfig zabbix-agent on

1.3 alert setting(Zabbixのアラートをチャットワークで通知する - Qiita)

Script default location is /usr/lib/zabbix/alertscripts

  • /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts

Create a script 'chatwork' to notify chatwork * chatowork

#!/bin/sh

TOKEN="CHATWORK_TOKEN"
ENDPOINT="https://api.chatwork.com/v2/rooms/${1}/messages"
SUBJECT=${2}
MESSAGE=${3}

/usr/bin/curl -X POST -H "X-ChatWorkToken: ${TOKEN}" -d "body=[info][title]${SUBJECT}[/title]${MESSAGE}[/info]" ${ENDPOINT}

Add execution authority

$ chmod +x /usr/lib/zabbix/alertscripts/chatwork

Select "Manage" -> "Media type" of Zabbix and create from media type creation.Set [Type] and [Script Parameters] as shown below.

media_type

Add media settings to any administrator user. Select any administrator from "Administration" -> "Users". Select the "Media" tab and click "Add" to open the setting screen. For types and destinations, set according to the situation.

Type (created media type name)
Destination Room ID of chatwork you want to use for notification

user

"Event Source: Trigger" is displayed in "Settings" -> "Action". I think that 'Report problems to Zabbix administrators' are set by default, so select it. Notifications will be sent with the subject and message you set here. Recovery message is a message when recovering from failure.

action

2.netdata(Home · firehol/netdata Wiki · GitHub)

2.1 netdata install

this commands exec

$ yum install zlib-devel libuuid-devel libmnl-devel gcc make git autoconf autogen automake pkgconfig
$ git clone https://github.com/firehol/netdata.git --depth=1
$ cd netdata
$ ./netdata-installer.sh
$ cd /etc/init.d/
$ cp -p ~/netdata/system/netdata-init-d ./netdata
$ chmod 755 netdata
$ chkconfig --add netdata
$ chkconfig netdata on

2.2 launch netata & access netdata

this commands exec

$ service netdata start

access http://(server_ip):19999