文章目录
一. 监控登录用户数量
- 在客户端操作 自定义监控项
1. 通过命令获取到你要得内容
[root@web01 ~]# who
root pts/1 2019-10-09 08:52 (10.0.0.1)
[root@web01 ~]# who|wc -l
1
[root@web01 ~]# who|wc -l
2
2. 在客户端配置key(键值) 自定义键值
- 路径: /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
配置键值
tail -1 /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
UserParameter=mysql.version,mysql -V
#查看数据库版本
UserParameter=键值,命令/脚本
英文单词
login.user
nginx.status
sda_tps
用户参数(用户自定义键值)
UserParameter=键值名称,命令/脚本/xxxx
#键值名称:单词 中间加上.
#login.user
UserParameter=login.user,who|wc -l
[root@web01 ~]# tail -2 /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf UserParameter=mysql.version,mysql -V
UserParameter=login.user,who|wc -l
#修改文件后重启服务生效
[root@web01 ~]# systemctl restart zabbix-agent.service
服务端测试
[root@oldboy-m01 ~]# zabbix_get -s 172.16.1.7 -k login.user
2
[root@oldboy-m01 ~]# zabbix_get -s 172.16.1.7 -k login.user
6
3. 配置web界面
创建模板
应用集
监控项
创建监控项相关名称 | 说明 |
---|---|
更新间隔 | 多长时间获取自定义得数据 |
历史数据保留时常 | 每个 更新间隔(30s)获取到的数据 存放过多导致磁盘空不足 |
趋势存储时间 | 记录数据趋势 减少磁盘空间使用 |
触发器
关联模板 把主机 与 模板绑定
图形
二. nginx状态:stub_status;
nginx准备
[root@web01 /]# ll /etc/nginx/conf.d/
total 12
-rw-r--r-- 1 root root 1093 Aug 13 23:02 default.conf
[root@web01 conf.d]# cat default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
`location /status {
allow 172.16.1.0/24;
deny all;
stub_status;
access_log off;
}`
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
[root@web01 /]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# nginx -s reload
[root@web01 conf.d]# curl 10.0.0.7/status
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
[root@web01 conf.d]# curl 172.16.1.7/status
Active connections: 1
server accepts handled requests
33 33 35
Reading: 0 Writing: 1 Waiting: 0
自定义选项
- 命令行取出索要的内容
- 脚本
- 自定义key
- 服务端测试
[root@web01 conf.d]# curl 172.16.1.7/status
Active connections: 1
server accepts handled requests
33 33 35
Reading: 0 Writing: 1 Waiting: 0
Active connections | 当前已经建立的连接(当前nginx的并发数量) | 实时的 |
server accepts | 服务器一共接收的了多少请求 总数 | 越来越大 |
handled | 服务器一共 已经处理 | 越来越大 |
requests | 用户一共发出多少次请求 | 越来越大 |
Reading | 读 服务端当前正在处理的请求头的数量 | 实时的 |
Writing | 写 服务端当前正在响应的响应头的数量 | 实时的 |
Waiting | 当前等待 排队数量 | 实时的 |
命令行取出索要的内容
active.
curl -s 172.16.1.7/status |awk 'NR==1{print $3}'
read
curl -s 172.16.1.7/status |awk 'NR==4{print $2}'
write.
curl -s 172.16.1.7/status |awk 'NR==4{print $4}'
wait .
curl -s 172.16.1.7/status |awk 'NR==4{print $6}'
自定义key
#UserParameter=nginx.active,curl -s 172.16.1.7/status |awk 'NR==1{print $3}'
.................................
推荐zabbix自定义监控使用脚本 及 参数传递
[root@web01 scripts]# cat nginx.sh
#!/bin/bash
case "$1" in
active) curl -s 172.16.1.7/status |awk 'NR==1{print $NF}' ;;
read) curl -s 172.16.1.7/status |awk 'NR==4{print $2}' ;;
write) curl -s 172.16.1.7/status |awk 'NR==4{print $4}' ;;
wait) curl -s 172.16.1.7/status |awk 'NR==4{print $6}' ;;
accept) curl -s 172.16.1.7/status |awk 'NR==3{print $1}' ;;
handle) curl -s 172.16.1.7/status |awk 'NR==3{print $2}' ;;
request) curl -s 172.16.1.7/status |awk 'NR==3{print $3}' ;;
esac
zabbix 自定义带参数的 key
#
UserParameter=nginx.status[*],sh /server/scripts/nginx.sh $1
#zabbix 自定义key的第1个参数
#服务端测试
zabbix_get -s 172.16.1.7 -k nginx.status[read] ||====> sh /server/scripts/nginx.sh read
`#zabbix自定义监控使用脚本 及 参数传递`
[root@web01 scripts]# cat /etc/zabbix/zabbix_agentd.d/nginx.conf
UserParameter=nginx.status[*],/bin/sh /server/scripts/nginx.sh "$1"
#修改配置文件后要重启服务
[root@web01 ~]# systemctl restart zabbix-agent.service
zabbix服务端测试
[root@m01 ~]# zabbix_get -s 172.16.1.7 -k nginx.status[active]
1
[root@m01 ~]# zabbix_get -s 172.16.1.7 -k nginx.status[read]
0
[root@m01 ~]# zabbix_get -s 172.16.1.7 -k nginx.status[accept]
36
web页面
- 修改模板
- 添加应用集
- 添加监控项
- 添加触发器
- 添加图片
修改模板
添加应用集
添加监控项