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
若采用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中查看模板中的监控项。
三 数据库优化(此部分转载,因时间关系,未能亲自验证,待有时间会把此部分自己试验结果奉上)
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()
|