监控系统 服务器配置,Zabbix服务器监控系统部署之自定义监控项的添加及配置(二)...

上一篇文章(Zabbix分布式服务器监控系统安装及部署(一))记录了Zabbix整套系统的安装及部署,其中包含Server端和client段,主要是说安装及配置的事儿了,本文章主要记录Zabbix的自定义监控项配置。

因为我用到只是监控mysql的一些数据等信息,所以也只记录这一块儿的,按照官方帮助文档中的说法,Zabbix提供了mysql的监控的模板,需要用户自己下载导入,官方下载地址,或者下载我提供的备用的:template_MySql。

下载后在Zabbixweb管理页面中导入,Configuration--- Templates --- Import Templates.选择相应xml模板导入即可。

8f1f827ee3472e701583c9c81f278087.png

编辑 etc/zabbix 下的配置文件,zabbix_agentd.conf 最下方,将以下内容前面的#去掉,记得将mysql的账号跟密码换掉:

UserParameter=mysql.ping,mysqladmin -uroot -ppasswd ping|grep alive|wc -l

UserParameter=mysql.uptime,mysqladmin -uroot -ppasswd status|cut -f2 -d":"|cut -f1 -d"T"

UserParameter=mysql.threads,mysqladmin -uroot -ppasswd status|cut -f3 -d":"|cut -f1 -d"Q"

UserParameter=mysql.questions,mysqladmin -uroot -ppasswd status|cut -f4 -d":"|cut -f1 -d"S"

UserParameter=mysql.slowqueries,mysqladmin -uroot -ppasswd status|cut -f5 -d":"|cut -f1 -d"O"

UserParameter=mysql.qps,mysqladmin -uroot -ppasswd status|cut -f9 -d":"

UserParameter=mysql.version,mysql -V

以上自带的监控参数比较简单。

若不够的话,可以将在上述目录下执行以下命令:

vi gz_status.py

创建这样一个新的文件,在里面输入以下内容:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

#File:gz_status.py

import MySQLdb,sys

user = 'root'

passwd = 'passwd'

a = sys.argv[1]

try:

conn = MySQLdb.connect(host = '127.0.0.1',user = user,passwd = passwd,connect_timeout = 2)

cursor = conn.cursor()

sql = "SHOW STATUS"

cursor.execute(sql)

alldata = cursor.fetchall()

for data in alldata:

if data[0] == a :

#print data[0],data[1]

print data[1]

break

cursor.close()

conn.close()

except Exception, e:

print e

sys.exit()

'''''Open_tables

Opened_tables

Max_used_connections

Threads_connected

Qcache_free_blocks

Qcache_total_blocks

Handler_read_first

Handler_read_key

Handler_read_rnd_next

Slow_queries'''

保存。然后在zabbix_agentd.conf下方加入以下内容:

UnsafeUserParameters=1

UserParameter=mysql.Open_tables,/etc/zabbix/gz_status.py Open_tables

UserParameter=mysql.Opened_tables,/etc/zabbix/gz_status.py Opened_tables

UserParameter=mysql.Max_used_connections,/etc/zabbix/gz_status.py Max_used_connections

UserParameter=mysql.Threads_connected,/etc/zabbix/gz_status.py Threads_connected

UserParameter=mysql.Qcache_free_blocks,/etc/zabbix/gz_status.py Qcache_free_blocks

UserParameter=mysql.Qcache_total_blocks,/etc/zabbix/gz_status.py Qcache_total_blocks

UserParameter=mysql.Handler_read_first,/etc/zabbix/gz_status.py Handler_read_first

UserParameter=mysql.Handler_read_key,/etc/zabbix/gz_status.py Handler_read_key

UserParameter=mysql.Handler_read_rnd_next,/etc/zabbix/gz_status.py Handler_read_rnd_next

UserParameter=mysql.Slow_queries,/etc/zabbix/gz_status.py Slow_queries

接着便可以在web中添加图形之类的直观数据了。。。

下面记录添加自定义的监控,如:监控用户数的增长,或者某个端口的情况等...

在zabbix_agentd.conf中,加入以下内容:

UserParameter=myhost.user,mysql -u root -ppasswd -e "use you_dbname;select count(*) from user" |tail -1

解释:

myhost.user 为Key,回头web设置中需要用到;

-u root -ppasswd 为mysql的用户名密码;

you_dbname 你要操作的数据库;

select count(*) from user sql语句;

UserParameter=myhost.port1005,netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'1005'")) c=c+1}} END{print c}'

以上一句为端口监听。将1005换成你需要监听的端口号就可以。

重启Zabbix-agentd服务。

sudo service zabbix-agent restart

然后可以在Zabbix Server服务器上测试下是否监听成功,命令:

zabbix_get -s 192.168.1.106 -k myhost.user

若成功的话,便会显示出查得的数据了。

接着在 web中添加items,操作步骤,找到:Configuration —— Hosts —— 点击相应host的itmes,进入后会列出当前该主机的itmes列表,点击右上角Create item。

9e96a13152850d05c8b5e33fca593bec.png

完成后,在创建图表的时候,便可以选择这个监控项了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值