在监控方面,两周的心得与大家共勉。
首先说说在线上跑的监控(cacti),两周下来没有也出现问题,日志也没有报错的迹象,绘图,获取数据都是正常的。如下图所示:至于监控,对于cacti来说,绘图是很直观的,一目了然,学会使用cacti,更重要的是要学会看坐标,还有坐标下面更详细的数值。
因为更多的模拟环境搭建是在vmware workstation上安装的,由于虚拟机的特殊性,"快照",会使物理主机与vmware的主机时间造成不一致,因此都采用ntpdate保持时间一致,或者快照恢复后一定要重启机器,都是解决时间不一致的方法
1
2
3
|
[root@cacti ~]
# crontab -e
*
/1
* * * *
/usr/sbin/ntpdate
-u asia.pool.ntp.org
[root@cacti ~]
# service crond start
|
监控的信息: 硬盘(本地硬盘和挂在硬盘)、内存、cpu的负载、终端用户的登陆个数、主机当前的进程数
接下来就来看看cacti在监控应用层服务方面的功能!
cacti监控nginx
cacti监控mysql
cacti监控mongodb
短信报警附截图
cacti监控memcached
cacti监控php-fpm
一、添加监控nginx监控模板
1、启动nginx的状态监控
编译安装nginx,更多模块功能的启用可以使用
然后,在编译nginx的时候加入参数--with-http_stub_status_module
3、重启nginx服务
4、访问nginx的状态监控页面
5、下载cacti监控nginx的模板
6、模板拷贝、模板导入
注:把模板中以.pl的两文件拷贝到你的cacti目录下的scripts/目录下,然后把以.xml的文件导入到cacti中,导入方法
导入成功后如下所示:
7、测试模板是否能够正常使用
二、安装nginx监控
1、安装net-snmp服务
1
|
[root@lnmp ~]
# yum install -y net-snmp net-snmp-utils net-snmp-libs
|
2、配置snmpd配置文件并测试服务
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
|
[root@lnmp ~]
# cd /etc/snmp/
[root@lnmp snmp]
# cp snmpd.conf snmpd.conf.bak
[root@lnmp snmp]
# vim snmpd.conf
#修改
view systemview included .1.3.6.1.2.1
[root@lnmp snmp]
# service snmpd start
正在启动 snmpd: [确定]
[root@lnmp snmp]
# snmpnetstat -v 2c -c public -Can -Cp tcp localhost
Active Internet (tcp) Connections (including servers)
Proto Local Address Remote Address (state)
tcp *.22 *.* LISTEN
tcp *.80 *.* LISTEN
tcp *.3306 *.* LISTEN
tcp 127.0.0.1.199 *.* LISTEN
tcp 127.0.0.1.3306 127.0.0.1.34893 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34894 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34895 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34899 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34900 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34901 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34907 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34908 ESTABLISHED
tcp 127.0.0.1.3306 127.0.0.1.34909 ESTABLISHED
tcp 127.0.0.1.9000 *.* LISTEN
tcp 172.16.3.164.22 172.16.3.127.51102 ESTABLISHED
tcp 172.16.3.164.22 172.16.3.127.51230 ESTABLISHED
|
3、添加远程监控主机
4、添加nginx的监控模板
5、启用监控主机模板,如nginx
6、创建graphs组为Remote Host,并将nginx加入到这个组中。
6、监控nginx状态如下,等一会看看是否能绘图
三、apache自带的ab压力测试工具,来测试队绘图是否有影响
1、ab测试1000的并发量
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
[root@cacti ~]# ab -c
1000
-n
1000
#反复的多测试几次
This
is
ApacheBench, Version
2.3
<$Revision:
655654
$>
Copyright
1996
Adam Twiss, Zeus Technology Ltd, http:
//www.zeustech.net/
Licensed to The Apache Software Foundation, http:
//www.apache.org/
Benchmarking
172.16
.
3.164
(be patient)
Completed
100
requests
Completed
200
requests
Completed
300
requests
Completed
400
requests
Completed
500
requests
Completed
600
requests
^[[ACompleted
700
requests
Completed
800
requests
Completed
900
requests
Completed
1000
requests
Finished
1000
requests
Server Software: nginx
Server Hostname:
172.16
.
3.164
Server Port:
80
Document Path: /index.html
Document Length:
186
bytes
Concurrency Level:
1000
Time taken
for
tests:
1.307
seconds
Complete requests:
1000
Failed requests:
265
(Connect:
0
, Receive:
0
, Length:
265
, Exceptions:
0
)
Write errors:
0
Non-2xx responses:
735
Total transferred:
41371480
bytes
HTML transferred:
41190245
bytes
Requests per second:
765.32
[#/sec] (mean)
Time per request:
1306.640
[ms] (mean)
Time per request:
1.307
[ms] (mean, across all concurrent requests)
Transfer rate:
30920.40
[Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect:
114
123
6.2
122
135
Processing:
134
368
312.1
158
1079
Waiting:
101
227
143.7
157
570
Total:
259
492
316.0
273
1200
Percentage of the requests served within a certain time (ms)
50
%
273
66
%
613
75
%
769
80
%
866
90
%
1033
95
%
1113
98
%
1188
99
%
1196
100
%
1200
(longest request)
[root@cacti ~]# ab -c
1000
-n
1000
http:
//172.16.3.164/index.html
This
is
ApacheBench, Version
2.3
<$Revision:
655654
$>
Copyright
1996
Adam Twiss, Zeus Technology Ltd, http:
//www.zeustech.net/
Licensed to The Apache Software Foundation, http:
//www.apache.org/
Benchmarking
172.16
.
3.164
(be patient)
Completed
100
requests
Completed
200
requests
Completed
300
requests
Completed
400
requests
Completed
500
requests
Completed
600
requests
Completed
700
requests
Completed
800
requests
Completed
900
requests
Completed
1000
requests
Finished
1000
requests
Server Software: nginx
Server Hostname:
172.16
.
3.164
Server Port:
80
Document Path: /index.html
Document Length:
186
bytes
Concurrency Level:
1000
Time taken
for
tests:
1.329
seconds
Complete requests:
1000
Failed requests:
205
(Connect:
0
, Receive:
0
, Length:
205
, Exceptions:
0
)
Write errors:
0
Non-2xx responses:
795
Total transferred:
32081560
bytes
HTML transferred:
31906265
bytes
Requests per second:
752.26
[#/sec] (mean)
Time per request:
1329.324
[ms] (mean)
Time per request:
1.329
[ms] (mean, across all concurrent requests)
Transfer rate:
23568.11
[Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect:
116
123
6.1
121
144
Processing:
120
348
306.9
159
1079
Waiting:
91
255
181.6
158
670
Total:
251
471
305.9
277
1203
Percentage of the requests served within a certain time (ms)
50
%
277
66
%
392
75
%
704
80
%
790
90
%
1016
95
%
1101
98
%
1141
99
%
1192
100
%
1203
(longest request)
|
2、查看状态监控页面
又反复的多次压力测试的结果
3、cacti状态监控图
cacti监控mysql
1、下载cacti监控mysql的模板
下载地址:http://code.google.com/p/mysql-cacti-templates/
软件:better-cacti-templates-1.1.8.tar.gz
2、解压模板
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@cacti ~]# ll better-cacti-templates-
1.1
.
8
.tar.gz
-rw-r--r--.
1
root root
275805
7
月
2
13
:
25
better-cacti-templates-
1.1
.
8
.tar.gz
[root@cacti ~]# tar xf better-cacti-templates-
1.1
.
8
.tar.gz
[root@cacti ~]# cd better-cacti-templates-
1.1
.
8
[root@cacti better-cacti-templates-
1.1
.
8
]# ll scripts/
总用量
108
-rw-rw-r--.
1
cactiuser cactiuser
52856
1
月
23
2011
ss_get_by_ssh.php
-rw-rw-r--.
1
cactiuser cactiuser
53624
1
月
23
2011
ss_get_mysql_stats.php
[root@cacti scripts]# cd /
var
/www/html/cacti0.
88
/scripts/
[root@cacti scripts]# chmod
755
ss_get_
ss_get_by_ssh.php ss_get_mysql_stats.php
[root@cacti scripts]# chmod
755
ss_get_*
|
3、修改监控mysql响应的php脚本
1
2
3
4
5
6
7
8
9
|
[root@cacti ~]# cd better-cacti-templates-
1.1
.
8
/scripts/
[root@cacti scripts]# vim ss_get_mysql_stats.php
$mysql_user =
'cactiuser'
; #被监控mysql的账户
$mysql_pass =
'cactiuser'
; #被监控mysql账户的密码
$mysql_port =
3306
;
$mysql_ssl = FALSE; # Whether to
use
SSL to connect to MySQL.
$heartbeat =
''
; # db.tbl
in
case
you
use
mk-heartbeat from Maatkit.
$cache_dir =
'/tmp'
; # If
set
,
this
uses caching to avoid multiple calls.
$poll_time =
300
; # Adjust to match your polling interval.
|
4、导入监控mysql的模板,如下图
选择导入mysql监控模板
导入成功如下:
5、添加mysql监控模板到被监控主机
6、被监控的mysql服务器需要创建监控用户
注:让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。
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
|
[root@lnmp ~]
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 29
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> grant all privileges on *.* to cactiuser@
"%"
identified by
"cactiuser"
;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to cactiuser@
"localhost"
identified by
"cactiuser"
;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@lnmp ~]
# mysql -ucactiuser -pcactiuser
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 30
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| live |
| mysql |
| performance_schema |
| psp |
|
test
|
| vms2_1 |
| zqcms |
| zqvms |
+--------------------+
9 rows
in
set
(0.04 sec)
mysql> \q
Bye
|
7、监控主机测试是否能够远程登陆mysql
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
|
[root@cacti scripts]# mysql -ucactiuser -pcactiuser -h
172.16
.
3.164
Welcome to the MySQL monitor. Commands end
with
; or \g.
Your MySQL connection id
is
33
Server version:
5.5
.
33
-log MySQL Community Server (GPL)
Copyright (c)
2000
,
2013
, Oracle and/or its affiliates. All rights reserved.
Oracle
is
a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to clear the current input statement.
|