码迷,mamicode.com
首页 > 移动开发 > 详细

zabbix增加手机端4个url地址的返回值

时间:2017-06-26 22:37:50      阅读:1393      评论:0      收藏:0      [点我收藏+]

标签:curl   zabbix   url   

由同事提供4个需要监控的url地址

GET类型:

http://10.15.24.61:809/UserCenterService.svc/getAccountInfo/563/9638

POST类型:

http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/4/0/563/1/9638/1.0

http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/3/0/563/1/9638/1.0

http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/2/0/563/1/9638/1.0


url的返回值

  以下操作,统一是在10.25.4.7服务器上操作。由于curl的是SLB IP地址,下面的操作,其实在任何1CentOS服务器都可以进行。

  其中,通过执行curl命令,获取的返回值,GET类型正确的结果如下:

[root@iZ23kdZ ~]# curl http://10.15.24.61:809/UserCenterService.svc/getAccountInfo/563/9638
"{\"state\":\"1\",\"data\":{\"AccountInfo\":{\"Uid\":\"563\",\"Recieving\":\"0\",\"Collect\":\"0\",\"Reading\":\"0\",\"Recommends\":\"0\",\"Bankcards\":\"0\",\"userName\":\"加加林\",\"IsQuickReg\":\"0\",\"UNameComplete\":\"0\",\"PwdComplete\":\"0\",\"IsOwner\":\"1\",\"IsRecommended\":\"1\",\"IsBindBankCard\":\"1\",\"MyBanks\":[{\"CardPadRightNum\":\"7471\",\"CardStatus\":\"2\"}],\"Email\":\"1550348062@qq.com\",\"EmailVerify\":\"\",\"isVip\":0}},\"errorInfo\":\"\",\"versionCode\":\"\"}"

POST类型的正确结果如下:

[root@iZ23kdZ ~]# curl -d -XPOST http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/4/0/563/1/9638/1.0
"{\"state\":\"1\",\"data\":{\"productlist\":null,\"rowCount\":0,\"ProSource\":4},\"errorInfo\":\"\",\"versionCode\":\"\"}"

  3POST类型的url返回结果是一致的。

  其中,以上4url的返回结果,只需要关注返回值前面的“state”值后面为“1”,就说明接口是正常的。

  因此,后面的监控都是围绕这个结果进行。



awk命令获取url返回值

GET类型:

[root@iZ23kdZ ~]# curl http://10.15.24.61:809/UserCenterService.svc/getAccountInfo/563/9638  2>/dev/null|grep state|cut -d":" -f 2|cut -d "\"" -f 2|cut -d "\\" -f 1
1

POST类型:

[root@iZ23kdZ ~]# curl -d-XPOST http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/4/0/563/1/9638/1.02>/dev/null|grep state|cut -d ":" -f 2|cut -d "\""-f 2|cut -d "\\" -f 1
1

  虽然同样是curl命令,但是,不同类型,参数不太一样。

  只要这条命令的返回值不是1,就让zabbix报警。

 

确认自定义监控脚本的位置

  创建自定义监控项,需要确认自定义监控脚本的位置。有的使用者会把自定义监控命令直接写到配置文件里,但是,推荐把监控脚本放在配置文件的include目录里。

[root@iZ23kdZ ~]# head -12 /etc/zabbix/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=10.25.4.8
#ServerActive=10.25.4.6
ServerActive=10.25.4.8
Hostname=10.25.4.8
#Hostname=iZ23kdZ
RefreshActiveChecks=300
BufferSend=5
BufferSize=1000
MaxLinesPerSecond=200
Timeout=10
Include=/etc/zabbix/zabbix_agentd.d/*.conf

  就是上面最后1行配置文件指定的目录。注意,监控脚本的后缀要求必须是.conf,否则,zabbix不会识别。

 

相关自定义监控脚本

[root@iZ23kdZ ~]# ll -tr /etc/zabbix/zabbix_agentd.d/curl*
-rw-r--r-- 1 root root 215Jun 23 14:20 /etc/zabbix/zabbix_agentd.d/curl_post_1.conf
-rw-r--r-- 1 root root 215Jun 23 15:23 /etc/zabbix/zabbix_agentd.d/curl_post_2.conf
-rw-r--r-- 1 root root 215Jun 23 15:28 /etc/zabbix/zabbix_agentd.d/curl_post_3.conf
-rw-r--r-- 1 root root 190 Jun 23 16:11 /etc/zabbix/zabbix_agentd.d/curl_get.conf

  如下是自定义的监控脚本,curl_post_3.conf没有列出,和前2个几乎一样。

[root@iZ23kdZ ~]# cat /etc/zabbix/zabbix_agentd.d/curl_get.conf 
UserParameter=curl_get,/usr/bin/curl http://10.15.24.61:809/UserCenterService.svc/getAccountInfo/563/9638  2>/dev/null|grep state|cut -d":" -f 2|cut -d "\"" -f 2|cut -d "\\" -f 1
[root@iZ23kdZ ~]# cat /etc/zabbix/zabbix_agentd.d/curl_post_1.conf 
UserParameter=curl_post_1,/usr/bin/curl -d -XPOST http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/4/0/563/1/9638/1.02>/dev/null|grep state|cut -d ":" -f 2|cut -d "\""-f 2|cut -d "\\" -f 1
[root@iZ23kdZ ~]# cat /etc/zabbix/zabbix_agentd.d/curl_post_2.conf 
UserParameter=curl_post_2,/usr/bin/curl -d -XPOST http://10.15.24.61:809/ProductService/userInvestVarietyYjsList/3/0/563/1/9638/1.02>/dev/null|grep state|cut -d ":" -f 2|cut -d "\""-f 2|cut -d "\\" -f 1


自定义脚本重启zabbix agent服务才能生效

#检查zabbix agent服务进程

[root@iZ23kdZ ~]# ps -ef|grep zabbix|grep -v "zabbix_server"
root      7847 26915  0 16:57 pts/0    00:00:00 grep --color=auto zabbix
root     18956    1  0 16:12 ?        00:00:00 zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf
root     18957 18956  0 16:12 ?        00:00:00 zabbix_agentd: collector [idle1 sec]
root     18958 18956  0 16:12 ?        00:00:00 zabbix_agentd: listener #1[waiting for connection]
root     18959 18956  0 16:12 ?        00:00:00 zabbix_agentd: listener #2[waiting for connection]
root     18960 18956  0 16:12 ?       00:00:00 zabbix_agentd:listener #3 [waiting for connection]
root     18961 18956  0 16:12 ?        00:00:00 zabbix_agentd: active checks#1 [idle 1 sec]

#杀死zabbix agent服务

[root@iZ23kdZ ~]# pkill -f /etc/zabbix/zabbix_agentd.conf

#查看进程结果

[root@iZ23kdZ ~]# ps -ef|grep zabbix|grep -v "zabbix_server"
root     7934 26915  0 16:57 pts/0    00:00:00 grep --color=auto zabbix

#启动zabbix agent服务

[root@iZ23kdZ ~]#zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf

#查看启动服务结果

[root@iZ23kdZ ~]# ps -ef|grep zabbix|grep -v "zabbix_server"
root      7941    1  0 16:57 ?        00:00:00 zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf
root      7942 7941  0 16:57 ?        00:00:00 zabbix_agentd: collector [idle1 sec]
root      7943 7941  0 16:57 ?        00:00:00 zabbix_agentd: listener #1[waiting for connection]
root      7944 7941  0 16:57 ?        00:00:00 zabbix_agentd: listener #2[waiting for connection]
root      7945 7941  0 16:57 ?        00:00:00 zabbix_agentd: listener #3[waiting for connection]
root      7946 7941  0 16:57 ?        00:00:00 zabbix_agentd: active checks#1 [idle 1 sec]
root     7967 26915  0 16:58 pts/0    00:00:00 grep --color=auto zabbix

  请按照文档的杀死进程和启动服务的命令来执行,否则,后果自负。

 

zabbix_get命令测试结果

[root@iZ23kdZ ~]# zabbix_get -s 10.25.4.8 -p 10050 -k "curl_post_1"
1
[root@iZ23kdZ ~]# zabbix_get -s 10.25.4.8 -p 10050 -k "curl_get"
1

  现在,就可以去zabbixweb页面添加监控项了。


增加Item

  依次点击“Configuration”→“Host

技术分享

  在页面下面找到“10.253.4.8”服务,点击“Items

技术分享

  4个监控项已经添加

技术分享

  4个监控项的任意1个,点击查看的结果:

技术分享

  只有4个位置需要修改。其中,“Key”值就是“zabbix_get -s 10.25.4.7 -p 10050 -k "curl_get"”命令最后的参数“-k”的值。

  “Name”值建议和“Key”值保持一致。

  “Description”的值是由前面提到的同事提供,就是这个4url的中文说明。

  “Applications”值是因为前面创建过这个监控组。

  再列出1个作为参考:

技术分享

触发值的创建

  在zabbixWEB界面,很多位置都可以找到这个触发值,只要是同一台需要监控的服务器。

技术分享

  “Triggers”创建后的列表:

技术分享

  每个“Triggers”项基本一致:

技术分享

  “Expression”框里的表达式,需要点击右边的“Add”按纽:

技术分享

  在弹出的对话框点击“Item”右边的“Select”按纽:

技术分享

  找到对应的监控项,点击确认。

技术分享

  在返回的对话框里,点击“Function”项,选中“Last (most recent) T value is NOT N”项。

  最后的“N”项,输入“1”。

  点击“Insert”按纽完成表达式的创建。

技术分享

  在“Trigger”配置页面里,Severity项的意思是报警级别。

  截图中最下面的“Clone”按纽,可以通过它来创建参数相近的触发值。前面的Items监控项,也有这样的按纽。



图形的创建

  点击“Graphs”按纽,注意是不是对应的服务器。

技术分享

  我把4个监控项的图形页面放在了一起,其实,分开也可以。

技术分享

  细节如下:

技术分享

  “Graph type”是图形类型,一般选择默认。

  每1个监控项是通过“Add”按纽来添加。

  点击“Preview”可以看到预览图。

  注意:所有修改,必须点击“Update”按纽才能生效。

  目前已经把4url地址的监控分开配置图形:

技术分享


curl_get配置:

技术分享

curl_post_1配置:

技术分享

curl_post_2配置:

技术分享

  最后1个也差不多。

 

  现在,要把4张图放在一个界面显示:

  依次点击“Monitoring”→“Screens

技术分享

  点击“Create screen”按纽

技术分享

  配置的内容如下:

技术分享

  “Columns”:纵列数

  “Rows”:排数

  点击“Add”按纽后,在列表里点击刚创建的“curl_4

技术分享

  点击右上角的“Edit screen”按纽

技术分享

  在弹出的页面里点击左上角的“Change”按纽。

技术分享

  在弹出的页面里,点击“Graph”选项的“Select”按纽

技术分享

  在弹出的对话框里,选择“curl_get

技术分享

  “Resource”就是“Graph”即可。

  “Dynamic item”的意思是“动态获取”,应该勾选。

  点击“Add”按纽完成添加。

  其它3个添加方法相同。

技术分享

  回到zabbix主界面,找到左侧的“Favorite screens”,点击“Action”按纽,在弹出的快捷菜单点击“Add

技术分享

  在弹出的对话框选中刚才创建的“curl_4”,点击“Select”按纽

技术分享

  最后的结果:

技术分享

  这样,就可以在zabbix主界面通过点击“Favorite screens”添加的screens,同时展示4url的监控状态。


参考文档

https://www.abcdocker.com/abcdocker/1453——Zabbix 3.0 部署监控 []


本文出自 “dark-matter” 博客,谢绝转载!

zabbix增加手机端4个url地址的返回值

标签:curl   zabbix   url   

原文地址:http://gagarin.blog.51cto.com/1056957/1942089

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!