zabbix api与php的配置

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介:
 因为最近线上的hadoop集群从mrv1升级到mrv2了,监控模板也跟着变动了。。
线上是200台左右的集群,模块采用了link的方式来添加,即一个模板下link大量的模块,然后主机添加到这个模板里。

wKioL1No9wXgRhWjAAGCDva4ZDY163.jpg

这样算下来一台机器差不多有 215个item.

为了增加NM的监控,也采用了link的方式来连接模板,在页面上link时发现一直返回一个空白页。
为了快速上线,改变了下方法,使用了host.update的api,直接把host link到NM的模板。

回过头来看这个问题:
在通过页面link模板时,其实也是调用了zabbix template相关的api(具体调用了template.update方法)
直接通过脚本来调用api测试:
测试脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import  urllib2
import  sys
import  json
def  requestJason(url,values):
     data  =  json.dumps(values)
     print  data
     req  =  urllib2.Request(url, data, { 'Content-Type' 'application/json-rpc' })
     response  =  urllib2.urlopen(req, data)
     data_get  =  response.read()
     output  =  json.loads(data_get)
     print  output
     try :
         message  =  output[ 'result' ]
     except :
         message  =  output[ 'error' ][ 'data' ]
         quit()
     print  json.dumps(message) 
     return  output
def  authenticate(url, username, password):
     values  =  { 'jsonrpc' '2.0' ,
               'method' 'user.login' ,
               'params' : {
                   'user' : username,
                   'password' : password
               },
               'id' '0'
               }
     idvalue  =  requestJason(url,values)
     return  idvalue[ 'result' ]
def  getTemplate(hostname,url,auth):
     values  =  { 'jsonrpc' '2.0' ,
               'method' 'template.get' ,
               'params' : {
                   'output' "extend" ,
                   'filter' : {
                       'host' : hostname
                   }
               },
               'auth' : auth,
               'id' '2'
               }
     output  =  requestJason(url,values)
     print  output[ 'result' ][ 0 ][ 'hostid' ]
     return   output[ 'result' ][ 0 ][ 'hostid' ]
def  changeTemplate(idx,id_list,url,auth):
     values  =  { 'jsonrpc' '2.0' ,
               'method' 'template.update' ,
               'params' : {
                 "templateid" :idx,           
                 "templates" :id_list
               },
               'auth' : auth,
               'id' '2'
               }
     output  =  requestJason(url,values)
     print  output
def  main():
     id_list  =  []
     hostname  =  "Vipshop_Template_OS_Linux_Hadoop_Datanode_Pro"
     url  =  'xxxx'
     username  =  'admin'
     password  =  'xxxx'
     auth  =  authenticate(url, username, password)
     idx  =  getTemplate(hostname,url,auth)
     temlist  =  [ 'Vipshop_Template_LB_Tengine_8090' , 'Vipshop_Template_Redis_6379' , 'Vipshop_Template_Redis_6380' , 'Vipshop_Template_Redis_6381' , 'Vipshop_Template_Redis_6382' , 'Vipshop_Template_Redis_6383' ]
     for  tem  in  temlist:
         idtemp  =  getTemplate(tem,url,auth)
         id_list.append({ "templateid" :idtemp})
     print  id_list
     #id_list = [{"templateid":'10843'},{"templateid":"10554"},{"templateid":"10467"},{"templateid":"10560"},{"templateid":"10566"},{"templateid":"10105"}]
     changeTemplate(idx,id_list,url,auth)
if  __name__  = =  '__main__' :
     main()
脚本结果:
urllib2.HTTPError: HTTP Error 500: Internal Server Error
因为api其实是发送了一个jason格式的post请求,手动使用curl来验证:
1
2
3
4
curl  -vvv -i -X POST -H  'Content-Type:application/json'  -d
'{ "params" : { "templates" : [{ "templateid" "10117" }, { "templateid" "10132" }, { "templateid" "10133" }, { "templateid" "10134" },
{ "templateid" "10135" }, { "templateid" "10136" }],  "templateid" "10464" },  "jsonrpc" "2.0" "method" "template.update" "auth" "421a04b400e859834357b5681a586a5f" "id" "2" }'
http: //zabbix .idc.vipshop.com /api_jsonrpc .php
返回500错误(即后端php处理时遇到错误导致),调整php的配置,把日志改成debug格式:
1
2
php-fpm.conf:
log_level = debug
在error log中发现如下错误:
1
2
3
4
5
6
7
8
[04-May-2014 14:04:32.115189] WARNING: pid 6270, fpm_request_check_timed_out(), line 271: [pool www] child 6294, script  '/apps/svr/zabbix/wwwroot/api_jsonrpc.php'  (request:  "POST /api_jsonrpc.php" ) executing too slow (1.269946 sec), logging
[04-May-2014 14:04:32.115327] DEBUG: pid 6270, fpm_got_signal(), line 72: received SIGCHLD
[04-May-2014 14:04:32.115371] NOTICE: pid 6270, fpm_children_bury(), line 227: child 6294 stopped  for  tracing
[04-May-2014 14:04:32.115385] NOTICE: pid 6270, fpm_php_trace(), line 142: about to trace 6294
[04-May-2014 14:04:32.115835] NOTICE: pid 6270, fpm_php_trace(), line 170: finished trace of 6294
[04-May-2014 14:04:32.115874] DEBUG: pid 6270, fpm_event_loop(), line 409: event module triggered 1 events
[04-May-2014 14:04:35.318614] WARNING: pid 6270, fpm_stdio_child_said(), line 166: [pool www] child 6294 said into stderr:  "NOTICE: sapi_cgi_log_message(), line 663: PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 512 bytes) in /apps/svr/zabbix/wwwroot/api/classes/CItem.php on line 1088"
[04-May-2014 14:04:35.318665] DEBUG: pid 6270, fpm_event_loop(), line 409: event module triggered 1 events
即在做link模板时,需要把相关的数据放在php的内存中,而默认的设置是128M,如果在item和host比较多的时候,很容易就会超过这个限制。
更改为
1
memory_limit = 1280M
重新测试,返回了502 Bad Gateway错误,即后端执行超时导致。
error log:
1
[04-May-2014 14:50:21.318071] WARNING: pid 4131, fpm_request_check_timed_out(), line 281: [pool www] child 4147, script  '/apps/svr/zabbix/wwwroot/api_jsonrpc.php'  (request:  "POST /api_jsonrpc.php" ) execution timed out (10.030883 sec), terminating
执行时间超过request_terminate_timeout 设置。导致502产生。
更改 request_terminate_timeout = 1800(默认是10s),max_execution_time = 0(默认30s),重新测试。ok.

小结:
zabbix不同于一般的线上应用,在调用api做更新时,是一个batch的行为,对内存和执行时间有一定的要求。
因此要合理的设置php的相关参数,在debug的时候调低日志级别并开启slow log来方便定位问题.



本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1407422,如需转载请自行联系原作者
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
16天前
|
缓存 监控 网络协议
在配置 PHP-FPM 的 pool 时,常见的性能优化技巧
在配置 PHP-FPM 的 pool 时,常见的性能优化技巧
|
9天前
|
关系型数据库 MySQL PHP
php wampserver的使用配置
本文介绍了WampServer在Windows系统下的配置和使用方法,包括如何修改PHP时区为中国标准时区PRC、更改Apache服务器端口号以避免冲突、设置起始页以及如何创建和管理虚拟目录。通过这些步骤,用户可以更有效地在本地环境中开发和测试PHP程序。
php wampserver的使用配置
|
12天前
|
Unix PHP
PHP-FPM 配置
PHP-FPM 配置
|
12天前
|
IDE 安全 网络安全
Xdebug 在不同版本的 PHP 中配置方法有什么不同?
Xdebug 在不同版本的 PHP 中配置方法有什么不同?
|
16天前
|
监控 IDE PHP
php xdebug的配置、调试、跟踪、调优、分析
php xdebug的配置、调试、跟踪、调优、分析
|
1月前
|
监控 Windows
Zabbix 5.0 LTS配置中文支持并解决字符乱码问题
文章介绍了如何在Zabbix 5.0 LTS中配置中文支持并解决字符乱码问题,包括在用户设置中选择中文语言和替换默认字体为Windows字体的步骤。
112 4
|
2月前
|
前端开发 API 网络架构
【Azure 应用服务】能否通过 Authentication 模块配置 Azure AD 保护 API 应用?
【Azure 应用服务】能否通过 Authentication 模块配置 Azure AD 保护 API 应用?
|
2月前
|
安全 API 网络安全
【Azure API 管理】APIM如何配置客户端证书的CRL检测策略
【Azure API 管理】APIM如何配置客户端证书的CRL检测策略
|
2月前
|
JSON 算法 API
【Azure API 管理】APIM 配置Validate-JWT策略,验证RS256非对称(公钥/私钥)加密的Token
【Azure API 管理】APIM 配置Validate-JWT策略,验证RS256非对称(公钥/私钥)加密的Token
|
2月前
|
API
【Azure 环境】在Azure活动目录中的应用注册,给应用添加API权限时发现API权限配置缺失
【Azure 环境】在Azure活动目录中的应用注册,给应用添加API权限时发现API权限配置缺失

推荐镜像

更多
下一篇
无影云桌面