zabbix配置安装

一、LNMP环境安装

1、依赖库yum安装

yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel   pcre pcre-devel libtool-ltdl-devel libxml2-devel curl-devel  libjpeg-devel  libpng-devel  freetype-devel openldap openldap-devel ldap-devel libevent libevent-devel libiconv libmcrypt libmcrypt-devel

2、安装nginx

tar -zxvf nginx-1.10.2.tar.gz     
cd nginx-1.10.2
useradd www
./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --user=www --group=www --with-pcre
make  && make install
/usr/local/nginx/sbin/nginx 

3、安装libmcrypt

tar -zxvf libmcrypt-2.5.8.tar.gz   
cd libmcrypt-2.5.8
./configure
make && make install

4、安装php

tar -zxvf php-7.0.13.tar.gz 
cd php-7.0.13
cp -frp /usr/lib64/libldap* /usr/lib/
 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --disable-rpath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbstring --with-mcrypt --with-openssl --enable-soap --enable-shmop --enable-sockets --enable-pcntl --with-mhash --with-pdo-mysql --with-mysql-sock --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-gd --with-libmemcached-dir=/usr/local --enable-memcached --enable-apc --enable-static  --without-pear --with-ldap-sasl --with-ldap --enable-gd-native-ttf --enable-mbregex --enable-sysvsem --enable-bcmath --enable-safe-mode --enable-opcache=no --with-gettext
make && make install
cp php.ini-production  /usr/local/php/etc/php.ini-p
cd /usr/local/php/etc/
cp php.ini-p php.ini
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
vim /etc/init.d/nginxd

#########复制下面内容到文件中###############

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: 345 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_conf=/usr/local/nginx/conf/nginx.conf
fcgi=/usr/local/php/sbin/php-fpm
fcgi_conf=/usr/local/php/etc/php-fpm.conf

RETVAL=0
prog="nginx"

[ -x $nginxd ] || exit 0
[ -x $fcgi ] || exit 0

# Start nginx daemons functions.
start() {
	test
	export LD_PRELOAD=/usr/local/lib/libtcmalloc_minimal.so
	nginx_pid=`ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
	fpm_pid=`ps ajxwww | grep php-fpm | grep Ss | awk '{print $2}'`

	if [ -z $fpm_pid ]
	then
		$fcgi -y $fcgi_conf || echo -n " already running"
	fi

	if [ -z $nginx_pid ]
	then
		echo -n "Starting nginx: "
		#ulimit -SHn 51200
		$nginxd -c $nginx_conf
		RETVAL=$?
		msg="OK"
		if [ $RETVAL -ne 0 ]
		then
			msg="FAILED"
		fi
		echo $msg
	else
		echo "nginx already running"
	fi
	unset LD_PRELOAD
	return $RETVAL
}

# Stop nginx daemons functions.
stop() {
	test
	nginx_pid=`ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
	if [ -z $nginx_pid ]
	then
		echo "nginx not running"
	else
		echo -n "Stopping nginx: "
		kill `ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
		RETVAL=$?
		msg="OK"
		if [ $RETVAL -ne 0 ]
		then
			msg="FAILED"
		fi
		echo $msg
	fi
	
	#$fcgi 
	fpm_pid=`ps ajxwwww | grep php-fpm | grep Ss | awk '{print $2}'`
	if [ -z $fpm_pid ]
	then
		echo "php-fpm not running"
	else
		#$fcgi stop
		kill -QUIT $fpm_pid
		
	fi
	return $RETVAL	
}

quit() {
	nginx_pid=`ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
	if [ -z $nginx_pid ]
	then
		echo "nginx not running"
	else
		echo -n "Stopping nginx: "
		kill -QUIT `ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
		RETVAL=$?
		msg="OK"
		if [ $RETVAL -ne 0 ]
		then
			msg="FAILED"
		fi
		echo $msg
	fi
	
	#$fcgi 
	fpm_pid=`ps ajxwwww | grep php-fpm | grep Ss | awk '{print $2}'`
	if [ -z $fpm_pid ]
	then
		echo "php-fpm not running"
	else
		kill -QUIT $fpm_pid 
		#$fcgi quit
	fi
	return $RETVAL	
}

test() {
	$nginxd -t -c $nginx_conf || exit
}

reload() {
	test
	nginx_pid=`ps ajxwww | grep nginx | grep Ss | awk '{print $2}'`
	fpm_pid=`ps ajxwwww | grep php-fpm | grep Ss | awk '{print $2}'`
	if [ -z $nginx_pid ]
	then
		echo "nginx not running"
	else
    	echo -n "Reloading $prog: "
    	kill -HUP $nginx_pid 
		RETVAL=$?
		msg="OK"
		if [ $RETVAL -ne 0 ]
		then
			msg="FAILED"
		fi
		echo $msg
	fi

	if [ -z $fpm_pid ]
	then
		echo "php-fpm not running"
	else
		#$fcgi reload
		kill -HUP $fpm_pid || echo -n " can't reload"
	fi
    #RETVAL=$?
}

# See how we were called.
case "$1" in
start)
        start
        ;;
quit)
		quit
		;;
test)
		test
		;;
stop)
        stop
        ;;


reload)
        reload
        ;;
restart)
        stop
	sleep 3
        start
        ;;
*)
        echo "Usage: $prog {start|stop|restart|reload|quit|test|help}"
        exit 1
esac
exit $RETVAL

############文件内容结束##############

chmod 755 /etc/init.d/nginxd
chkconfig nginxd on
service nginxd restart

5、缺少 libtcmalloc_minimal.so解决办法

下载 libunwind-0.99.tar.gz
https://download.csdn.net/download/zhangxueleishamo/10392485 
tar -zxvf libunwind-0.99.tar.gz 
cd libunwind-0.99
./configure 
make && make install
tar -zxvf gperftools-2.4.tar.gz 
 ./configure  
make && make install
二、下载zabbix并安装

1、下载

wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.2/zabbix-3.4.2.tar.gz/download --no-check-certificate
tar -zxvf zabbix-3.4.2.tar.gz 
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin

2、配置zabbix的mysql用户

mysql -uroot -p
#创建zabbix库,注如没有utf8mb4字符集,使用utf8
CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
#导入数据表结构
mysql> use zabbix;
mysql> source /soft/zabbix-3.4.2/database/mysql/schema.sql;
mysql> source /soft/zabbix-3.4.2/database/mysql/data.sql;
mysql> source /soft/zabbix-3.4.2/database/mysql/images.sql;
mysql> quit
3、编译安装zabbix
cd zabbix-3.4.2
yum install -y net-snmp net-snmp-devel curl curl-devel mysql-devel libevent-devel pcre-devel
 ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy
make && make install
mkdir /usr/local/zabbix/logs
mv zabbix_agentd.conf zabbix_agentd.conf.bak

    vim zabbix_agentd.conf

#cd /usr/local/zabbix/etc/
#mv zabbix_agentd.conf zabbix_agentd.conf.bak
#vim zabbix_agentd.conf
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

    vim zabbix_server.conf

#mv zabbix_server.conf zabbix_server.conf.bak
#vim zabbix_server.conf
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBHost=localhost
DBPassword=123456       #(zabbix用户的密码)
AlertScriptsPath=/usr/local/zabbix/alertscripts

    创建自定义脚本目录,设置权限,目录下的脚本,可以被zabbix调用

    mkdir /usr/local/zabbix/alertscripts

    chown zabbix.zabbix -R /usr/local/zabbix

sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php/etc/php.ini

    vim /usr/local/php/etc/php.ini

cgi.fix_pathinfo=1

    service nginxd restart

4、由于zabbix_server 服务不支持 chkconfig,使用下列方法自启动 
    vim /etc/init.d/zabbix_server 

    在#!/bin/sh下面一行添加

#chkconfig: 345 95 95       ##这里再配置文件里面行首“#”表示注释
#description: Zabbix_Server     ##这里再配置文件里面行首“#”表示注释

    vim /etc/init.d/zabbix_agentd 

#chkconfig: 345 95 95       ##这里是在配置文件里面行首“#”表示注释,
#description: Zabbix_agentd     ##这里再配置问价里面行首“#”表示注释

     chkconfig zabbix_server on

     chkconfig zabbix_agentd on

    /etc/init.d/zabbix_server start

    /etc/init.d/zabbix_agentd start

    netstat -ntpl|grep zabbix

tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      42548/zabbix_agentd 
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      43444/zabbix_server

 5、注:如果10051端口没有启动,查看日志

 35053:20180504:172050.328 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    连接数据库失败,设置mysql.sock

    vim /usr/local/zabbix/etc/zabbix_server.conf

DBSocket=/tmp/mysql.sock

    然后重启zabbix_server即可

5、复制php页面,设置权限

#cp -rf /soft/zabbix-3.4.2/frontends/php/ /usr/local/zabbix/php
#chown www.www -R /usr/local/zabbix/php/

6、编辑nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

server {
        listen   80;
        server_name localhost;
        root /usr/local/zabbix/php;
        index index.php index.html index.htm;

        location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php/$1  last;
                break;
            }
        }

        location ~ \.php {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                include        fastcgi_params;
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                   set $real_script_name $1;
                   set $path_info $2;
                }

                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name
;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
        }

}

7、编辑php配置文件,开启中文支持

vim /usr/local/zabbix/php/include/locales.inc.php 

'zh_CN' => ['name' => _('Chinese (zh_CN)'),     'display' => true],

    重启nginx服务

    service nginxd restart

8、网页访问,开始安装:

    http://103.17.42.86/setup.php





 9、安装成功,登陆,修改成中文




三、监控服务器,创建主机

1、configuration(配置)-->Hosts(主机)-->Create host(创建主机)



Host name:主机名,只允许数字、空格、句号、下划线,非主流符号不支持,与客户端配置文件中host name名称必须一致

Visible name:显示名称,可选项。 主机名的别名。

Groups:主机要加入的组,一个主机至少要加入一个组。

interfaces:端口。zabbix agent默认为10050,snmp161,jmx 12345 ,IMPI623

2、配置模版 Templates


3、查看主机列表。 绿色ZBX表示成功监控了这台客户端


4、添加组名

configuration(配置)--->Host Groups(组)--->Create Host Group(创建主机组),录入如下图:


Group name:组名,必须唯一

四、在zabbix被监控客户端的配置

1、linux下安装配置。下载zabbix-agent

wget http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-agent-3.4.4-2.el6.x86_64.rpm
yum -y install  zabbix-agent-3.4.4-2.el6.x86_64.rpm

     vim /etc/zabbix/zabbix_agentd.conf

Server=172.20.38.86                #zabbix服务器的ip
ServerActive=172.20.38.86          #zabbix上添加的名称
Hostname=172.20.38.95              #被监控端的ip地址

    /etc/init.d/zabbix-agent start

2、windows下安装配置。下载zabbix-agent

    https://assets.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip


    复制复合服务器要求的文件到c:\zabbix下


    将配置文件zabbix_agentd.win.conf 拷贝到c:\zabbix下并修改文件,更改名字为zabbix_agentd.conf

LogFile=c:\zabbix\zabbix_agentd.log
Server=172.20.38.86
ServerActive=172.20.38.98
Hostname=172.20.38.98

    进入bat命令行,输入以下命令安装

cd c:\zabbix
zabbix_agentd.exe -c c:\zabbix\zabbix_agentd.conf -i

    启动客户端agent


    在win服务管理器中


    以上linux和win下面客户端配置完成。

五、查看监控数据

1、最新数据  检测中(Monitoring)-最新数据(Lastest data)


 选择 主机群组Host groups或 主机Hosts  后 应用 Apply 可显示最新数据 lastest data,如下图


2、图表数据  检测中(Monitoring)-图表数据(Graphs)-选择 主机组或主机 -图形


六、zabbix用户管理

1、创建用户



2、报警媒介、权限设置



七、中文乱码解决

1、乱码如下图


2、下载 simkai.ttf  文件,上传到zabbix网站目录fonts下


3、修改zabbix的php文件

sed -i  's/DejaVuSans/simkai/g' /usr/local/zabbix/php/include/defines.inc.php 

4、其他问题  初始化数据库的时候未使用utf8编码所致.初始化数据库使用命令

在my.cnf文件中增加

default-character-set = utf8

5、修改完后显示图


八、监控项item

Items 是从主机里面获取的所有数据。

item由key+参数组成。

1、创建监控项

点击配置(configuration)->主机(Hosts)->在你要配置的主机一栏上点击 监控项(Items)->点击创建监控项create item。具体看截图,各个参数我都已经标注清楚了。


2、Item属性详解

属性 描述
Host 主机或者模板
Name 监控项item名称可以使用如下宏变量:

$1, $2…$9,这9个参数对应item key的参数位置。

例如: Free disk space on $1

如果item key为“vfs.fs.size[/,free]”,那么对应的名称会变成”Free disk space on /“,$1对应了第一个参数”/“,你明白了吗?

Type item类型(常见agent、SNMP、agent(active)等),请看后续监控项类型相关文章.
Key 监控项item的key.点击select可以看到系统很多自带的key,也可以看到用户自定义的key,如何自定义key,情继续关注ttlsa后续的zabbix教程.
Host interface 主机接口,例如agent、SNMP、impi等
Type of information 获取到得数据类型

Numeric (unsigned) – 64bit unsigned integer

Numeric (float) – floating point

numberCharacter – 字符串,最长255字节

Log – 日志文件. key必须为log[].

Text – 大小无限制的文本

Data type 定义获取到整数数据的数据类型

Boolean – 数据为0或者1.’true’表示1,’false’为0,不区分大小写。

如下为True和False的定义:

TRUE – true, t, yes, y, on, up, running, enabled, available

FALSE – false, f, no, n, off, down, unused, disabled, unavailable

任何非0数字都被认为是TRUE,0被定义为FALSE.负数呢?

Octal – 八进制

Decimal – 十进制

Hexadecimal – 十六进制

zabbix将会自动把他们转为数字

Units 默认情况下,如果原始值超过1000,那么他会先除以1000并且显示出来例如,设置了单位为bps并且收到的值为11102,将会显示为11.1Kbps

如果单位被指定为 B (byte), Bps (bytes per second) ,那么它会除以1024然后再显示数据。所以大家在监控流量和文件大小的时候不要用错单位,否则会出现数据不一致的情况。

如下为时间单位:

unixtime – 转为 “yyyy.mm.dd hh:mm:ss”. 只能使用正数。

uptime – 转为“hh:mm:ss” 或者“N days, hh:mm:ss”

例如,收到的值为881764秒,他将会显示为“10 days, 04:56:04”

s – 转为“yyy mmm ddd hhh mmm sss ms”;

例如,收到的值为881764(单位秒),他将会被显示为10d 4h 56m”,只会显示3个单元。有时候只会显示2个单元,例如”1m 5h”(不包含分,秒,毫秒),如果返回的值小于0.001,他只会显示”<1 ms”禁用单位:ms、rpm、RPM、%

Use custom multiplier 如果启用这个选项,所有接收到的整数或者浮点数都会乘以这个文本框里面的值。使用这个选项,zabbix将会把收到的KB,MBps等数据先转为B,Bps。否则zabbix不能正确设置前缀(K,M,G等等).

zabbix 2.2开始支持科学计数法,例如:1e+70.

Update interval (in sec) 数据更新时间注意:如果设置为0,那么这个数据将永久不更新。但是如果在灵活更新间隔(flexible interval)里面设置了一个非0间隔,那么以这个为准
Flexible intervals 可以创建例外的更新间隔,例如:

Interval:10,Period:1-5,10:00-19:00,表示周一到周五的早上10点到晚上19点每十秒更新一次数据。其余时间使用默认值。这边最多只能设置7个灵活更新间隔.如果设置的多个灵活时间间隔有冲突,那么他会使用最小的时间间隔。

两个注意点:如果时间间隔被设置为0,那么数据永久不会更新。它不能用在zabbix主动方式的item

Keep history(in days) 历史记录可以在数据库中保存多久,过期的历史数据将会被Housekeeper删除.

从Zabbix2.2开始,这个值可以被一个全局值覆盖:Administrator->General->Housekeeper->勾选Keep history(in days),输入你希望历史记录保留的时间。

zabbix官方推荐大家尽量开启他,尽量使用一个较短的历史记录。如果你想看历史数据的画,你可以将”趋势历史记录Keep trends”的保留时间设置长一点。

Keep trends(in days) 趋势数据(以小时为单位的min,max,avg,count的数据)在数据库中保留时常,过期数据将会被HouseKeeping删除。

从zabbix2.2开始.这个值可以被一个全局值覆盖(请参考上面的Keep history)

备注:趋势数据只能存数字类型数据,字符、日志这些都无法存储。

Store value As is – 数据不作处理

Delta (speed per second) –

计算值公式为 (value-prev_value)/(time-prev_time)

value – 获取到得原始值

value_prev – 上次接收到的值

time – 当前时间

prev_time – 上次接收数据的时间一般用于数据增长的类型,例如:

网卡流量,每次获取到得都是当前网卡总流量。比如第一次给的值是0字节(UNIX时间为1),第二获取到得是3000字节(UNIX时间为31),那么套用公式(3000-0)/(31-30),可以得出数据是100字节/秒

备注:如果当前获取到的值比上一个值更小,那么zabbix会忽略这个值,等待下一次的值

Delta (simple change) –

计算公式为 (value-prev_value),value – 当前值value_prev – 上次获取到得值

Show value 值映射,需要配置数字映射到字符的映射表。例如:

1=>ttlsa.com访问正常。如果key返回的数据为1,那么监控页面不会显示1,而是显示ttlsa.com访问正常。key返回的数据只能为整数,并且不做任何修改保存到数据库中。只有在显示的时候才会根据映射表来展示相应的内容。

Log time format 只可以用在LOG类型中,支持占位符:

y: 年(0001-9999)

M: 月(01-12)

d: 日(01-31)

h: 小时(00-23)

m: 分钟(00-59)

s: 秒(00-59)如果时间搓留空不会被解析。

例如:

如下为zabbix agent日志” 23480:20100328:154718.045 Zabbix agent started. Zabbix 1.8.2 (revision 11211).”前面6个字符是PID,后面更上日期,时间和日志内容,日志时间类为“pppppp:yyyyMMdd:hhmmss”

备注:“p” 与 ”:” 为占位符,除了“yMdhms”不能为占位符,其它任意字符都可以作为占位符

New application 创建一个新的应用
Applications 包含多个应用,例如:

cpu、disk、network,监控项可以属于多个应用

Populates host inventory field 数据自动填充到inventory资产清单的相应属性,前提是你的inventory处于自动模式
Description 监控项的描述
Enabled 是否启用这个监控项.

3、监控项keys列

Key
功能 返回值 参数 描述
agent.hostname
    -  
agent.ping
       
agent.version
zabbix agent版本 字符串 - 例如返回: 1.8.2
kernel.maxfiles
系统支持最大的openfiles 整数    
kernel.maxproc
系统支持最大的进程数量 整数    
log
监控日志文件 Log file – 文件详细路径regexp – 正则encoding – 编码

maxlines – zabbix agent向server或者proxy发送最大的行数。这个参数覆盖配置文件zabbxi_agentd.conf中的’MaxLinesPerSecond’

mode – 可选值: all (默认), skip (跳过处理老数据).mode参数从2.0版本开始支持

output – 可选项,输出格式模板. The \0 escape sequence is replaced with the matched text while an \N(where N=1…9) escape sequence is replaced with Nth matched group (or an empty string if the N exceeds the number of captured groups).

If <output> is left empty

– the whole line containing the matched text is returned. Note that all global regular expression types except ‘Result is TRUE’ always return the whole matched line and the <output> parameter is ignored.

output是2.2中新加入的功能

这个监控项只能设置为 active check(主动模式).如果文件不存在或者没有相应的权限,那么监控项状态会转变为unsupported.示例:

log[/var/log/syslog] log[/var/log/syslog,error] log[/home/zabbix/logs/logfile,,,100]

logrt[file_pattern,<regexp>,<encoding>,<maxlines>,<mode>,<output>]
监控支持轮转的日志 Log file_pattern – 文件绝对路径regexp – 正则表达式encoding – 编码

maxlines – 客户端每秒发送给server的最大行数. 这个参数会覆盖客户端配置文件zabbix_agentd.conf中MaxLinesPerSecond的值

mode – 可选值: all (默认), skip (跳过老数据的处理).

Mode参数从2.0开始支持

output – an optional output formatting template. The \0 escape sequence is replaced with the matched text while an \N(where N=1…9) escape sequence is replaced with Nth matched group (or an empty string if the N exceeds the number of captured groups). If <output> is left empty – the whole line containing the matched text is returned. Note that all global regular expression types except ‘Result is TRUE’ always return the whole matched line and the <output> parameter is ignored. The output parameter is supported from version 2.2.

The item must be configured as an active check. Log rotation is based on the last modification time of files.示例:logrt[“/home/zabbix/logs/^logfile[0-9]{1,3}$”,,,100]

– will match a file like “logfile1″ (will not match “.logfile1″)

 

logrt[“/home/user/logfile_.*_[0-9]{1,3}”,”pattern_to_match”,”UTF-8″,100]

– will collect data from files such “logfile_abc_1” or “logfile__001”.

net.dns[<ip>,zone,<type>,<timeout>,<count>]
检测DNS服务是否开启 0 – DNS挂了 1 – DNS运行中 ip – DNS服务器的ip地址(留空表示使用本地DNS, ignored on Windows)zone – 需要测试的域名type – 记录类型 (默认为 SOA)

timeout (ignored on Windows) – 超时时间(默认1秒)

count (ignored on Windows) – 重试次数 (默认值2)

示例key:net.dns[8.8.8.8,zabbix.com,MX,2,1]type可选值: ANY, A, NS, CNAME, MB, MG, MR, PTR, MD, MF, MX, SOA, NULL, WKS (除了windows), HINFO, MINFO, TXT, SRV

SRV记录从Zabbix agent versions 1.8.6 (Unix) and 2.0.0 (Windows)开始支持Zabbix 2.0

之前的命名方式: net.tcp.dns(目前依旧支持)

net.dns.record[<ip>,zone,<type>,<timeout>,<count>]
执行一个DNS查询 获取DNS查询数据 ip – DNS服务器的ip地址(留空表示使用本地DNS, ignored on Windows)zone – 需要测试的域名type – 记录类型 (默认为 SOA)

timeout (ignored on Windows) – 超时时间(默认1秒)

count (ignored on Windows) – 重试次数 (默认值2)

示例key:net.dns.record[8.8.8.8,ttlsa.com,MX,2,1]type的可选值: ANY, A, NS, CNAME, MB, MG, MR, PTR, MD, MF, MX, SOA, NULL, WKS (except for Windows), HINFO, MINFO, TXT, SRV

SRV记录从Zabbix agent versions 1.8.6 (Unix) and 2.0.0 (Windows)开始支持Zabbix 2.0

之前的命名方式: net.tcp.dns(目前依旧支持)

net.if.collisions[if]
Out-of-window collision Number of collisions 数字 if – 网卡
net.if.discovery
列出网卡. 通常用于低级别的discovery JSON对象   Zabbix agent 2.0开始支持 但是操作系统FreeBSD, OpenBSD and NetBSD上的 Zabbix agent 2.2开始支持
net.if.in[if,<mode>]
网卡入口流量 整数 if – 网卡名称mode – 可用值:bytes – 字节数 (默认)

packets – 包数量

errors – 错误数量

dropped – 丢包数量

示例keys: net.if.in[eth0,errors] net.if.in[eth0]请使用增量存储方式
net.if.out[if,<mode>]
网卡出口流量 整数 if – 网卡名称mode – 可用值:bytes – 字节数 (默认)

packets – 包数量

errors – 错误数量

dropped – 丢包数量

范例keys:net.if.out[eth0,errors] net.if.out[eth0]请使用增量存储方式
net.if.total[if,<mode>]
网卡进/出流量的总和 整数 if – 网卡名称mode – 可用值:bytes – 字节数 (默认)

packets – 包数量

errors – 错误数量

dropped – 丢包数量

范例keys:net.if.total[eth0,errors] net.if.total[eth0]请使用增量存储方式
net.tcp.listen[port]
检测端口是否开启 0 – 未监听1 – 监听中 port – TCP端口 示例:net.tcp.listen[80]linux下的zabbix agent 1.8.4开始支持
net.tcp.port[<ip>,port]
是否可以连接到指定的TCP端口 0 – 无法连接1 – 可以连接 ip – IP地址(默认是 127.0.0.1)port – 端口 范例:net.tcp.port[,80]检测web服务器端口是否运行中

老命名方式: check_port[*]

net.tcp.service[service,<ip>,<port>]
检测服务是否开启,并且端口可用 0 – 服务挂了1 – 服务运行中 service – 如下: ssh, ntp, ldap, smtp, ftp, http, pop, nntp,imap, tcp, https, telnetip – IP地址 (默认127.0.0.1)port– 端口 (默认情况为标准端口号) 示例key:net.tcp.service[ftp,,45] – 检测45端口上得FTP是否运行中Zabbix 1.8.3 支持的版本请使用service.ntp 代替ntp.

https 和telnet 服务从2.0和2.2开始支持

net.tcp.service.perf[service,<ip>,<port>]
检测服务器性能 0 – 服务挂了;seconds – 链接到服务器端口消耗的时间 service – 如下:ssh, ntp, ldap, smtp, ftp, http, pop, nntp,imap, tcp, https, telnetip – IP地址 (默认127.0.0.1)port– 端口 (默认情况为标准端口号) 示例key:net.tcp.service.perf[ssh] – 检测SSH服务器响应速度加密协议检测不被支持 (类似 IMAP端口 993或者POP端口995) .但是我们可以使用net.tcp.service.perf[tcp,<ip>,<port>] 来检测他们.Windows agent不能检测LDAP和HTTPS. Note that the telnet check looks for a prompt (‘:’ at the end).老命名方式: check_service_perf[*]注意:that before Zabbix 1.8.3 version service.ntp should be used instead of ntp. Zabbix 2.0支持 https和telnet服务
net.udp.listen[port]
检测UDP端口是否在监听 0 – 未监听1 – 监听中 port – udp端口 范例:net.udp.listen[68]linux系统的Zabbix agent 1.8.4开始支持
proc.mem[<name>,<user>,<mode>,<cmdline>]
用户进程消耗的内存 内存使用量 (字节单位). name – 进程名 (默认值 “all processes”)user – 用户名 (默认值“all users”)mode– 可选值: avg, max, min, sum (默认)

cmdline – 命令行过滤(正则表达时)

示例keys:proc.mem[,root]– root的进程消耗了多少内存

proc.mem[zabbix_server,zabbix]

– zabbix用户运行的zabbix_server使用了多少内存

proc.mem[,oracle,max,oracleZABBIX] – memory used by the most memory-hungry process running under oracle having oracleZABBIX in its command line

proc.num[<name>,<user>,<state>,<cmdline>]
某用户某些状态的进程的数量 进程数量 name – 进程名称 (默认“all processes”)user – 用户名 (默认 “all users”)state – 可用值: all (默认), run,sleep, zomb

cmdline – 命令行过滤(正则表达时)

示例keys: proc.num[,mysql]– MySQL用户运行的进程数量

proc.num[apache2,www-data]

– www-data运行了多少个apache2进程proc.num[,oracle,sleep,oracleZABBIX] – number of processes in sleep state running under oracle having oracleZABBIX in its command line

备注:Windows系统只支持name和user两个参数

sensor[device,sensor,<mode>]
读取硬件传感器   device – 设备名称sensor – 传感器名称mode – 可选值: avg,

max, min (if this parameter is omitted, device and sensor are treated verbatim).

On Linux 2.4, 读取/proc/sys/dev/sensors.

示例key:sensor[w83781d-i2c-0-2d,temp1] Prior to Zabbix 1.8.4, the sensor[temp1] format was used. On Linux 2.6+, 读取/sys/class/hwmon. On OpenBSD, 读取hw.sensors MIB.示例keys:

sensor[cpu0,temp0] – CPU0的温度

sensor[cpu[0-2]$,temp,avg] – cpu平均温度

Zabbix 1.8.4开始支持OpenBSD

system.boottime
系统启动的时间鹾 整数   unix时间戳
system.cpu.intr
设备中断 整数    
system.cpu.load[<cpu>,<mode>]
CPU负载 浮点数 cpu – 可用值: all (默认), percpu (所有在线cpu的负载)mode – 可用值: avg1 (1分钟 默认值), avg5(5分钟平均), avg15 (15分钟平均值) 范例key:system.cpu.load[,avg5]老命令方式: system.cpu.loadX

参数percpu is Zabbix 2.0.0开始支持

system.cpu.num[<type>]
CPU数量 处理器个数 type – 可用值: online (默认值), max 范例:system.cpu.num
system.cpu.switches
上下文交换 交换次数   老命名方式: system[switches]
system.cpu.util[<cpu>,<type>,<mode>]
CPU利用率 百分比 cpu – cpu数量 (默认是所有cpu)type – 可用值: idle, nice, user (默认), system (windows系统默认值), iowait, interrupt, softirq,stealmode – 可用值: avg1 (一分钟平均,默认值), avg5(5分钟平均, avg15 (15分钟平均值) 范例key:system.cpu.util[0,user,avg5]老命名方式:

system.cpu.idleX, system.cpu.niceX, system.cpu.systemX, system.cpu.userX

system.hostname[<type>]
返回主机名 字符串 type (仅用于windows系统) – 可用值: netbios(默认) or host 例如:on Linux: system.hostname → linux-w7x1 system.hostname → www.zabbix.com on Windows: system.hostname → WIN-SERV2008-I6 system.hostname[host] → Win-Serv2008-I6LonG type参数从zabbix 1.8.6开始支持
system.hw.chassis[<info>]
返回机架信息 字符串 info – full (默认), model, serial, type 或vendor 例如: system.hw.chassis[full] Hewlett-Packard HP Pro 3010 Small Form Factor PC CZXXXXXXXX Desktop] 需要root权限,因为这些信息是从内存中读取的。 Zabbix agent version 2.0 开始支持
system.hw.cpu[<cpu>,<info>]
返回CPU信息 字符/数字 cpu – cpu数量或者all (默认)info – full (默认), curfreq, maxfreq, model 或者vendor 例如:system.hw.cpu[0,vendor]AuthenticAMD 从/proc/cpuinfo、/sys/devices/system/cpu/[cpunum]/cpufreq/cpuinfo_max_freq获取信息. 如果指定了CPU数量和 curfreq或者maxfreq, 将会返回数值(Hz).

Zabbix agent 2.0 开始支持

system.hw.devices[<type>]
列出PCI或者USB 文本值 type – pci (默认) or usb 范例:system.hw.devices[pci]00:00.0 Host bridge: Advanced Micro Devices [AMD] RS780 Host Bridge [..] 返回lspci或者lsusb (不带参数)

Zabbix agent 2.0开始支持

system.hw.macaddr[<interface>,<format>]
列出MAC地址 字符串 interface – all (默认) 或者正则表达式format – full (默认) 、short 范例:system.hw.macaddr[“eth0$”,full][eth0] 00:11:22:33:44:55 列出指定接口mac地址 如果format指定为short,MAC地址相同的将会被忽略掉

Zabbix agent 2.0开始支持

system.localtime[<type>]
系统时间 数字或者字符串 utc – (默认) (00:00:00 UTC, January 1, 1970)local – 本地时间格式 ‘yyyy-mm-dd,hh:mm:ss.nnn,+hh:mm’ zabbix 2.0开始支持带参数
system.run[command,<mode>]
在制定的主机上运行命令 文本 command – 命令mode – wait (默认值, 执行超时时间), nowait (不等待)       最大可用返回512KB数据,包含空白数据。命令输出数据必须是文本 例如:system.run[ls -l /]– 列出/的文件和目录.

备注: 启用这个方法, agent配置文件必须配置 EnableRemoteCommands=1选项

system.stat[resource,<type>]
虚拟内存状态 数字 ent - number of processor units this partition is entitled to receive (float)kthr,<type> - information about kernel thread states:r - average number of runnable kernel threads (float)

b - average number of kernel threads placed in the Virtual Memory Manager wait queue (float)

memory,<type> - information about the usage of virtual and real memory:

avm - active virtual pages (integer)

fre - size of the free list (integer)

page,<type> - information about page faults and paging activity:

fi - file page-ins per second (float)

fo - file page-outs per second (float)

pi - pages paged in from paging space (float)

po - pages paged out to paging space (float)

fr - pages freed (page replacement) (float)

sr - pages scanned by page-replacement algorithm (float)

faults,<type> - trap and interrupt rate:

in - device interrupts (float)

sy - system calls (float)

cs - kernel thread context switches (float)

cpu,<type> - breakdown of percentage usage of processor time:

us - user time (float)

sy - system time (float)

id - idle time (float)

wa - idle time during which the system had outstanding disk/NFS I/O request(s) (float)

pc - number of physical processors consumed (float)

ec - the percentage of entitled capacity consumed (float)

lbusy - indicates the percentage of logical processor(s) utilization that occurred while executing at the user and system level (float)

app - indicates the available physical processors in the shared pool (float)

disk,<type> - disk statistics:

bps - indicates the amount of data transferred (read or written) to the drive in bytes per second (integer)

tps - indicates the number of transfers per second that were issued to the physical disk/tape (float)

This item is supported starting from version 1.8.1.

system.sw.arch
返回软件信息 字符串   范例:system.sw.arch i686数据来自uname方法

Zabbix agent 2.0.开始支持

system.sw.os[<info>]
返回系统信息 字符串 info – full (default), short ,name 范例:system.sw.os[short]Ubuntu 2.6.35-28.50-generic 2.6.35.11

信息来自如下文件

[full] – /proc/version

[short] – /proc/version_signature

[name] – /etc/issue.net

Zabbix agent version 2.0.开始支持

system.sw.packages[<package>,<manager>,<format>]
已安装软件列表 文本值 package – all (默认)或者正则表达式manager – all (默认) or a package managerformat – full (默认) ,short 范例:system.sw.packages[mini,dpkg,short] python-minimal, python2.6-minimal, ubuntu-minimal Lists (alphabetically) installed packages whose names match the given package regexp (“all” lists them all).包管理:

manager (执行命令)

dpkg (dpkg –get-selections)

pkgtool (ls /var/log/packages)

rpm (rpm -qa)

pacman (pacman -Q)

如果format 为full, packages are grouped by package managers (each manager on a seperate line beginning with it’s name in square brackets).

如果format为short, 包不分组,并且都列在一行上.

Zabbix agent 2.0开始支持

system.swap.in[<device>,<type>]
交换分区IN(磁盘交换到内存) 数字 device – 交换分区设备 (默认all)type – 可选值: count (swapins数量), sectors(sectors swapped in), pages (pages swapped in). 示例key:system.swap.in[,pages]数据采集自: Linux 2.4: /proc/swaps, /proc/partitions, /proc/stat

Linux 2.6: /proc/swaps, /proc/diskstats, /proc/vmstat

system.swap.out[<device>,<type>]
Swap out (f内存到磁盘) 数字 device – swap设备 (默认all)type – possible values: count (number of swapouts), sectors(sectors swapped out), pages (pages swapped out). See supported by platformfor details on defaults. 示例key:system.swap.out[,pages]数据采集自:

Linux 2.4: /proc/swaps, /proc/partitions, /proc/stat

Linux 2.6: /proc/swaps, /proc/diskstats, /proc/vmstat

system.swap.size[<device>,<type>]
交换分区大小 字节或者百分比 device – 交换分区 (默认值 all)type – possible values: free (free swap space, default), pfree (free swap space, in percent), pused (used swap space, in percent), total (total swap space), used (used swap space) 示例 key:system.swap.size[,pfree]– 空闲swap百分比

老命名格式:

system.swap.free, system.swap.total

system.uname
返回主机相信信息 字符串   示例值:FreeBSD localhost 4.2-RELEASEFreeBSD 4.2-RELEASE #0: Mon Nov i386

Since Zabbix 2.2.0, the value for this item is obtained by using the uname() system call, whereas previously it was obtained by invoking “uname -a” on Unix systems. Hence, the value of this item might differ from the output of “uname -a” and does not include additional information that “uname -a”

system.uptime
系统运行时长(秒) 多少秒   使用s/uptime来获取
system.users.num
登陆用户数量 多少用户   agent使用who命令获取
vfs.dev.read[<device>,<type>,<mode>]
磁盘读取状态 整数(如果type为如下): sectors,operations,bytes 浮点数(如果type为如下): sps, ops,bps device – 磁盘设备 (默认值 “all”1)type – 可选值: sectors, operations, bytes, sps, ops, bps(必须指定, 不同操作系统下不同). sps, ops, bps stand for: sectors, operations, bytes per second, respectively mode – 可选值: avg1 (一分平均, 默认值), avg5(五分内平均), avg15 (15分内平均值). 备注: 只有type为sps, ops, bps的时候,第三个参数才被支持。不同操作系统的TYPE参数: FreeBSD – bps

Linux – sps

OpenBSD – operations

Solaris – bytes

示例key:vfs.dev.read[,operations]老命名方式: io[*]

Usage of the type parameters ops, bps and sps on supported platforms used to be limited to 8 devices (7 individual devices and one “all”).

Starting with Zabbix 2.0.1 this limit has been increased to 1024 (1023 individual devices and one for “all”).

Zabbix 1.8.6开始支持LVM Until Zabbix 1.8.6, only relative device names may be used (for example, sda), since 1.8.6 an optional /dev/ prefix may be used (for example, /dev/sda)

vfs.dev.write[<device>,<type>,<mode>]
磁盘写入状态 整数(如下类型): sectors,operations,bytes 浮点型(如下类型): sps, ops,bps device – 磁盘设备 (默认值 “all”1)type – sectors, operations, bytes, sps, ops, bps (must specify exactly which parameter to use, since defaults are different under various OSes). sps, ops, bps means: sectors, operations, bytes per second respectively   mode – one of avg1 (default),avg5 (average within 5 minutes), avg15. Note: The third parameter is supported only if the type is in: sps, ops, bps. Default values of ‘type’ parameter for different OSes: FreeBSD – bps Linux – sps OpenBSD – operations Solaris – bytes Example: vfs.dev.write[,operations] Old naming: io[*] The type parameters ops, bps and sps on supported platforms used to be limited to 8 devices (7 individual devices and one “all”). Starting with Zabbix 2.0.1 this limit has been increased to 1024 (1023 individual devices and one for “all”). Supports LVM since Zabbix 1.8.6. Until Zabbix 1.8.6, only relative device names may be used (for example, sda), since 1.8.6 optional /dev/ prefix may be used (for example, /dev/sda)
vfs.file.cksum
计算文件校验 File checksum, calculated by algorithm used by UNIX cksum file – 文件完整路径 例如,返回值: 1938292000例如:

vfs.file.cksum[/etc/passwd]

老命名规范: cksum

vfs.file.contents
获取文本内容 Contents of a file or empty string if it is empty or it contains only LF/CR characters file – 文件完整路径 例如:vfs.file.contents[/etc/passwd]文件不可以超过64KB.

Zabbix agent 2.0开始支持

vfs.file.exists
检测文件是否存在 1 – 文件/硬链接/软连接文件存在 0 – 不存在 file – 文件完整路径 例如:vfs.file.exists[/tmp/application.pid]
vfs.file.md5sum
文件MD5校验码 文件MD5哈希值 file – 完整路径 示例返回值:b5052decb577e0fffd622d6ddc017e82 示例:vfs.file.md5sum[/usr/local/etc/zabbix_agentd.conf]

1.8.6移除了64MB文件大小的限制

vfs.file.regexp
文件中搜索字符串 包含字符串的行,或者为空 file – 文件完整路径regexp – GNU正则表达encoding – 编码

start line – 从哪一行开始,默认第一行

end line – 从哪一行结束,默认最后一行

output – an optional output formatting template. The \0 escape sequence is replaced with the matched text while an \N(where N=1…9) escape sequence is replaced with Nth matched group (or an empty string if the N exceeds the number of captured groups). 如果 <output> 为空, 所有包含搜索字符串的行都会被返回

start line和end line从zabbix 2.0开始支持

仅返回首先匹配的行例如:vfs.file.regexp[/etc/passwd,zabbix]

vfs.file.regexp[/path/to/some/file,”([0-9]+)$”,,3,5,\1]

vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]

– getting the ID of user zabbix

vfs.file.regmatch
文件中搜索字符串 0 – 为找到1 – 找到 file – 文件完整路径regexp – GNU 正则表达式encoding – 编码

start line – 哪行开始,默认第一行

end line – 哪行结束,默认最后一行 上面两个参数从

2.0版本开始支持。

例如:vfs.file.regmatch[/var/log/app.log,error]
vfs.file.size
文件大小 字节 file – 完整路径 zabbix必须有可读此文件的权限例如:vfs.file.size[/var/log/syslog]
vfs.fs.discovery
列出挂载的文件系统 Used for low-level discovery JSON对象 从zabbix agent 2.0开始支持
vfs.fs.inode[fs,<mode>]
inodes数量 数字 fs – 文件系统mode – total (默认), free, used, pfree (空闲百分比), pused (使用百分比) 例如:vfs.fs.inode[/,pfree]老命名规则:

vfs.fs.inode.free[*], vfs.fs.inode.pfree[*], vfs.fs.inode.total[*]

vfs.fs.size[fs,<mode>]
磁盘空间 字节 fs – 文件系统mode – total (默认), free, used, pfree (空闲百分比), pused (使用百分比) 返回本地文件系统的使用量.例如: vfs.fs.size[/tmp,free]老命名规则: vfs.fs.free[*], vfs.fs.total[*], vfs.fs.used[*], vfs.fs.pfree[*], vfs.fs.pused[*],*是任意挂载点
vm.memory.size[<mode>]
内存大小 字节或者百分比 mode – total (默认), active, anon, buffers, cached, exec, file, free, inactive, pinned, shared, wired, used, pused, available, available其中挑一个 老命名规则: vm.memory.buffers, vm.memory.cached, vm.memory.free, vm.memory.shared, vm.memory.total监控项vm.memory.size[]允许三种类型的参数

第一类:包含total – 总内存

第二类: 系统指定内存类型:active, anon, buffers, cached, exec, file, free, inactive,pinned, shared, wired.

第三类:用户级别,一共使用了多少内存,还有多少内存可用: used, pused, available,pavailable.

web.page.get[host,<path>,<port>]
获取网页内容 网页源代码 host – 主机名/域名path – 文件地址,默认/port – 端口,默认80 返回空字符串表示失败.
例如:web.page.get[www.ttlsa.com,/,80]
web.page.perf[host,<path>,<port>]
获取完全加载网页消耗的时长 host – 主机名/域名path – html地址,默认是/port – 端口,默认80 返回0表示失败. 例如: web.page.perf[www.ttlsa.com,/,80]
web.page.regexp[host,<path>,<port>,<regexp>,<length>,<output>]
在网页中搜索字符串 The matched string, or as specified by the optional<output>parameter. An empty string if no match was found. host – 主机名path – html文件路径 (默认值 /)port – 端口 (默认80)

regexp – GNU正则表达式

length – 返回的最大的字符串数量

output – 输出格式模板可选项. The \0 escape sequence is replaced with the matched text while an \N(where N=1…9) escape sequence is replaced with Nth matched group (or an empty string if the N exceeds the number of captured groups). If <output> is left empty – the whole line containing the matched text is returned. The output parameter is supported from version 2.2.

失败则返回空字符 (不匹配).示例:web.page.regexp[www.zabbix.com,index.php,80,OK,2]
vfs.file.time
文件时间 Unix时间戳. file – 文件路径mode - one of modify (default, modification time), access - last access time, change - last change time 示例:vfs.file.time[/etc/passwd,modify]

The file size limit depends on large file support.

         

 










猜你喜欢

转载自blog.csdn.net/zhangxueleishamo/article/details/80198566