0
点赞
收藏
分享

微信扫一扫

Zabbix监控案例

言午栩 2022-07-13 阅读 47


Zabbix监控案例_linux

Zabbix监控案例

  • ​​案例一、监控nginx服务的运行状态​​
  • ​​1 环境准备​​
  • ​​1.1 运行zabbix_agentd服务 并启用的自定义监控项功能​​
  • ​​1.2 安装源码nginx软件并加载状态模块​​
  • ​​2 编写监控脚本​​
  • ​​2.1 编写​​
  • ​​2.2 测试​​
  • ​​3 定义监控服务使用命令​​
  • ​​3.1 把shell脚本定义为zabbix_agentd服务可以使用命令​​
  • ​​3.2 重启服务​​
  • ​​3.3 测试命令​​
  • ​​4 web页面配置​​
  • ​​4.1 创建新模板 ATMP2​​
  • ​​4.2 创建新应用集 status​​
  • ​​4.3 创建监控项 名 监控命令​​
  • ​​4.4 监控200主机,调用新创建的模板 ATMP2​​
  • ​​案例二、监控服务器的TCP连接状态​​
  • ​​5 概述​​
  • ​​6 编写监控脚本​​
  • ​​7 定义监控服务使用命令​​
  • ​​7.1 定义命令​​
  • ​​7.2 重启服务​​
  • ​​7.3 测试命令​​
  • ​​8 web页面配置​​
  • ​​8.1 在ATMP2模板里添加新应用集 TCP_STATUS​​
  • ​​8.2 创建新的监控项​​
  • ​​8.3 查看监控数据​​

案例一、监控nginx服务的运行状态

1 环境准备

1.1 运行zabbix_agentd服务 并启用的自定义监控项功能

[root@host102 ~]# yum -y install gcc pcre-devel
[root@host102 ~]# tar -zxf zabbix-3.4.4.tar.gz
[root@host102 ~]# cd zabbix-3.4.4/
[root@host102 zabbix-3.4.4]# ./configure --enable-agent
[root@host102 zabbix-3.4.4]# make install
[root@host102 ~]# vim /usr/local/etc/zabbix_agentd.conf
93 Server=127.0.0.1,192.168.2.5
134 ServerActive=192.168.2.5:10051
265 Include=/usr/local/etc/zabbix_agentd.conf.d/ *.conf
280 UnsafeUserParameters=1

[root@host102 ~]# useradd zabbix
[root@host102 ~]# zabbix_agentd
[root@host102 ~]# netstat -utnlp | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 9130/zabbix_agentd

1.2 安装源码nginx软件并加载状态模块

[root@host102 ~]# rpm -q gcc pcre-devel zlib-devel
gcc-4.8.5-28.el7.x86_64
pcre-devel-8.32-17.el7.x86_64
package zlib-devel is not installed
[root@host102 ~]# yum -y install zlib-devel
[root@host102 ~]# tar -zxf nginx-1.12.2.tar.gz
[root@host102 ~]# cd nginx-1.12.2/

[root@host102 nginx-1.12.2]# ./configure --with-http_stub_status_module

[root@host102 ~]# ls /usr/local/nginx/
conf html logs sbin
[root@host102 ~]#
[root@host102 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
location /status {
stub_status on;
}

[root@host102 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@host102 ~]# systemctl stop httpd
[root@host102 ~]# systemctl disable httpd
[root@host102 ~]# /usr/local/nginx/sbin/nginx
[root@host102 ~]# netstat -utnlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11731/nginx: master

[root@host102 ~]# curl http://localhost/status
Active connections: 1 //实时连接数
server accepts handled requests
1 1 1 //历史累计连接数量、处理连接数量、处理请求数量
Reading: 0 Writing: 1 Waiting: 0 //读、写、等待

2 编写监控脚本

2.1 编写

[root@host102 ~]# vim /usr/local/bin/nginx_status.sh
#!/bin/bash
case $1 in
"shishi") #获取实时连接数
curl -s http://localhost/status | awk 'NR==1{print $3}' ;;

"lishi") #历史累计连接数量
curl -s http://localhost/status | awk 'NR==3{print $1}' ;;

"Waiting") #等待数量
curl -s http://localhost/status | awk 'NR==4{print $6}' ;;
esac

2.2 测试

[root@host102 ~]# /usr/local/bin/nginx_status.sh shishi
[root@host102 ~]# /usr/local/bin/nginx_status.sh lishi
[root@host102 ~]# /usr/local/bin/nginx_status.sh Waiting

3 定义监控服务使用命令

3.1 把shell脚本定义为zabbix_agentd服务可以使用命令

[root@host102 ~]# vim /usr/local/etc/zabbix_agentd.conf.d/x.conf
UserParameter=nginx_status[*],/usr/local/bin/nginx_status.sh $1

3.2 重启服务

[root@host102 ~]# killall -9 zabbix_agentd
[root@host102 ~]# killall -9 zabbix_agentd
zabbix_agentd: no process found
[root@host102 ~]# zabbix_agentd
[root@host102 ~]# netstat -utnlp | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12003/zabbix_agentd

3.3 测试命令

[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_status[lishi]
32
[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_status[shishi]
1
[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_status[Waiting]
0

4 web页面配置

4.1 创建新模板 ATMP2

Zabbix监控案例_vim_02

Zabbix监控案例_vim_03

4.2 创建新应用集 status

Zabbix监控案例_linux_04

Zabbix监控案例_linux_05

Zabbix监控案例_vim_06

4.3 创建监控项 名 监控命令

sum_link nginx_status[lishi]

now_link nginx_status[shishi]

waiting_link nginx_status[Waiting]

Zabbix监控案例_vim_07

Zabbix监控案例_nginx_08

Zabbix监控案例_连接数_09

Zabbix监控案例_连接数_10

4.4 监控200主机,调用新创建的模板 ATMP2

Zabbix监控案例_vim_11

Zabbix监控案例_连接数_12

  1. 查看监控数据
  2. Zabbix监控案例_nginx_13

案例二、监控服务器的TCP连接状态

5 概述

客户端与服务器建立连接时的连接方式: TCP 和 UDP
TCP标记位:SYN ACK FIN
TCP连接状态

  • 连接时三次握手
  • Zabbix监控案例_linux_14

  • 断开时四次握手
  • Zabbix监控案例_连接数_15

6 编写监控脚本

[root@host102 ~]# vim /usr/local/bin/net_status.sh
#!/bin/bash
case "$1" in
"estab")
ss -antp | awk 'BEGIN{z=0}/^ESTAB/{z++}END{print z}';;
"timewait")
ss -antp | awk 'BEGIN{y=0}/^TIME-WAIT/{y++}END{print y}';;
"closewait")
ss -antp | awk 'BEGIN{x=0}/^CLOSE_WAIT/{x++}END{print x}';;
esac

[root@host102 ~]# chmod +x /usr/local/bin/net_status.sh

7 定义监控服务使用命令

7.1 定义命令

[root@host102 ~]# vim /usr/local/etc/zabbix_agentd.conf.d/x.conf
UserParameter=net_status[*],/usr/local/bin/net_status.sh $1

7.2 重启服务

[root@host102 ~]# killall -9 zabbix_agentd
[root@host102 ~]# killall -9 zabbix_agentd
zabbix_agentd: no process found
[root@host102 ~]# zabbix_agentd
[root@host102 ~]# netstat -utnlp | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 14368/zabbix_agentd

7.3 测试命令

[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k net_status[closewait]
0
[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k net_status[timewait]
44
[root@host102 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k net_status[estab]
3

8 web页面配置

8.1 在ATMP2模板里添加新应用集 TCP_STATUS

Zabbix监控案例_vim_16

8.2 创建新的监控项

名 命令
close_wait net_status[closewait]
time_wait net_status[timewait]
ESTAB net_status[estab]

Zabbix监控案例_nginx_17

8.3 查看监控数据

Zabbix监控案例_linux_18


Zabbix监控案例_linux_19


Zabbix监控案例_连接数_20


举报

相关推荐

0 条评论