[toc]

Zabbix监控Nginx

配置监控Nginx的步骤

实验环境

服务器系统 角色 IP
CentOS 7.4 x86_64 Zabbix-Server 10.0.0.71
CentOS 7.4 x86_64 Zabbix-Agent 10.0.0.7

监控nginx

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# nginx配置文件
server{
listen 80;
server_name _;

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}

# 创建脚本目录
mkdir -p /etc/zabbix/scripts

# 创建脚本存放目录
mkdir -p /etc/zabbix/scripts

# 编辑脚本
#!/bin/bash
############################################################
# $Name: nginx_status.sh
# $Version: v1.0
# $Function: Nginx Status
# $Author: DriverZeng
# $organization: www.driverzeng.com
# $Create Date: 2016-06-23
# $Description: Monitor Nginx Service Status
############################################################

NGINX_PORT=80 #如果端口不同仅需要修改脚本即可,否则修改xml很麻烦
NGINX_COMMAND=$1

nginx_active(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
}

nginx_reading(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
}

nginx_writing(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'
}

nginx_waiting(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'
}

nginx_accepts(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'
}

nginx_handled(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'
}

nginx_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'
}

case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
*)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac

# 添加执行权限
chmod +x /etc/zabbix/scripts/jk.sh

# 配置监控项
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/scripts/jk.sh "$1"

网页配置

image-20230326211126972

image-20230326211135166

image-20230326211139293

image-20230326211143409

zabbix监控php

配置监控php的步骤

实验环境

服务器系统 角色 IP
CentOS 7.4 x86_64 Zabbix-Server 10.0.0.71
CentOS 7.4 x86_64 Zabbix-Agent 10.0.0.7

修改php配置

1
2
3
4
5
6
7
vim /etc/php-fpm.d/www.conf

# 打开php状态模板
pm.status_path = /phpfpm_status

# 重启php
systemctl restart php-fpm

修改nginx配置

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 编辑nginx配置文件
server{
listen 80;
server_name _;

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ ^/(phpfpm_status)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

# 重启nginx
systemctl restart nginx

# 查看php状态
curl http://127.0.0.1/phpfpm_status

pool: www
process manager: dynamic
start time: 24/Mar/2023:17:22:53 +0800
start since: 13
accepted conn: 1
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 1
max children reached: 0
slow requests: 0

## PHP-FPM状态解释:
pool #fpm池名称,大多数为www
process manager #进程管理方式dynamic或者static
start time #启动日志,如果reload了fpm,时间会更新
start since #运行时间
accepted conn #当前池接受的请求数
listen queue #请求等待队列,如果这个值不为0,那么需要增加FPM的进程数量
max listen queue #请求等待队列最高的数量
listen queue len #socket等待队列长度
idle processes #空闲进程数量
active processes #活跃进程数量
total processes #总进程数量
max active processes #最大的活跃进程数量(FPM启动开始计算)
max children reached #程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量过小,可以适当调整。

# 编辑脚本
#!/bin/bash
############################################################
# $Name: phpfpm_status.sh
# $Version: v1.0
# $Function: Nginx Status
# $Author: DriverZeng
# $organization: www.driverzeng.com
# $Create Date: 2016-06-23
# $Description: Monitor Nginx Service Status
############################################################

PHPFPM_COMMAND=$1
PHPFPM_PORT=80 #根据监听不同端口进行调整

start_since(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^start since:/ {print $NF}'
}

accepted_conn(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^accepted conn:/ {print $NF}'
}

listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue:/ {print $NF}'
}

max_listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max listen queue:/ {print $NF}'
}

listen_queue_len(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue len:/ {print $NF}'
}

idle_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^idle processes:/ {print $NF}'
}

active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^active processes:/ {print $NF}'
}

total_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^total processes:/ {print $NF}'
}

max_active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max active processes:/ {print $NF}'
}

max_children_reached(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max children reached:/ {print $NF}'
}

slow_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^slow requests:/ {print $NF}'
}

case $PHPFPM_COMMAND in
start_since)
start_since;
;;
accepted_conn)
accepted_conn;
;;
listen_queue)
listen_queue;
;;
max_listen_queue)
max_listen_queue;
;;
listen_queue_len)
listen_queue_len;
;;
idle_processes)
idle_processes;
;;
active_processes)
active_processes;
;;
total_processes)
total_processes;
;;
max_active_processes)
max_active_processes;
;;
max_children_reached)
max_children_reached;
;;
slow_requests)
slow_requests;
;;
*)
echo $"USAGE:$0 {start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}"
esac

# 增加执行权限
chmod +x /etc/zabbix/scripts/phpjk.sh

# 配置监控项配置文件
vim php.jk.conf
UserParameter=phpfpm_status[*],/bin/bash /etc/zabbix/scripts/phpjk.sh "$1"

# 重启zabbixagent
systemctl restart zabbix-agent.service

# 检测是否能监控到
zabbix_get -s 172.16.1.7 -k
phpfpm_status[start_since]
482

网页配置

image-20230326211546452

image-20230326211550033

image-20230326211555810

Zabbix监控JVM

在Zabbix中,JMX监控数据的获取由专门的代理程序来实现,即Zabbix-Java-Gateway来负责数据的采集,Zabbix-Java-Gateway和JMX的Java程序之间通信获取数据

JMX在Zabbix中的运行流程

  1. Zabbix-ServerZabbix-Java-Gateway获取Java数据
  2. Zabbix-Java-Gateway找Java程序服务器部署的zabbix-agent获取数据
  3. Java程序返回数据给Zabbix-Java-Gateway
  4. Zabbix-Java-Gateway返回数据给Zabbix-Server
  5. Zabbix-Server进行数据展示

配置JMX监控的步骤

  1. 安装Zabbix-Java-Gateway
  2. 配置zabbix_java_gateway.conf参数
  3. 配置zabbix-server.conf参数
  4. Tomcat应用开启JMX协议
  5. ZabbixWeb配置JMX监控的Java应用

实践环境

服务器系统 角色 IP
CentOS 7.4 x86_64 Zabbix-Server 10.0.0.8
CentOS 7.4 x86_64 Zabbix-java-gateway 10.0.0.8
CentOS 7.4 x86_64 Zabbix-Agent 10.0.0.7

zabbix服务端

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
# 安装java
yum install java-1.8.0-openjdk -y

# 安装对应版本的zabbix-java-gateway(如果源码安装加上--enable-java参数)
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-java-gateway-5.0.32-1.el7.x86_64.rpm?spm=a2c6h.25603864.0.0.54a02e2feKZO9Z

# 配置zabbix-java-gateway
vim /etc/zabbix/zabbix_java_gateway.conf
LISTEN_IP="172.16.1.9" # 服务端IP
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java_gateway.pid"
START_POLLERS=32
TIMEOUT=30

# 启动zabbix-java-gateway
systemctl start zabbix-java-gateway
netstat -lntup|grep 10052
tcp6 0 0 :::10052 :::* LISTEN 13042/java

# 修改zabbix-server 配置文件
vim /etc/zabbix/zabbix_server.conf
JavaGateway=10.0.0.7 # java gateway地址
JavaGatewayPort=10052 # java gateway默认端口10052
StartJavaPollers=5 # 启动进程轮询java gateway

# 重启zabbix-server
systemctl restart zabbix-server

zabbix客户端

yum安装tomcat

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
# 安装tomcat
yum install -y tomcat

# 修改tomcat启动文件
vim /usr/libexec/tomcat/server
FLAGS="$JAVA_OPTS" # 在此行下面加入以下内容
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.53"

# jvm配置文件解析
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote # 启用远程监控JMX
-Dcom.sun.management.jmxremote.port=12345 # jmx启用远程端口,Zabbix添加时必须一致
-Dcom.sun.management.jmxremote.authenticate=false # 不开启用户密码认证
-Dcom.sun.management.jmxremote.ssl=false # 不启用ssl加密传输
-Djava.rmi.server.hostname=10.0.0.7" # 运行tomcat主机的IP地址

# 启动tomcat
systemctl start tomcat

# 检查端口是否启用
netstat -lntup|grep 12345

绿色安装tomcat(压缩包免安装)

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
# 安装tomcat服务
mkdir /soft/package/src -p
wget https://mirrors.aliyun.com/apache/tomcat/tomcat-9/v9.0.73/bin/apache-tomcat-9.0.73.tar.gz
tar xf apache-tomcat-9.0.73.tar.gz -C /soft/

# 创建tomcat软连接
ln -s /soft/apache-tomcat-9.0.73/ /soft/tomcat

# 开启tomcat的远程jvm配置文件
vim /soft/apache-tomcat-9.0.73/bin/catalina.sh
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.53"

# jvm配置文件解析
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote # 启用远程监控JMX
-Dcom.sun.management.jmxremote.port=12345 # jmx启用远程端口,Zabbix添加时必须一致
-Dcom.sun.management.jmxremote.authenticate=false # 不开启用户密码认证
-Dcom.sun.management.jmxremote.ssl=false # 不启用ssl加密传输
-Djava.rmi.server.hostname=10.0.0.7" # 运行tomcat主机的IP地址

# 重启tomcat服务
sh /soft/apache-tomcat-9.0.73/bin/shutdown.sh
sh /soft/apache-tomcat-9.0.73/bin/startup.sh

网页配置(zabbix添加tomcat主机,并添加Zabbix自带java监控模板)

image-20230327000822638

Zabbix监控MySQL

网页配置监控

1
2
3
4
5
# 安装mariadb
yum install -y mariadb-server

# 启动mariadb
systemctl start mariadb

image-20230327204840569

image-20230327204842072

image-20230327204845366

image-20230327204847777

手动配置监控

percona Monitoring Plugins 是一个高质量的组件,为MySQL 数据库添加企业级的监控和图表功能。但其脚本使
用PHP 实现,故而Zabbix-Agent 需要安装PHP 环境。

percona工具集

准备环境

服务器系统 角色 IP
CentOS 7.4 x86_64 Zabbix-Server 10.0.0.8
CentOS 7.4 x86_64 Zabbix-Agent 10.0.0.7

配置流程

  1. 在Zabbix-Agent 端安装percona Monitoring Plugins

    1
    2
    3
    yum install -y http://www.percona.com/downloads/perconarelease/
    redhat/0.1-3/percona-release-0.1-3.noarch.rpm
    yum install percona-zabbix-templates -y
  2. 查看percona 安装后的目录结构

    1
    2
    3
    4
    5
    6
    7
    8
    tree /var/lib/zabbix/percona
    /var/lib/zabbix/percona
    ├── scripts #脚本文件路径
    │ ├── get_mysql_stats_wrapper.sh
    │ └── ss_get_mysql_stats.php
    └── templates
    ├── userparameter_percona_mysql.conf #key文件位置
    └── zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml #模板文件位置
  3. 将自定义监控项配置文件复制至/etc/zabbix_agentd.conf.d 目录下

    1
    2
    cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
    /etc/zabbix/zabbix_agentd.d/percona_mysql.conf
  4. 重启zabbix-agent

    1
    systemctl restart 1 zabbix-agent
  5. 修改脚本中的MySQL 用户名和密码

    1
    2
    3
    4
    vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
    $mysql_user = 'root';
    $mysql_pass = '123';
    $mysql_port = 3306;
  6. 在Zabbix-Server 端上使用Zabbix_get 获取值(否则会失败)

    1
    2
    3
    4
    5
    6
    7
    zabbix_get -s 10.0.0.7 -k MySQL.pool-read-requests
    223003813
    //如果获取不到值常见问题
    1.看是否是MySQL密码错误
    2.不要直接执行脚本来获取
    3.删除/tmp/localhost-mysql_cacti_stats.txt文件
    4.权限问题导致
  7. 在Zabbix页面模板选项中导入Percona模板, 模板存放在/var/lib/zabbix/percona/templates , 最后关联主机即可。

Zabbix监控redis

网页配置监控

安装redis

1
2
3
4
5
# 安装redis
yum install -y redis

# 启动redis
systemctl start redis

image-20230327205641046

image-20230327205644001

image-20230327205647133

image-20230327205649803

手动配置监控

Redis 使用自带的INFO 命令,进行状态监控。以一种易于解释且易于阅读的格式,返回关于Redis 服务器的各种信息和统计数值。

准备环境

服务器系统 角色 IP
CentOS 7.4 x86_64 Zabbix-Server 10.0.0.8
CentOS 7.4 x86_64 Zabbix-Agent 10.0.0.7

操作流程

  1. 编写Shell脚本

    • 脚本端口、连接redis服务地址根据具体情况进行修改
    • AUTH认证没有开启,将PASSWD修改为空即可。
    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
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    mkdir -p /etc/zabbix/scripts

    vim /etc/zabbix/scripts/redis_status.sh
    #!/bin/bash
    ############################################################
    # $Name: redis_status.sh
    # $Version: v1.0
    # $Function: Redis Status
    # $Author: DriverZeng
    # $organization: www.driverzeng.com
    # $Create Date: 2016-06-23
    # $Description: Monitor Redis Service Status
    ############################################################

    R_COMMAND="$1"
    R_PORT="6379" #根据实际情况调整端口
    R_SERVER="127.0.0.1" #根据具体情况调整IP地址
    PASSWD="" #如果没有设置Redis密码,为空即可

    redis_status(){
    (echo -en "AUTH $PASSWD\r\nINFO\r\n";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT"
    > /tmp/redis_"$R_PORT".tmp
    REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
    echo "$REDIS_STAT_VALUE"
    }

    case $R_COMMAND in
    used_cpu_user_children)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_sys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    total_commands_processed)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    role)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    lru_clock)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    latest_fork_usec)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keyspace_misses)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keyspace_hits)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    expires)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    expired_keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    evicted_keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    connected_clients)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    changes_since_last_save)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    blocked_clients)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    bgsave_in_progress)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    bgrewriteaof_in_progress)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_memory_peak)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_memory)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_user)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_sys_children)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    total_connections_received)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    *)
    echo $"USAGE:$0
    {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}"
    esac
    • Redis状态参数解释:
    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
    server : Redis 服务器信息,包含以下域:
    redis_version : Redis 服务器版本
    redis_git_sha1 : Git SHA1
    redis_git_dirty : Git dirty flag
    os : Redis 服务器的宿主操作系统
    arch_bits : 架构(32 或 64 位)
    multiplexing_api : Redis 所使用的事件处理机制
    gcc_version : 编译 Redis 时所使用的 GCC 版本
    process_id : 服务器进程的 PID
    run_id : Redis 服务器的随机标识符(用于 Sentinel 和集群)
    tcp_port : TCP/IP 监听端口
    uptime_in_seconds : 自 Redis 服务器启动以来,经过的秒数
    uptime_in_days : 自 Redis 服务器启动以来,经过的天数
    lru_clock : 以分钟为单位进行自增的时钟,用于 LRU 管理
    clients : 已连接客户端信息,包含以下域:
    connected_clients : 已连接客户端的数量(不包括通过从属服务器连接的客户端)
    client_longest_output_list : 当前连接的客户端当中,最长的输出列表
    client_longest_input_buf : 当前连接的客户端当中,最大输入缓存
    blocked_clients : 正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量
    memory : 内存信息,包含以下域:
    used_memory : 由 Redis 分配器分配的内存总量,以字节(byte)为单位
    used_memory_human : 以人类可读的格式返回 Redis 分配的内存总量
    used_memory_rss : 从操作系统的角度,返回 Redis 已分配的内存总量(俗称常驻集大小)。这个值和 top 、ps 等命令的输出一致。
    used_memory_peak : Redis 的内存消耗峰值(以字节为单位)
    used_memory_peak_human : 以人类可读的格式返回 Redis 的内存消耗峰值
    used_memory_lua : Lua 引擎所使用的内存大小(以字节为单位)
    mem_fragmentation_ratio : used_memory_rss 和 used_memory 之间的比率
    persistence : RDB 和 AOF 的相关信息
    stats : 一般统计信息
    replication : 主/从复制信息
    cpu : CPU 计算量统计信息
    commandstats : Redis 命令统计信息
    cluster : Redis 集群信息
    keyspace : 数据库相关的统计信息
    参数还可以是下面这两个:
    all : 返回所有信息
    default : 返回默认选择的信息
    当不带参数直接调用 INFO 命令时,使用 default 作为默认参数。
  2. 添加脚本执行权限

    1
    chmod +x /etc/zabbix/scripts/1 redis_status.sh
  3. Zabbix权限不足处理办法

    1
    rm -f /tmp/redis_6379.tmp
  4. key的redis_status.conf 的配置文件如下:

    1
    2
    cat /etc/zabbix/zabbix_agentd.d/redis_status.conf
    UserParameter=redis_status[*],/bin/bash /etc/zabbix/scripts/redis_status.sh "$1"
  5. 重启zabbix-agent

    1
    systemctl restart 1 zabbix-agent
  6. 在Zabbix-Server 使用Zabbix_get 获取值

    1
    2
    zabbix_get -s 10.0.0.7 -k redis_status[used_cpu_sys]
    16.81

zabbix监控web

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 域名解析
vim /etc/hosts
172.16.1.71 zabbix.xxx.com

# 模拟访问url
curl -L -c cook 'http://zabbix.xxx.com/index.php'
-b # cookie字符串或文件读取位置,使用option来把上次的cookie信息追加到http request里面去。
-c # 操作结束后把cookie写入到这个文件中

# 查看本地cook
cat cook

# 模拟访问并登陆url
curl -L -c cook -b cook -d 'name=Admin&password=zabbix&autologin=1&enter=Sign+in' 'http://zabbix.xxx.com/index.php'

curl -L -c cook -b cook 'http://zabbix.xxx.com/queue.php'

Web场景监测网页配置

我们使用Zabbix Web 监控来监控Zabbix的Web界面。我们想知道它是否可用、是否正常工作以及响应速度。所以我们必须使用用户名和密码登录。

image-20230327212206810

image-20230327212209693

image-20230327212212674

访问zabbix

image-20230327212243080

登录zabbix

image-20230327212254390

检查zabbix

image-20230327212304038

退出zabbix

image-20230327212312310

检查是否注销

image-20230327212320601

汇总

image-20230327212328805

image-20230327212334312