路漫漫其修远兮
吾将上下而求索

zabbix学习:自定义key和proxy

zabbix使用进阶(01)
	
ZABBIX(3)

	自定义key:在zabbix agent端的配置文件中由用户通过UserParameter指令定义用户自定义参数;
		UserParamter=<key>,<command>
		UserParamter=<key[*]>,<command> $1...$9
		
		注意:类似awk命令自带$1...$9,需要改写为$$1, $$2, ...$$9;

主机:172.18.1.21		
[root@localhost ~]#vim /etc/zabbix/zabbix_agentd.conf 
UserParameter=system.memory.free,awk '/^MemFree/{print $2}' /proc/meminfo
[root@localhost ~]#systemctl restart zabbix-agent.service
主机:172.18.1.20
[root@localhost ~]#zabbix_get -s 172.18.1.21 -k "system.memory.free"
110808


主机:172.18.1.21
UserParameter=system.memory.usage[*],awk '/^$1/{print $$2}' /proc/meminfo	#要获取的key是变量,master发送总量,返回的是总量信息,master发送剩余的,
    返回的是剩余的,比较灵活,可以传递的key可以多个,一般是每次传递一个变量,表达式中的$1表示从master接收的第一个key,$$2表示后面的awk所要的$2,只要将
    需要的key写到zabbix界面的item上面就可以监控多个值
主机:172.18.1.20
[root@localhost ~]#zabbix_get -s 172.18.1.21 -k "system.memory.usage[MemTotal]"
743316
[root@localhost ~]#zabbix_get -s 172.18.1.21 -k "system.memory.usage[Me]"
743316
110716
270928


UserParameter=nginx.status[*],/usr/bin/nginxstatus.sh $1	#666,这个是最有价值的脚本
[root@localhost ~]#systemctl restart zabbix-agent.service
#!/bin/bash
#
host='127.0.0.1'
port='80'
statusurl='/ngxstatus'

active() {
	curl -s http://${host}:${port}${statusurl} | awk '/^Active/{print $3}'
}

accepts() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $1}'
}

handled() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $2}'
}

requests() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $3}'
}

reading() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $2}'
}

writing() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $4}'
}

waiting() {
	curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $6}'
}

$1	

				
				
监控php-fpm的各状态指标;
[root@localhost ~]#yi nginx php-fpm
[root@localhost ~]#vim /etc/php-fpm.d/www.conf 		#因为php-fpm为fastcgi协议必须用nginx进行代理后才能与其进行通信,通过http协议取出需要的值
pm.status_path = /fpmstatus		
ping.path = /ping		
ping.response = pong		
		
[root@localhost ~]#vim /etc/nginx/nginx.conf
server {
	listen 80;
	server_name localhost;

	location /ngxstatus {
		stub_status;
	}

	location ~* ^/(fpmstatus|ping)/?$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_pass SCRIPT_FILENAME $fastcgi_script_name;
		include fastcgi_params;
	}
}
		

[root@localhost ~]#systemctl start php-fpm.service	#9000端口
[root@localhost ~]#systemctl start nginx	#80端口	还是有问题,fastcgi配置有问题

[root@localhost ~]#curl http://localhost/ngxstatus
[root@localhost ~]#curl http://localhost/fpmstatus


		

zabbix proxy:代理

			
1000台*100item = 100 000 项
			
(1) 准备数据库服务器;

(2) 安装
    zabbix-proxy-mysql-3.0.2-1.el7.x86_64.rpm  zabbix-get-3.0.2-1.el7.x86_64.rpm  
    
(3) 生成数据库,可以单独在proxy上面创建,也可以在原来的数据库上面新建一个数据库
    /usr/share/doc/zabbix-proxy-mysql-3.0.2/schema.sql.gz
    MariaDB [(none)]> create database zabbix_proxy charset 'utf8';
    MariaDB [(none)]> grant all on zabbix_proxy.* to 'zbxproxy'@'172.18.1.24' identified by 'zbxpass';
    mysql zabbix_proxy < /usr/share/doc/zabbix-proxy-mysql-3.0.2/schema.sql		#数据库名在配置文件中,更改数据库名要在配置文件中改	

(4) 配置,监听端口10051
    # grep "^####" zabbix_proxy.conf 
    ############ GENERAL PARAMETERS #################
    ######### PROXY SPECIFIC PARAMETERS #############
    ############ ADVANCED PARAMETERS ################
    ####### LOADABLE MODULES #######
    ####### TLS-RELATED PARAMETERS #######
    
    Server=		Zabbix Server主机地址;
        
    DBHost=
    DBName=
    DBUser=
    DBPass=
    
    ConfigFrequency=	#多长时间将server端的配置数据接收到proxy端
    DataSenderFrequency=	#多长时间发送数据到server端
    
(5) 在server端添加此proxy 
    Administration --> proxies 
    
    Active:Proxy主动向server发起配置信息同步请求;
    Passive:由Server端向Proxy发送配置信息;
    
(6) 添加hosts时,选择使用指定的proxy进行监控;

    
注意:
    (1) 在server添加的Proxy的名称,要与proxy的配置文件中Hostname的值保持一致;
    (2) 通过proxy监控的主机,agent要授权proxy有监控权限;
        server=Proxy_Server_IP
        
        
        
zabbix performance tuning:
NVPS:New Value Per Second
    官方说:x86能达到:100w/m, 15000/s
    
zabbix服务器进程数量调整:
    alerter, discoverer, escalator, http poller, housekeeper, poller, trapper, configration syncer, ipmi poller, ...
    
    StartPollers=50
    StartPingers=10
    ...
    StartDBSyncers=2
    ...
    
数据库优化:
    分表:
        history_*
        trend*
        events*
        
建议:
    Database:历史数据不要保存太长时间;尽量让数据缓存数据库服务器内存中;
    触发器的表达式:减少使用min(), max(), avg();尽量使用last(), nodata();
    数据收集:polling较慢时,减少使用snmp/agentless/agent, 尽量使用trapping方式,即agent(active),主动模式;
    数据类型:文本型数据处理速度较慢,尽量少收集类型为text或string或log型的数据,多使用numeric型

其他

附:Linux系统上常用的SNMP OID

服务器负载:

1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3




CPU信息:

percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0




内存使用:

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0



硬盘使用:

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1


系统运行时间:

.1.3.6.1.2.1.1.3.0



SNMP System Group:

sysDescr 1.3.6.1.2.1.1.1
sysObjectID 1.3.6.1.2.1.1.2
sysUpTime 1.3.6.1.2.1.1.3
sysContact 1.3.6.1.2.1.1.4
sysName 1.3.6.1.2.1.1.5
sysLocation 1.3.6.1.2.1.1.6
sysServices 1.3.6.1.2.1.1.7




SNMP Interfaces Group:

ifNumber 1.3.6.1.2.1.2.1
ifTable 1.3.6.1.2.1.2.2
ifEntry 1.3.6.1.2.1.2.2.1
ifIndex 1.3.6.1.2.1.2.2.1.1
ifDescr 1.3.6.1.2.1.2.2.1.2
ifType 1.3.6.1.2.1.2.2.1.3
ifMtu 1.3.6.1.2.1.2.2.1.4
ifSpeed 1.3.6.1.2.1.2.2.1.5
ifPhysAddress 1.3.6.1.2.1.2.2.1.6
ifAdminStatus 1.3.6.1.2.1.2.2.1.7
ifOperStatus 1.3.6.1.2.1.2.2.1.8
ifLastChange 1.3.6.1.2.1.2.2.1.9
ifInOctets 1.3.6.1.2.1.2.2.1.10
ifInUcastPkts 1.3.6.1.2.1.2.2.1.11
ifInNUcastPkts 1.3.6.1.2.1.2.2.1.12
ifInDiscards 1.3.6.1.2.1.2.2.1.13
ifInErrors 1.3.6.1.2.1.2.2.1.14
ifInUnknownProtos 1.3.6.1.2.1.2.2.1.15
ifOutOctets 1.3.6.1.2.1.2.2.1.16
ifOutUcastPkts 1.3.6.1.2.1.2.2.1.17
ifOutNUcastPkts 1.3.6.1.2.1.2.2.1.18
ifOutDiscards 1.3.6.1.2.1.2.2.1.19
ifOutErrors 1.3.6.1.2.1.2.2.1.20
ifOutQLen 1.3.6.1.2.1.2.2.1.21
ifSpecific 1.3.6.1.2.1.2.2.1.22




SNMP IP Group

ipForwarding 1.3.6.1.2.1.4.1
ipDefaultTTL 1.3.6.1.2.1.4.2
ipInReceives 1.3.6.1.2.1.4.3
ipInHdrErrors 1.3.6.1.2.1.4.4
ipInAddrErrors 1.3.6.1.2.1.4.5
ipForwDatagrams 1.3.6.1.2.1.4.6
ipInUnknownProtos 1.3.6.1.2.1.4.7
ipInDiscards 1.3.6.1.2.1.4.8
ipInDelivers 1.3.6.1.2.1.4.9
ipOutRequests 1.3.6.1.2.1.4.10
ipOutDiscards 1.3.6.1.2.1.4.11
ipOutNoRoutes 1.3.6.1.2.1.4.12
ipReasmTimeout 1.3.6.1.2.1.4.13
ipReasmReqds 1.3.6.1.2.1.4.14
ipReasmOKs 1.3.6.1.2.1.4.15
ipReasmFails 1.3.6.1.2.1.4.16
ipFragsOKs 1.3.6.1.2.1.4.17
ipFragsFails 1.3.6.1.2.1.4.18
ipFragCreates 1.3.6.1.2.1.4.19
ipAddrTable 1.3.6.1.2.1.4.20
ipAddrEntry 1.3.6.1.2.1.4.20.1
ipAdEntAddr 1.3.6.1.2.1.4.20.1.1
ipAdEntIfIndex 1.3.6.1.2.1.4.20.1.2
ipAdEntNetMask 1.3.6.1.2.1.4.20.1.3
ipAdEntBcastAddr 1.3.6.1.2.1.4.20.1.4
ipAdEntReasmMaxSize 1.3.6.1.2.1.4.20.1.5




SNMP ICMP Group

icmpInMsgs 1.3.6.1.2.1.5.1
icmpInErrors 1.3.6.1.2.1.5.2
icmpInDestUnreachs 1.3.6.1.2.1.5.3
icmpInTimeExcds 1.3.6.1.2.1.5.4
icmpInParmProbs 1.3.6.1.2.1.5.5
icmpInSrcQuenchs 1.3.6.1.2.1.5.6
icmpInRedirects 1.3.6.1.2.1.5.7
icmpInEchos 1.3.6.1.2.1.5.8
icmpInEchoReps 1.3.6.1.2.1.5.9
icmpInTimestamps 1.3.6.1.2.1.5.10
icmpInTimestampReps 1.3.6.1.2.1.5.11
icmpInAddrMasks 1.3.6.1.2.1.5.12
icmpInAddrMaskReps 1.3.6.1.2.1.5.13
icmpOutMsgs 1.3.6.1.2.1.5.14
icmpOutErrors 1.3.6.1.2.1.5.15
icmpOutDestUnreachs 1.3.6.1.2.1.5.16
icmpOutTimeExcds 1.3.6.1.2.1.5.17
icmpOutParmProbs 1.3.6.1.2.1.5.18
icmpOutSrcQuenchs 1.3.6.1.2.1.5.19
icmpOutRedirects 1.3.6.1.2.1.5.20
icmpOutEchos 1.3.6.1.2.1.5.21
icmpOutEchoReps 1.3.6.1.2.1.5.22
icmpOutTimestamps 1.3.6.1.2.1.5.23
icmpOutTimestampReps 1.3.6.1.2.1.5.24
icmpOutAddrMasks 1.3.6.1.2.1.5.25
icmpOutAddrMaskReps 1.3.6.1.2.1.5.26




SNMP TCP Group:

tcpRtoAlgorithm 1.3.6.1.2.1.6.1
tcpRtoMin 1.3.6.1.2.1.6.2
tcpRtoMax 1.3.6.1.2.1.6.3
tcpMaxConn 1.3.6.1.2.1.6.4
tcpActiveOpens 1.3.6.1.2.1.6.5
tcpPassiveOpens 1.3.6.1.2.1.6.6
tcpAttemptFails 1.3.6.1.2.1.6.7
tcpEstabResets 1.3.6.1.2.1.6.8
tcpCurrEstab 1.3.6.1.2.1.6.9
tcpInSegs 1.3.6.1.2.1.6.10
tcpOutSegs 1.3.6.1.2.1.6.11
tcpRetransSegs 1.3.6.1.2.1.6.12
tcpConnTable 1.3.6.1.2.1.6.13
tcpConnEntry 1.3.6.1.2.1.6.13.1
tcpConnState 1.3.6.1.2.1.6.13.1.1
tcpConnLocalAddress 1.3.6.1.2.1.6.13.1.2
tcpConnLocalPort 1.3.6.1.2.1.6.13.1.3
tcpConnRemAddress 1.3.6.1.2.1.6.13.1.4
tcpConnRemPort 1.3.6.1.2.1.6.13.1.5
tcpInErrs 1.3.6.1.2.1.6.14
tcpOutRsts 1.3.6.1.2.1.6.15




SNMP UDP Group

udpInDatagrams 1.3.6.1.2.1.7.1
udpNoPorts 1.3.6.1.2.1.7.2
udpInErrors 1.3.6.1.2.1.7.3
udpOutDatagrams 1.3.6.1.2.1.7.4
udpTable 1.3.6.1.2.1.7.5
udpEntry 1.3.6.1.2.1.7.5.1
udpLocalAddress 1.3.6.1.2.1.7.5.1.1
udpLocalPort 1.3.6.1.2.1.7.5.1.2




SNMP Group:

snmpInPkts 1.3.6.1.2.1.11.1
snmpOutPkts 1.3.6.1.2.1.11.2
snmpInBadVersions 1.3.6.1.2.1.11.3
snmpInBadCommunityNames 1.3.6.1.2.1.11.4
snmpInBadCommunityUses 1.3.6.1.2.1.11.5
snmpInASNParseErrs 1.3.6.1.2.1.11.6
NOT USED 1.3.6.1.2.1.11.7
snmpInTooBigs 1.3.6.1.2.1.11.8
snmpInNoSuchNames 1.3.6.1.2.1.11.9
snmpInBadValues 1.3.6.1.2.1.11.10
snmpInReadOnlys 1.3.6.1.2.1.11.11
snmpInGenErrs 1.3.6.1.2.1.11.12
snmpInTotalReqVars 1.3.6.1.2.1.11.13
snmpInTotalSetVars 1.3.6.1.2.1.11.14
snmpInGetRequests 1.3.6.1.2.1.11.15
snmpInGetNexts 1.3.6.1.2.1.11.16
snmpInSetRequests 1.3.6.1.2.1.11.17
snmpInGetResponses 1.3.6.1.2.1.11.18
snmpInTraps 1.3.6.1.2.1.11.19
snmpOutTooBigs 1.3.6.1.2.1.11.20
snmpOutNoSuchNames 1.3.6.1.2.1.11.21
snmpOutBadValues 1.3.6.1.2.1.11.22
NOT USED 1.3.6.1.2.1.11.23
snmpOutGenErrs 1.3.6.1.2.1.11.24
snmpOutGetRequests 1.3.6.1.2.1.11.25
snmpOutGetNexts 1.3.6.1.2.1.11.26
snmpOutSetRequests 1.3.6.1.2.1.11.27
snmpOutGetResponses 1.3.6.1.2.1.11.28
snmpOutTraps 1.3.6.1.2.1.11.29
snmpEnableAuthenTraps 1.3.6.1.2.1.11.30




应用示例:
查看服务器1分钟平均负载:


snmpwalk -v1 -c public 127.0.0.1  .1.3.6.1.4.1.2021.10.1.3.1
UCD-SNMP-MIB::laLoad.1 = STRING: 0.25


查看服务器当前连接:


snmpwalk -v1 -c public 127.0.0.1  1.3.6.1.2.1.6.13.1.1


TCP-MIB::tcpConnState.0.0.0.0.22.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.0.0.0.0.80.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.0.0.0.0.111.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.0.0.0.0.443.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.0.0.0.0.3306.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.127.0.0.1.25.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.127.0.0.1.199.0.0.0.0.0 = INTEGER: listen(2)
TCP-MIB::tcpConnState.192.168.1.2.22.192.168.1.16.5035 = INTEGER: established(5)
TCP-MIB::tcpConnState.192.168.1.2.22.192.168.1.16.10518 = INTEGER: established(5)
TCP-MIB::tcpConnState.192.168.1.2.22.192.168.1.16.24713 = INTEGER: established(5)

未经允许不得转载:江哥架构师笔记 » zabbix学习:自定义key和proxy

分享到:更多 ()

评论 抢沙发

评论前必须登录!