Zabbix 5.0 with SELinux on CentOS 8

 article  Comments Off on Zabbix 5.0 with SELinux on CentOS 8
Mar 142021
 

SELinux環境下で動かそうとしたらいろいろあったので覚書。

前提

環境

  • CentOS 8.3
  • Zabbix 5.0.9
  • PostgreSQL 10.15
  • Apache 2.4

利用テンプレート

  • Template App Zabbix Server
  • Template App Apache by HTTP
  • Template App PHP-FPM by HTTP
  • Template OS Linux by Zabbix agent
  • Template DB PostgreSQL

適用したSELinuxブール値

  • httpd_can_connect_zabbix –> on
  • httpd_can_network_connect_db –> off
  • zabbix_can_network –> on

作成したSELinuxポリシーなど

Zabbix Server用

module zabbix-server_local 1.0;

require {
        type zabbix_t;
        type zabbix_var_run_t;
        type krb5_keytab_t;
        type var_log_t;
        class sock_file create;
        class sock_file unlink;
        class unix_stream_socket connectto;
        class dir search;
        class file open;
        class file read;
}

#============= zabbix_t ==============
allow zabbix_t zabbix_var_run_t:sock_file create;
allow zabbix_t zabbix_var_run_t:sock_file unlink;
allow zabbix_t self:unix_stream_socket connectto;
allow zabbix_t krb5_keytab_t:dir search;
allow zabbix_t var_log_t:file open;
allow zabbix_t var_log_t:file read;

上記ポリシーに加えてdac_overrideも要求されるが、/run/zabbixの所有者権限がzabbix:zabbix 700となっており、厳密なDACとしてはrootでの書き込みが許可されていないため発生している。
dac_overrideは許可したくないので/run/zabbixの権限をzabbix:root 775に変更してrootにも書き込み許可を与えるようにした。サービスユニットファイルを以下のとおり修正している。

[Service]
ExecStartPre=/usr/bin/mkdir -p /run/zabbix
ExecStartPre=/usr/bin/chgrp root /run/zabbix
ExecStartPre=/usr/bin/chmod g+w  /run/zabbix

Apache用

httpd_can_network_connect_dbをoffにしたので、PostgreSQLへの接続のみを明示的に許可している。

module httpd_local 1.0;

require {
        type httpd_t;
        type postgresql_port_t;
        class tcp_socket name_connect;
}

#============= httpd_t ==============
allow httpd_t postgresql_port_t:tcp_socket name_connect;

Zabbix Agent監視用

PostgreSQL監視用に/var/lib/zabbix/.pgpass読み込み(zabbix_var_lib_t)と、system.sw.packagesキーでrpm一覧を取得するためのrpm_exec_t実行権限やvar_lib_rpm_tの読み込み権限が必要だった。

module zabbix-agent_local 1.0;

require {
        type zabbix_agent_t;
        type zabbix_var_lib_t;
        type rpm_exec_t;
        type rpm_var_lib_t;
        type devlog_t;
        type initctl_t;
        type proc_kcore_t;
        class file open;
        class file read;
        class file execute;
        class file execute_no_trans;
        class file map;
        class sock_file getattr;
        class fifo_file getattr;
        class file getattr;
}

#============= zabbix_agent_t ==============
allow zabbix_agent_t zabbix_var_lib_t:file open;
allow zabbix_agent_t zabbix_var_lib_t:file read;
allow zabbix_agent_t rpm_exec_t:file execute;
allow zabbix_agent_t rpm_exec_t:file execute_no_trans;
allow zabbix_agent_t rpm_exec_t:file map;
allow zabbix_agent_t rpm_var_lib_t:file open;
allow zabbix_agent_t rpm_var_lib_t:file read;
allow zabbix_agent_t devlog_t:sock_file getattr;
allow zabbix_agent_t initctl_t:fifo_file getattr;
allow zabbix_agent_t proc_kcore_t:file getattr;

Zabbix 4.0.9 SELinux設定

 article  Comments Off on Zabbix 4.0.9 SELinux設定
Jun 132019
 

SELinuxを有効にしたCentOS 7にZabbix 4.0.9を導入した際のSELinux設定メモです。

CentOS 7にZabbix 4.0.9、MariaDB、Apache HTTP Serverを導入し、SELinux無効化状態であれば起動するところまで設定済みなところから始めます。

まずはApacheからZabbix Serverへの接続許可、Zabbixからのネットワーク接続を許可するbool値を設定します。httpd_can_network_connect_dbというのもありますが、今回ApacheからMySQLへの接続はUNIXドメインソケット経由となり、ネットワーク経由ではありませんので不要です。

# setsebool -P httpd_can_connect_zabbix=on
# setsebool -P zabbix_can_network=on

ポリシー作成に必要なパッケージをインストールします。

# yum install -y policycoreutils-python selinux-policy-devel

単純にZabbix Serverを起動すると、/var/run/zabbix/配下に各種ソケットファイルが作成できないとのエラーが発生しますので、そちらを許可するポリシーを作成します。

# cat zabbix-server_local.te
module zabbix-server_local 1.0;

require {
        type zabbix_var_run_t;
        type zabbix_t;
        class sock_file create;
        class sock_file unlink;
        class unix_stream_socket connectto;
}

#============= zabbix_t ==============
allow zabbix_t zabbix_var_run_t:sock_file create;
allow zabbix_t self:unix_stream_socket connectto;
allow zabbix_t zabbix_var_run_t:sock_file unlink;

作成したポリシーファイルをビルドしてインストールします。

# make -f /usr/share/selinux/devel/Makefile zabbix-server_local.pp
# semodule -i zabbix-server_local.pp

通常はここまで実施すればZabbix Server自身の稼働には問題ないのですが、Template DB MySQLを適用してMariaDBの状態を監視しようとするとエラーになります。

具体的にはmysql UNIXドメインソケットに接続できない、my.cnfファイルが読み込めずにmysqlコマンドを実行できないため、これらを許可するポリシーを作成します。

# cat zabbix-agentd_local.te
module zabbix-agentd_local 1.0;

require {
        type mysqld_etc_t;
        type mysqld_home_t;
        type mysqld_t;
        type zabbix_agent_t;
        class unix_stream_socket connectto;
        class file open;
        class file read;
}

#============= zabbix_agent_t ==============
allow zabbix_agent_t mysqld_etc_t:file open;
allow zabbix_agent_t mysqld_etc_t:file read;
allow zabbix_agent_t mysqld_home_t:file open;
allow zabbix_agent_t mysqld_home_t:file read;
allow zabbix_agent_t mysqld_t:unix_stream_socket connectto;

また、zabbixユーザーが使用する.my.cnfは/var/lib/zabbix/.my.cnfに配置しますので、こちらのファイルタイプがmysqld_home_tになるようにファイルコンテキストも作成します。

# cat zabbix-agentd_local.fc
/var/lib/zabbix/\.my\.cnf -- unconfined_u:object_r:mysqld_home_t:s0

teファイル、fcファイル両方揃ったところでビルドしインストールします。

# make -f /usr/share/selinux/devel/Makefile zabbix-agentd_local.pp
# semodule -i zabbix-agentd_local.pp

これでMySQL監視もおこなえるようになりました。

導入したポリシーモジュールは以下のプライオリティ400のものになります。

# semodule -lfull|grep zabbix
400 zabbix-agentd_local pp
400 zabbix-server_local pp
100 zabbix              pp

ocf:heartbeat:apacheでZabbixのレスポンスチェックではまった

 article  Comments Off on ocf:heartbeat:apacheでZabbixのレスポンスチェックではまった
Sep 282018
 

CentOS 7.5のPacemaker/Corosync環境でZabbix 4.0のHA構成を試していていたら、ocf:heartbeat:apacheを使ったhttpdの起動がうまくいかなかった。
クラスターリソースは以下で作成している。

pcs resource create WebSite ocf:resource:apache statusurl="http://localhost/zabbix/" client=curl

Apacheのアクセスログではステータスコード200も返っているのに、なんでかなと思ったら、返答されるHTMLの終端タグ</html>が含まれていないからだった(curl http://localhost/zabbix/の応答が</body>で終わってる)。

pcs resource update WebSite testregex="< *html *>"

とやって解決。

CentOS 7.1でZabbix Server 2.4.4がsegfault

 article  Comments Off on CentOS 7.1でZabbix Server 2.4.4がsegfault
Apr 062015
 

CentOS 7で動かしていたZabbix Server 2.4.4が起動しなくなりました。segfaltしている模様です。

[root@localhost ~]# systemctl status zabbix-server.service
zabbix-server.service - Zabbix Server
   Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled)
   Active: failed (Result: start-limit) since Tue 2015-04-05 23:23:56 JST; 7min ago
  Process: 18642 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=killed, signal=SEGV)

Apr 05 23:23:56 localhost systemd[1]: zabbix-server.service: control process exited, code=killed status=11
Apr 05 23:23:56 localhost systemd[1]: Failed to start Zabbix Server.
Apr 05 23:23:56 localhost systemd[1]: Unit zabbix-server.service entered failed state.
Apr 05 23:23:56 localhost systemd[1]: zabbix-server.service holdoff time over, scheduling restart.
Apr 05 23:23:56 localhost systemd[1]: Stopping Zabbix Server...
Apr 05 23:23:56 localhost systemd[1]: Starting Zabbix Server...
Apr 05 23:23:56 localhost systemd[1]: zabbix-server.service start request repeated too quickly, refusing to start.
Apr 05 23:23:56 localhost systemd[1]: Failed to start Zabbix Server.
Apr 05 23:23:56 localhost systemd[1]: Unit zabbix-server.service entered failed state.
[root@localhost ~]# dmesg
[335292.404381] zabbix_server[18567]: segfault at 18 ip 00007fb071057c00 sp 00007fff73f4b3b8 error 4 in libpthread-2.17.so[7fb07104e000+16000]
[335292.405914] zabbix_server[18569]: segfault at 18 ip 00007fb071057c00 sp 00007fff73f4b3b8 error 4 in libpthread-2.17.so[7fb07104e000+16000]
[335292.621060] zabbix_server[18617]: segfault at 18 ip 00007fbb3753ec00 sp 00007fffdcf66fb8 error 4 in libpthread-2.17.so[7fbb37535000+16000]
[335292.626269] zabbix_server[18615]: segfault at 18 ip 00007fbb3753ec00 sp 00007fffdcf66fb8 error 4 in libpthread-2.17.so[7fbb37535000+16000]
[335292.751505] zabbix_server[18628]: segfault at 18 ip 00007f2653115c00 sp 00007fffbaf569e8 error 4 in libpthread-2.17.so[7f265310c000+16000]
[335292.752712] zabbix_server[18630]: segfault at 18 ip 00007f2653115c00 sp 00007fffbaf569e8 error 4 in libpthread-2.17.so[7f265310c000+16000]
[335292.878242] zabbix_server[18635]: segfault at 18 ip 00007f3c927ccc00 sp 00007fffa83ec778 error 4 in libpthread-2.17.so[7f3c927c3000+16000]
[335292.880241] zabbix_server[18637]: segfault at 18 ip 00007f3c927ccc00 sp 00007fffa83ec778 error 4 in libpthread-2.17.so[7f3c927c3000+16000]
[335293.004628] zabbix_server[18642]: segfault at 18 ip 00007f717b2d7c00 sp 00007fffcb6b7db8 error 4 in libpthread-2.17.so[7f717b2ce000+16000]
[335293.005836] zabbix_server[18644]: segfault at 18 ip 00007f717b2d7c00 sp 00007fffcb6b7db8 error 4 in libpthread-2.17.so[7f717b2ce000+16000]
[root@localhost ~]#

以下の状況と同じようです。
[ZBX-7790] zabbix_server_m[13777]: segfault at 18 ip 00007fe6639a8fe0 sp 00007fffbb66e498 error 4 in libpthread-2.18 – crash in "main" process – ZABBIX SUPPORT
trousersパッケージの削除かgnutlsのダウングレードで解決するようですが、trousersを削除するとpacemakerも削除されるので今回はgnutlsをダウングレード。

[root@localhost ~]# rpm -Uvh --force http://ftp.iij.ad.jp/pub/linux/centos/7.0.1406/updates/x86_64/Packages/gnutls-3.1.18-10.el7_0.x86_64.rpm
Retrieving http://ftp.iij.ad.jp/pub/linux/centos/7.0.1406/updates/x86_64/Packages/gnutls-3.1.18-10.el7_0.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:gnutls-3.1.18-10.el7_0           ################################# [ 50%]
Cleaning up / removing...
   2:gnutls-3.3.8-12.el7              ################################# [100%]
[root@localhost ~]#

無事起動しました。

[root@localhost ~]# systemctl start zabbix-server
[root@localhost ~]# systemctl status zabbix-server
zabbix-server.service - Zabbix Server
   Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled)
   Active: active (running) since Tue 2015-04-05 23:42:45 JST; 5s ago
  Process: 30941 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
 Main PID: 30943 (zabbix_server)
   CGroup: /system.slice/zabbix-server.service
           ├─30943 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
           ├─30948 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
           ├─30949 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.012501 sec, idle 60 sec]
           ├─30950 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000041 sec, idle 5 sec]
           ├─30951 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000036 sec, idle 5 sec]
           ├─30952 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000050 sec, idle 5 sec]
           ├─30953 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000032 sec, idle 5 sec]
           ├─30954 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000034 sec, idle 5 sec]
           ├─30955 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000052 sec, idle 5 sec]
           ├─30956 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
           ├─30957 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
           ├─30958 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
           ├─30959 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
           ├─30965 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
           ├─30966 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000007 sec, idle 5 sec]
           ├─30968 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.000708 sec, idle 30 sec]
           ├─30969 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
           ├─30970 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 15 sec]
           ├─30971 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000903 sec, idle 5 sec]
           ├─30974 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000813 sec, idle 60 sec]
           ├─30975 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000002 sec, idle 5 sec]
           ├─30976 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000002 sec, idle 5 sec]
           ├─30980 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 5 sec]
           ├─30981 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000002 sec, idle 5 sec]
           ├─30982 /usr/sbin/zabbix_server: escalator [processed 0 escalations in 0.000626 sec, idle 3 sec]
           ├─30985 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000005 sec, idle 5 sec]
           └─30986 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000006 sec, idle 1 sec]

Apr 05 23:42:45 localhost systemd[1]: Started Zabbix Server.
[root@localhost ~]#

ZabbixサーバーをHA化

 article  Comments Off on ZabbixサーバーをHA化
Jul 232014
 

CentOS 6.4で、repo.zabbix.comからzabbix-server-mysqlとzabbix-web-mysqlをインストールして稼働している状態から、PacemakerとDRBDを使ったHA化をおこなってみます。

まずはPacamakerの管理対象となるサービスを停止し、自動起動も無効化します。

for s in httpd zabbix-server mysqld; do
 service $s stop
 chkconfig $s off
done

クラスターパッケージ群を導入します。

yum install pacemaker cman pcs ccs resource-agents

DRBDはELrepoから導入します。

pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs property set migration-threshold=1
pcs property set cluster-recheck-interval=5m

DRBDのリロース設定をおこないます。

pcs -f cfg-drbd resource create drbd0 ocf:linbit:drbd drbd_resource=r0
pcs -f cfg-drbd resource add_operation drbd0 start interval=0 timeout=240s
pcs -f cfg-drbd resource add_operation drbd0 promote interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 demote interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 noftify interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 stop interval=0 timeout=100s
pcs -f cfg-drbd resource add_operation drbd0 monitor interval=20s timeout=20s role=Slave
pcs -f cfg-drbd resource add_operation drbd0 monitor interval=10s timeout=20s role=Master
pcs -f cfg-drbd master drbd0-clone drbd0 master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
pcs push cfg-drbd

DRBD領域をマウントするファイルシステムリソース設定をおこないます(fs-data)。

pcs -f cfg-fs1 resource create fs-data Filesystem device=/dev/drbd/by-res/r0 directory=/data fstype=ext4 options=noatime
pcs -f cfg-fs1 resource add_operation fs-data start interval=0 timeout=60s
pcs -f cfg-fs1 resource add_operation fs-data stop interval=0 timeout=60s
pcs -f cfg-fs1 resource add_operation fs-data monitor interval=20s timeout=40s
pcs -f cfg-fs1 constraint colocation add fs-data drbd0-clone INFINITY with-rsc-role=Master
pcs -f cfg-fs1 constraint order promote drbd0-clone then start fs-data
pcs push cfg-fs1

MySQLデータベースをDRBD領域配下に移動します。

mv /var/lib/mysql /data/
mkdir /var/lib/mysql
chown mysql: /var/lib/mysql
chmod 755 /var/lib/mysql

MYSQLデータベース領域をマウントするファイルシステムリソース設定をおこないます(fs-mysql)。

pcs -f cfg-fs2 resource create fs-mysql Filesystem device=/data/mysql directory=/var/lib/mysql fstype=ext4 options=bind
pcs -f cfg-fs2 resource add_operation fs-mysql start interval=0 timeout=60s
pcs -f cfg-fs2 resource add_operation fs-mysql stop interval=0 timeout=60s
pcs -f cfg-fs2 resource add_operation fs-mysql monitor interval=20s timeout=40s

fs-dataとfs-mysqlリソースが同一ノードで動作するようにgroup設定を施したうえで反映させます。

pcs -f cfg-fs2 resource group add group0 fs-data fs-mysql
pcs push cfg-fs2

—–

pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs property set migration-threshold=1
pcs property set cluster-recheck-interval=5m

Pacamakerの管理対象となるサービスを停止します。

for s in httpd zabbix-server mysqld; do
 service $s stop
 chkconfig $s off
done

DRBDのリロース設定をおこないます。

pcs -f cfg-drbd resource create drbd0 ocf:linbit:drbd drbd_resource=r0
pcs -f cfg-drbd resource add_operation drbd0 start interval=0 timeout=240s
pcs -f cfg-drbd resource add_operation drbd0 promote interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 demote interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 noftify interval=0 timeout=90s
pcs -f cfg-drbd resource add_operation drbd0 stop interval=0 timeout=100s
pcs -f cfg-drbd resource add_operation drbd0 monitor interval=20s timeout=20s role=Slave
pcs -f cfg-drbd resource add_operation drbd0 monitor interval=10s timeout=20s role=Master
pcs -f cfg-drbd master drbd0-clone drbd0 master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
pcs push cfg-drbd

DRBD領域をマウントするファイルシステムリソース設定をおこないます(fs-data)。

pcs -f cfg-fs1 resource create fs-data Filesystem device=/dev/drbd/by-res/r0 directory=/data fstype=ext4 options=noatime
pcs -f cfg-fs1 resource add_operation fs-data start interval=0 timeout=60s
pcs -f cfg-fs1 resource add_operation fs-data stop interval=0 timeout=60s
pcs -f cfg-fs1 resource add_operation fs-data monitor interval=20s timeout=40s
pcs -f cfg-fs1 constraint colocation add fs-data drbd0-clone INFINITY with-rsc-role=Master
pcs -f cfg-fs1 constraint order promote drbd0-clone then start fs-data
pcs push cfg-fs1

MySQLデータベースをDRBD領域配下に移動します。

mv /var/lib/mysql /data/
mkdir /var/lib/mysql
chown mysql: /var/lib/mysql
chmod 755 /var/lib/mysql

MYSQLデータベース領域をマウントするファイルシステムリソース設定をおこないます(fs-mysql)。

pcs -f cfg-fs2 resource create fs-mysql Filesystem device=/data/mysql directory=/var/lib/mysql fstype=ext4 options=bind
pcs -f cfg-fs2 resource add_operation fs-mysql start interval=0 timeout=60s
pcs -f cfg-fs2 resource add_operation fs-mysql stop interval=0 timeout=60s
pcs -f cfg-fs2 resource add_operation fs-mysql monitor interval=20s timeout=40s

fs-dataとfs-mysqlリソースが同一ノードで動作するようにgroup設定をおこないます。

pcs -f cfg-fs2 resource group add group0 fs-data fs-mysql
pcs push cfg-fs2

Zabbix server is not running: the information displayed may not be current

 article  Comments Off on Zabbix server is not running: the information displayed may not be current
Jul 162013
 

CentOS 6.4にrepo.zabbix.comからパッケージを導入して。
zabbix_serverプロセスは動いているし、10051ポートもLISTENしている。
/etc/zabbix/web/zabbix.conf.phpも間違いない。

$ZBX_SERVER                     = 'localhost';
$ZBX_SERVER_PORT                = '10051';

SELinux有効な環境下では(ちなみにtargetedポリシーを素のまま利用)

setsebool -P httpd_can_network_connect=true

を実施する必要があった。

Zabbix server is not running: the information displayed may not be current – ZABBIX Forums

Zabbixデータ量推移 ~ 1週間目

 article  Comments Off on Zabbixデータ量推移 ~ 1週間目
Mar 012011
 

Amazon EC2上で動かしているZabbixのテーブルサイズ推移を計測中です。
計測しているデータは

  • MySQLテーブルのサイズ – information_schemaのdata_length値
  • テーブルファイルのサイズ – Per-Tableテーブルスペースでの.idbファイルサイズ

それぞれMuninのmysql table size pluginlog_sizes pluginを使っています。
Zabbixでの取得item数は110項目ほどで、9割方の項目がhistory=7/trends=365/delay=60の設定になっています。

1週間経過してのデータ量推移は以下のようになりました。全テーブル分のデータを取得しているのでグラフが冗長ですが、Zabbixがデータを累積するのはhistory系とtrends系のテーブルですので、そちらに着目していただけるとわかりやすいかと思います。

mysql_table_size推移

mysql_table_size推移


file_sizes推移

file_sizes推移

テーブルサイズ、ファイルサイズともにhistoryとhistory_uintが増加し続け、history保存期限の1週間を経過したところからほぼ横ばいになりました。
ちなみにHousekeepingFrequencyは1です(Ubuntu 10.10パッケージデフォルト)。

正直言うと、レコード追加と削除の繰り返しでテーブルの断片化が進み、テーブルサイズは横ばいだがファイルサイズは増え続けるような状況を予想していたのですが、削除レコードの領域も上手に再利用されているようです。
定期的にALTER TABLE ~ TYPE=InnoDBを実行して断片化解消しなきゃダメなのかな、と思っていたのですが、サイズ傾向だけで見る限りではそんな必要もなさそうです。InnoDBの断片化状況ってどうやったら判断できるんでしょう 😕

まぁ、単にデータ量だけで考えれば、これ以降はtrendsとtrends_uintがじわじわと増えていって、それも1年後に横ばいになるってことなのでしょうね 😉

EC2を1年以上継続利用する予定は今のところないのですが、気が向いたら1ヶ月後ぐらいに再度状況アップするかも知れません。

Zabbix history vs trends

 article  Comments Off on Zabbix history vs trends
Feb 252011
 

Zabbixのhistoryとtrendsの違いに関して、Forumにトピックがあったのでメモ。
History vs trends – ZABBIX Forums

なんとなくhistoryはitemで取得した生データ、trendsはhistoryを一定期間で丸めたデータ、と勝手に解釈していましたが、おおよそ間違いではなかったようです。

The history tables store the data as is, the trends tables store that data as a 30 minute trend average with min and max values,

trendsは30分間隔での平均値、最小値、最大値とのこと。

ただ、trendsへのデータ保存はhistoryから削除するHouseKeepingのタイミングで実施しているのだろうと思っていたのですけれど、そこは勘違いしていました。
zabbix_server/housekeeper/housekeeper.cのhousekeeping_history_and_trends()をみても、削除はhistoryもtrendsも同じようにおこなっていてhistoryからtrendsへの移送などはおこなっていません。

で、グラフで表示する値は24時間以内であればhistoryを使い、それより長い期間の場合はtrendsを使うとのことです。

ZABBIX generates all graphs are generated from detailed history if period is less than 24 hours, and the trends are used for graphs having period longer than 24 hours.

Zabbixでディスク容量監視を1項目に限定するとしたら

 article  Comments Off on Zabbixでディスク容量監視を1項目に限定するとしたら
Dec 192010
 

Zabbixのディスク容量監視で取得できるキーにはtotal, used, free, pused, pfreeの5項目あります。
totalは別にして、容量不足だけを監視したいのならどれか1項目でもなんとかなるはずです。
最低限取得するとしたら、Zabbixの負荷的にどれが一番効率がいいのか、ソースを見てみました。

zabbix-1.8.3/src/libs/zbxsysinfo/linux/diskspace.c

        if (free)
                *free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
        if (used)
                *used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
        if (pfree)
        {
                if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
                        *pfree = (double)(100.0 * s.f_bavail) /
                                        (s.f_blocks - s.f_bfree + s.f_bavail);
                else
                        *pfree = 0;
        }
        if (pused)
        {
                if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
                        *pused = 100.0 - (double)(100.0 * s.f_bavail) /
                                        (s.f_blocks - s.f_bfree + s.f_bavail);
                else
                        *pused = 0;
        }

ちなみにs構造体に入ってくる値はstatvfs()かstatfs()でまとめて取得するようになっています。

計算の少なさでfreeの勝ち。次点はusedでした。
ただ閾値設定をファイルシステム毎にサイズ指定することになってしまうので、pfreeかpusedで値を取得、パーセンテージで監視するのが一番かもしれません。pfreeかpusedどちらかを取るならpfreeのほうが若干計算少ないです。

コードの単純さだけを比較すれば、サイズとパーセンテージではサイズが有利、freeかusedではfreeが有利ということになります。

ZABBIXのデータ収集間隔を最小300秒に一括変更

 article  Comments Off on ZABBIXのデータ収集間隔を最小300秒に一括変更
Nov 252009
 

ZABBIXでのデータ収集間隔はデフォルト5秒といったアイテムもあり、そのまま多数のノード監視に適用するとサーバー負荷が高くなりやすい。
面倒なのでitemsテーブルのdelay値を一括変更した。

# psql zabbix zabbix
Password for user zabbix: ********
psql (8.4.1)
Type "help" for help.

zabbix=> update items set delay=300 where delay<300;
UPDATE 4003
zabbix=> 

これで300秒未満に設定されているデータ収集間隔は全て300秒に変更される。