Zabbix_自定义监控项 (3)

一. 监控登录用户数量

  • 在客户端操作 自定义监控项

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页面

  • 修改模板
  • 添加应用集
  • 添加监控项
  • 添加触发器
  • 添加图片

修改模板

在这里插入图片描述

添加应用集

在这里插入图片描述

添加监控项

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

添加图形

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值