zabbix性能优化之我见

zabbix是一个强大的网管工具,其功能和用途也随之多变,但万变不离其宗,对于庞大的监控系统性能优化、方案优化是不可缺少的。

以下是我阅读zabbix官方文档,结合两个项目的心得。

一、拓扑优化

zabbix再带proxy功能,因本公司自主研发私有云平台,故可以在个别项目上用虚拟机来作proxy服务器,在确保vm正常运作的前提下,减少了server端的负荷。

二、方案优化

那么有的同学说了,如果硬件条件有限且同一批次中标业务么有私有云,那么建议在agent端采取active checks模式,根据官网定义,虽然agent端有更复杂的流程,且有举例

1. Agent opens a TCP connection
2. Agent asks for the list of checks
3. Server responds with a list of items (item key, delay)4. Agent parses the response
5. TCP connection is closed
6. Agent starts periodical collection of data 

但是相对于被动agent,对于server的压力会大大减小,避免server端宕机,被动agent在此不做赘述,网上有很多部署方法。

若采用active checks模式,首先针对zabbix_agentd.conf文件修改

a)在ServerActive=xxx 填server端ip、

b)Hostname=xx 填agent的hostname 、

c)StartAgents=0 

注:如果此处值为0,那么passive checks 将被disable,同学们可以根据实际业务大小来分配主动、被动agent个数)


d)针对模板变更,

1.以任何一个现有模板为例,clone并重命名,假如重命名模板为TEST

2.将模板TEST里所有items和discovery rules里的items都变更type为atvice agent

3.将创建的host关联重命名的模板TEST,注意创建的时候,ip和port都填0,否则会因模式冲突看到一个红色的Z,让人觉得很不舒服,不是么


至此active-checks模式的agent部署完毕,可以在overview中查看模板中的监控项。


三 数据库优化(此部分转载,因时间关系,未能亲自验证,待有时间会把此部分自己试验结果奉上)

分享一个zabbix数据库的优化脚本,适合2.0版本。

对history,hostory_uint按日分区,trends,trends_uint按月分区;

关闭Houserkeeper:

vim zabbix_server.conf

DisableHousekeeper=1

对history,hostory_uint每日建立第二天的分区并删除45天前的分区

对trends,trends_uint每月20号建立下一个月的分区,并删除12个月前的分区

时间可以自己修改

由于events表的大小对仪表盘的展示速度影响很大,2.0以后的版本又对该表做过修改,具有主键约束,不能以clock做分区表优化,所以我每日都清理该表,只保留了3天的数据(根据自己的环境和需求而定,可以自己修改),很简单的一个定期维护脚本,希望能帮到大家


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
#!/usr/bin/env python
# coding: utf- 8
import  MySQLdb
import  datetime
now_time = datetime.datetime.now()
error_time = now_time.strftime( '%Y-%m-%d %H:%M:%S' )
theday = (now_time + datetime.timedelta(days=+ 1 )).strftime( '%Y%m%d' )
next_day = (now_time + datetime.timedelta(days=+ 2 )).strftime( '%Y-%m-%d' )
themonth = datetime.datetime(now_time.year,(now_time.month+ 1 ),now_time.day).strftime( '%Y%m' )
next_month = datetime.datetime(now_time.year,(now_time.month+ 2 ), 1 ).strftime( '%Y-%m-%d' )
last_time = (now_time - datetime.timedelta(days= 30 )).strftime( '%Y%m%d' )
last_time_month = datetime.datetime((now_time.year- 1 ),now_time.month,now_time.day).strftime( '%Y%m' )
events_time = (now_time - datetime.timedelta(days= 1 )).strftime( '%Y-%m-%d' )
history_time = (now_time - datetime.timedelta(days= 45 )).strftime( '%Y%m%d' )
trends_time = datetime.datetime((now_time.year- 1 ),now_time.month,now_time.day).strftime( '%Y%m' )
table_day=[ 'history' 'history_uint' ]
table_month=[ 'trends' 'trends_uint' ]
conn=MySQLdb.connect(host= 'localhost' ,user= 'zabbix' ,passwd= 'zabbix' ,db= 'zabbix' ,port= 3306 )
cur=conn.cursor()
for  name_d  in  table_day:
    try :
    ####新增分区#######
       cur.execute( 'ALTER TABLE `%s` ADD PARTITION (PARTITION p%s VALUES LESS THAN (UNIX_TIMESTAMP("%s 00:00:00")))'  % (name_d, theday, next_day))
                                                                                                                                                 
    except MySQLdb.Error,e:
        print  "[%s] Mysql Error %d: %s"  % (error_time, e.args[ 0 ], e.args[ 1 ])
        pass
for  name_m  in  table_month:
    try :
       ####新增分区#######
       if  now_time.day ==  20 :
          cur.execute( 'ALTER TABLE `%s` ADD PARTITION (PARTITION p%s VALUES LESS THAN (UNIX_TIMESTAMP("%s 00:00:00")))'  % (name_m, themonth, next_month))
    except MySQLdb.Error,e:
        print  "[%s] Mysql Error %d: %s"  % (error_time, e.args[ 0 ], e.args[ 1 ])
        pass
######清除events表 1 天前的数据######
try :
    cur.execute( 'DELETE FROM `events` where `clock` < UNIX_TIMESTAMP("%s 00:00:00")' % events_time)
    cur.execute( 'optimize table events;' )
except MySQLdb.Error,e:
    print  "[%s] Mysql Error %d: %s"  % (error_time, e.args[ 0 ], e.args[ 1 ])
    pass
######清除history,histroy_uint表 45 天前的数据######
for  name_d  in  table_day:
     try :
        cur.execute( 'ALTER TABLE `%s` DROP PARTITION p%s;'  % (name_d, history_time))
     except MySQLdb.Error,e:
        print  "[%s] Mysql Error %d: %s"  % (error_time, e.args[ 0 ], e.args[ 1 ])
        pass
######清除trends,trends_uint表一年前的数据######
for  name_m  in  table_month:
     try :
        cur.execute( 'ALTER TABLE `%s` DROP PARTITION p%s;'  % (name_m, trends_time))
     except MySQLdb.Error,e:
        print  "[%s] Mysql Error %d: %s"  % (error_time, e.args[ 0 ], e.args[ 1 ])
        pass
conn.commit()
cur.close()
conn.close()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值