设为首页 收藏本站
查看: 1344|回复: 0

[经验分享] Zabbix 监控TCP的SYN,establised

[复制链接]

尚未签到

发表于 2019-1-23 07:32:54 | 显示全部楼层 |阅读模式
  1、在 agent 端建立脚本,并赋予 zabbix 执行权限
  #!/bin/bash
  # Script to fetch Netstat statuses for tribily monitoring systems
  # Author: hanxiao2100@qq.com
  # License: GPLv2
  # Set Variables
  

  # Functions to return tcp stats
  function tcp {
  netstat -n | grep tcp | wc -l
  }
  

  function udp {
  netstat -n | grep udp | wc -l
  }
  

  function icmp {
  netstat -n | grep icmp | wc -l
  }
  

  function syn {
  netstat -n | grep SYN | wc -l
  }
  function timewait {
  netstat -n | grep TIME_WAIT | wc -l
  }
  function established {
  netstat -n | grep ESTABLISHED | wc -l
  }
  function close {
  netstat -n | grep CLOSE | wc -l
  }
  # Run the requested function
  $1
  

  2、添加zabbix_agent用户参数
  # Monitor Network status
  UserParameter=network.tcp,/usr/local/zabbix_agent/etc/scripts/networkStatus tcp
  UserParameter=network.udp,/usr/local/zabbix_agent/etc/scripts/networkStatus udp
  UserParameter=network.icmp,/usr/local/zabbix_agent/etc/scripts/networkStatus icmp
  UserParameter=network.tcp.syn,/usr/local/zabbix_agent/etc/scripts/networkStatus syn
  UserParameter=network.tcp.timewait,/usr/local/zabbix_agent/etc/scripts/networkStatus timewait
  UserParameter=network.tcp.established,/usr/local/zabbix_agent/etc/scripts/networkStatus established
  UserParameter=network.tcp.close,/usr/local/zabbix_agent/etc/scripts/networkStatus close
  

  到服务端来采集,测试下是不是正常
DSC0000.jpg

  3、在zabbix 服务端创建模板
DSC0001.jpg

DSC0002.jpg

  

  创建 Applications 应用
DSC0003.jpg

  

  创建监控项目
DSC0004.jpg

DSC0005.jpg

DSC0006.jpg

DSC0007.jpg

DSC0008.jpg

DSC0009.jpg

DSC00010.jpg

  

  创建图表
DSC00011.jpg

  

  4、查看监控数据
DSC00012.jpg

  

  http://www.linuxidc.com/Linux/2012-06/62870.htm
  onitoring network connection states with Zabbix (+ iptables + iptstate)

Thisis a little howto about displaying some small n’ nice graphs regarding to network connections of your machine. In the way of “Nothing is silly if it involves getting graphs”, the goal of this article is to get a realtime graph showing numbers of current server connections according to protocols,
本文内容英文原文由以下博客作者提供!我做中文说明. 呵呵
http://blog.portwd.com/sysadmin/monitoring-iptables-with-zabbix/
1. iptables, iptstate, zabbix server/agent
2. iptables Zabbix template
3. monitoring scripts
Weneed to get the template from point 2. and import it to Zabbix sever. Then we will rename it’s application from “Network” to e.g. Network_iptables, due to namespace conflict with default Linux template.Now when we have a possibility to display TCP states and type of connections, let’s fill it with data.
/etc/zabbix_agentd.conf:
UserParameter=iptstate.tcp,/etc/zabbix/scripts/net-tcp
UserParameter=iptstate.tcp.syn,/etc/zabbix/scripts/net-syn
UserParameter=iptstate.tcp.timewait,/etc/zabbix/scripts/net-time-wait
UserParameter=iptstate.tcp.established,/etc/zabbix/scripts/net-established
UserParameter=iptstate.tcp.close,/etc/zabbix/scripts/net-close
UserParameter=iptstate.udp,/etc/zabbix/scripts/net-udp
UserParameter=iptstate.icmp,/etc/zabbix/scripts/net-icmp
Boldfont are the names of keys in our newly imported iptables/iptstate zabbix template. Then you need to authorize zabbix user to run iptstate command (potentially without password) and you do it in /etc/sudoers file. Since zabbix agent doesn’t allow to callsudo command directly fromit’s config ( you will end up with error log “you must have a tty to run sudo” ), it is also required to turn off “Defaults requiretty” by commenting it out. The scripts which are called in the example above arelocated in point 3.
#!/bin/bash
est=`sudo iptstate -s | grep ESTABLISHED | wc -l`
echo $est
Outputof this simple script is a number of connections which are in ESTABLISHED TCP state. These checks are periodical, so after restarting zabbix-agentd, you’ll get graphs like from beggining of this article. Good part is that you don’t need to be stuck with defaults, you can define some more like this:
iptstate -s -t | head -2 |tail -1 | sed 's/^.*OTHER: //'
上一张我的图吧,还是热呼呼的,呵呵!


第一步,导入zabbix的关于tcp的模版和脚本文件.见附件!
第二步编辑/etc/zabbix_agentd.conf:
UserParameter=iptstate.tcp,/etc/zabbix/scripts/net-tcp
UserParameter=iptstate.tcp.syn,/etc/zabbix/scripts/net-syn
UserParameter=iptstate.tcp.timewait,/etc/zabbix/scripts/net-time-wait
UserParameter=iptstate.tcp.established,/etc/zabbix/scripts/net-established
UserParameter=iptstate.tcp.close,/etc/zabbix/scripts/net-close
UserParameter=iptstate.udp,/etc/zabbix/scripts/net-udp
UserParameter=iptstate.icmp,/etc/zabbix/scripts/net-icmp
建立脚本文件到/etc/zabbix/scripts这个目录里。
请到这儿下载 http://data.portwd.com/code/zabbix-iptables/
第三步:替换掉/etc/sudoers里的选项
sed -i -e 's/^Defaults.*requiretty/# &/' /etc/sudoers
第三步不做的后果是:
a、zabbix-agentd.log会在你查看关于tcp的图形时,狂报以下信息:
sudo: sorry, you must have a tty to run sudo
第四步重启zabbix-agent
备注1: 在测试中有发现部分机器使用iptstate 没有任何的输出。此时,我们需要加载一个模块。
# modprobe ip_conntrack
关于tcp的脚本,建议先在客户端执行,确认有数字输出,如果本地都没有输出,在zabbix server端也不会有输出。
备注2:在客户端使用zabbix用户执行net-tcp时,出现iptstate  找不到命令。请使用完全路径,我也是在某台vps发现这个问题,我的附件里没有修改。太懒了,原作者的也没有修改。关于iptstate,请使用绝对路径
[root@s10315190 scripts]# cat net-icmp
#!/bin/bash
est=`sudo /usr/sbin/iptstate -s | grep icmp | wc -l`
echo $est
使用zabbix 不超过3天,收获真是不少!官方详尽的文档,不少网站和博客上大量的模版,让我收益良多!
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2012年资料/6月/14日/Zabbix 如何监控TCP的SYN,establised?/
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-666473-1-1.html 上篇帖子: centos6 安装 zabbix 2.4 下篇帖子: Centos 6.5 yum安装zabbix2.2
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表