热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

实战3Cacti监控nginx和mysql

在监控方面,两周的心得与大家共勉。首先说说在线上跑的监控(cacti),两周下来没有出现问题,日志也没有出现报错的迹象,绘图,获取数据都是正常的。如下图所示:至于监控,对于cact

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

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

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

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

照成不一致,因此都采用ntpdate保持时间一致。

[root@cacti ~]# crontab -e
*/1 * * * * /usr/sbin/ntpdate -u asia.pool.ntp.org 
[root@cacti ~]# service crond start

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

,

,

,

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

cacti监控nginx

cacti监控mysql

一、添加监控nginx监控模板

1、启动nginx的状态监控

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

,

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

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

,

3、重启nginx服务

,

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

,

5、下载cacti监控nginx的模板

,

6、模板拷贝、模板导入

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

,

, 

导入成功后如下所示:

,

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

,

二、安装nginx监控

1、安装net-snmp服务

[root@lnmp ~]# yum install -y net-snmp net-snmp-utils net-snmp-libs

2、配置snmpd配置文件并测试服务

[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的并发量

[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、解压模板

[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脚本

[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”权限。

[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

[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.
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、查看监控绘图

,

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

 ,

本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1433409

实战3 Cacti监控nginx和mysql,,

实战3 Cacti监控nginx和mysql


推荐阅读
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • CentOS 6.5安装VMware Tools及共享文件夹显示问题解决方法
    本文介绍了在CentOS 6.5上安装VMware Tools及解决共享文件夹显示问题的方法。包括清空CD/DVD使用的ISO镜像文件、创建挂载目录、改变光驱设备的读写权限等步骤。最后给出了拷贝解压VMware Tools的操作。 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
author-avatar
千语千寻2012_501
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有