mysql监控nginx_实战3 Cacti监控nginx和mysql

在监控方面,两周的心得与大家共勉。

首先说说在线上跑的监控(cacti),两周下来没有出现问题,日志也没有出现报错的迹象,绘图,获取数据都是正常的。如下图所示:

至于监控,对于cacti来说,绘图是很直观的,一目了然,学会使用cacti,更重要的是要学会看坐标,还有坐标下面更详细的数值。

因为更多的模拟环境搭建是在vmware workstation上安装的,由于虚拟机的特殊性,快照,会使物理主机与vmware的主机时间

照成不一致,因此都采用ntpdate保持时间一致。[[email protected] ~]# crontab -e

*/1 * * * * /usr/sbin/ntpdate -u asia.pool.ntp.org

[[email protected] ~]# service crond start

监控的信息: 硬盘(本地硬盘和挂在硬盘)、内存、cpu的负载、终端用户的登陆个数、主机当前的进程数

926f30d8154dba8f25e062cce5a8f444.png

277b25dd017db86e8d09ff5f288d15a2.png

c5f0181a3c32ec81708a4ceb4b9bb9be.png

接下来就来看看cacti在监控应用层服务方面的功能!

cacti监控nginx

cacti监控mysql

一、添加监控nginx监控模板

1、启动nginx的状态监控

编译安装nginx,更多模块功能的启用可以使用

7eec491b2616ef356b402841cedfc60b.png

然后,在编译nginx的时候加入参数--with-http_stub_status_module

2、编辑配置文件nginx.conf,添加如下

12d24312834e98e63f48fe5b6073f0bf.png

3、重启nginx服务

ff8653dbd2a6d8ad796357d384d0ef51.png

4、访问nginx的状态监控页面

08af397548948a1cecf8d3cdecd7c490.png

5、下载cacti监控nginx的模板

9c7e19f07aade6d887ea66f80bad3f0e.png

6、模板拷贝、模板导入

注:把模板中以.pl的两文件拷贝到你的cacti目录下的scripts/目录下,然后把以.xml的文件导入到cacti中,导入方法

be22e71fb659db25adc0bcf2a539cbcb.png

263d9b1e307cdc04adfd32b58d02d329.png

导入成功后如下所示:

b38139444b9f16393b7c1fb8aff7987d.png

7、测试模板是否能够正常使用

da89b0981596007a98c6223fbd4590cf.png

二、安装nginx监控

1、安装net-snmp服务[[email protected] ~]# yum install -y net-snmp net-snmp-utils net-snmp-libs

2、配置snmpd配置文件并测试服务[[email protected] ~]# cd /etc/snmp/

[[email protected] snmp]# cp snmpd.conf snmpd.conf.bak

[[email protected] snmp]# vim snmpd.conf

#修改

view    systemview    included   .1.3.6.1.2.1

[[email protected] snmp]# service snmpd start

正在启动 snmpd:                                           [确定]

[[email protected] 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、添加远程监控主机

cd4ed8053178b5385ae8ef9bc94e653c.png

8494d644747f3bd2edeb9689bc8a7ed2.png

6ebb9e76521694922a1496a4107029ab.png

4、添加nginx的监控模板

15130850ac0adf8637b705ce7e66049c.png

e99c31c8ad5a57c0764567df75cac3d5.png

2b3fa5dbd32ad7cbbfae16e638690451.png

5、启用监控主机模板,如nginx

266ff065e311e41afe598aa13a4dc2eb.png

69826238e560785ce769d5b32a2a2483.png

4f45682664f11ac68d3c2c4b52c1af5b.png

6、创建graphs组为Remote Host,并将nginx加入到这个组中。

4f18de2d6c008473cf1af26af47f2d94.png

a319111c3c5b02ba105b1c218a1da370.png

9d1a734dfafac131207667dc3ff68eff.png

9dc319a7b5cdd5fc2b050af92f90c4fc.png

5b05df1b6070d2928bdfb9bb2e8614f5.png

6、监控nginx状态如下,等一会看看是否能绘图

4dc24b1dd96a6d84d49f077e632bae5c.png

三、apache自带的ab压力测试工具,来测试队绘图是否有影响

1、ab测试1000的并发量[[email protected] ~]# ab -c 1000 -n 1000    #反复的多测试几次

This is ApacheBench, Version 2.3 

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)

[[email protected] ~]# ab -c 1000 -n 1000 http://172.16.3.164/index.html

This is ApacheBench, Version 2.3 

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、查看状态监控页面

dec7c4b70e3278459e0186404c4b0a83.png

又反复的多次压力测试的结果

8e333f735a0f24bc953f960391e9c778.png

3、cacti状态监控图

afa08dfdce7cc61a73e96f52d18247db.png

cacti监控mysql

1、下载cacti监控mysql的模板

下载地址:http://code.google.com/p/mysql-cacti-templates/

软件:better-cacti-templates-1.1.8.tar.gz

2、解压模板[[email protected] ~]# 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

[[email protected] ~]# tar xf better-cacti-templates-1.1.8.tar.gz

[[email protected] ~]# cd better-cacti-templates-1.1.8

[[email protected] 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

[[email protected] scripts]# cd /var/www/html/cacti0.88/scripts/

[[email protected] scripts]# chmod 755 ss_get_

ss_get_by_ssh.php       ss_get_mysql_stats.php

[[email protected] scripts]# chmod 755 ss_get_*

3、修改监控mysql响应的php脚本[[email protected] ~]# cd better-cacti-templates-1.1.8/scripts/

[[email protected] 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监控模板

a135d409c58540a6b988777eb44ecb98.png

导入成功如下:

62319708c9b7de714cc7fd1ea9644a43.png

5、添加mysql监控模板到被监控主机

71d38465eb089afe39e7fca1f9f23293.png

62639625ee73d00df11c0bd1d8c3dacb.png

29e200a0581048f7d9eebc2554a057c0.png

39ca722a9162700a116aa0a29b2bc662.png

63d70290e258f43eed2351784b7c4643.png

b50f26e8ff0d31f13d9bd6f0b4bf02bd.png

6、被监控的mysql服务器需要创建监控用户

注:让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。[[email protected] ~]# 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 [email protected]"%" identified by "cactiuser";

Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to [email protected]"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

[[email protected] ~]# 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[[email protected] 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.

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| live               |

| mysql              |

| performance_schema |

| psp                |

| test               |

| vms2_1             |

| zqcms              |

| zqvms              |

+--------------------+

9 rows in set (0.00 sec)

mysql> \q

Bye

7、查看监控绘图

71af6607553a7156fc5524bd3ed27767.png

稍等一下,看是否能获取到mysql的数据

ea0bbd324e2166da91d46772afb557f4.png

原文:http://467754239.blog.51cto.com/4878013/1433409

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值