实战3 Cacti监控nginx、mysql、mongodb、memcached和php-fpm

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

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

首先说说在线上跑的监控(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的负载、终端用户的登陆个数、主机当前的进程数

wKioL1OzZZXwPH2GAALsVBoFPlM089.jpg

wKioL1OzZZ3D3w-AAAU_k72Z7c0100.jpg

wKioL1OzZaWj1vtoAATY-kNkdg4494.jpg

 

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

cacti监控nginx

cacti监控mysql

cacti监控mongodb

短信报警附截图

cacti监控memcached

cacti监控php-fpm

一、添加监控nginx监控模板

1、启动nginx的状态监控

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

wKioL1Oza7CC2QzRAASGaZ8We9k099.jpg

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

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

wKioL1OzbQ3hXNN2AAEvbDH5AgY828.jpg

3、重启nginx服务

wKioL1OzbUuAg1WRAAEfLmVuR-Y614.jpg

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

wKiom1OzbfaDFNJ8AADrsdc8uwU890.jpg

5、下载cacti监控nginx的模板

wKiom1Ozb97wmM97AAMmhblm1wo190.jpg

6、模板拷贝、模板导入

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

wKiom1OzcOfS0cXkAAJ2OlTfVdo140.jpg

wKioL1OzcaqikHtRAAcMGdyWvr8294.jpg 

导入成功后如下所示:

wKioL1OzcimgeFejAAKf_Jk4oPI825.jpg

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

wKiom1Ozc-3z7hkeAAI1g2yMmEc334.jpg

 

二、安装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、添加远程监控主机

wKiom1OzdpyxiWsJAAMM5RvKZEA775.jpg

wKioL1Ozdm6Af6G8AAWaaTvVICY823.jpg

wKiom1Ozdp3xWekJAALmSyC-ui0757.jpg

4、添加nginx的监控模板

wKioL1OzdyfCbRP2AAcBLsjexys441.jpg

wKiom1Ozd0Tgb70OAAR_FNwPD94138.jpg

wKiom1Ozd5ej7963AALHCMaLcbM946.jpg

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

wKioL1Ozd7_gqmHTAATSTFF3bGs396.jpg

wKiom1OzeDLC_nFXAAMMWmSZKaE916.jpg

wKioL1OzeAOTr36nAAT1aFOd3WA579.jpg

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

wKioL1OzeenSUZd8AAGq_xAXIUg527.jpg

wKiom1OzehehyhMBAAJa1ruCAs0541.jpg

wKioL1OzeemSSs3HAANUFAJt1Ec607.jpg

wKiom1OzehiBA-aYAAOdYgASP3M028.jpg

wKioL1OzeemS3gfgAAMw2XPYyeE707.jpg

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

wKioL1Ozemng1eTGAAThaZs_Tr8463.jpg

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

wKioL1Oze8vR6y9_AAD2_kMnI9c590.jpg

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

wKiom1OzfSOBdaVAAADkdBqHauo370.jpg

3、cacti状态监控图

wKioL1OzhMTAM9owAAQUNyqgpV0318.jpg

 

 

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监控模板

wKiom1OznRjDDLgyAAdN8D9xKis118.jpg

导入成功如下:

wKiom1OznUSCrlNlAAXBexlGQtE964.jpg

 

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

wKiom1OznoaB1aiHAANmLewW_6s433.jpg

wKiom1OznofQClHDAAVLboE3PpU567.jpg

wKioL1OznljTA4sXAAN92qwhTXw200.jpg

wKioL1OznljBFYC7AAS5ZLL7zgA940.jpg

wKiom1OznofDYg_wAAUgEDF3k2Q900.jpg

wKioL1OznlnTiIXiAAVpH_euj0c834.jpg

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

wKioL1OzoFrD0c-HAAUe_5a6HTI981.jpg

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

 wKiom1Ozo8CCN7EBAAUweRBOEQ4530.jpg

cacti监控mongodb

cacti服务器地址:172.16.3.154

mongodb服务器地址:172.16.3.188

 一、ssh双机互联

因为cacti监控mongodb是需要登录到mongodb的服务端运行mongo的状态获取命令,所以需要ssh连接登录。所以需要配置非交互式帐号密码登录。这里采用公私钥模式。

先在监控服务器生成一对公私钥。

1、监控端和被监控端主机名互相解析

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
#ON Cacti
[root@cacti ~] # cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.3.188 mongodb
172.16.3.154 cacti.org 
#ON mongodb
[root@mongodb ~] # cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.3.188 mongodb
172.16.3.154 cacti.org
#ON Test
[root@cacti ~] # ping cacti.org
PING cacti.org (172.16.3.154) 56(84) bytes of data.
64 bytes from cacti.org (172.16.3.154): icmp_seq=1 ttl=64  time =0.023 ms
64 bytes from cacti.org (172.16.3.154): icmp_seq=2 ttl=64  time =0.032 ms
64 bytes from cacti.org (172.16.3.154): icmp_seq=3 ttl=64  time =0.038 ms
^C
--- cacti.org  ping  statistics ---
3 packets transmitted, 3 received, 0% packet loss,  time  2270ms
rtt min /avg/max/mdev  = 0.023 /0 .031 /0 .038 /0 .006 ms
You have new mail  in  /var/spool/mail/root
[root@cacti ~] # ping mongodb
PING mongodb (172.16.3.188) 56(84) bytes of data.
64 bytes from mongodb (172.16.3.188): icmp_seq=1 ttl=64  time =0.633 ms
64 bytes from mongodb (172.16.3.188): icmp_seq=2 ttl=64  time =0.295 ms
64 bytes from mongodb (172.16.3.188): icmp_seq=3 ttl=64  time =0.171 ms
64 bytes from mongodb (172.16.3.188): icmp_seq=4 ttl=64  time =0.274 ms
64 bytes from mongodb (172.16.3.188): icmp_seq=5 ttl=64  time =0.234 ms
^C
--- mongodb  ping  statistics ---
5 packets transmitted, 5 received, 0% packet loss,  time  4631ms
rtt min /avg/max/mdev  = 0.171 /0 .321 /0 .633 /0 .162 ms

2、配置ssh公私钥无需密码登录:

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
[root@cacti ~]# ssh-keygen 
Generating  public / private  rsa key pair.
Enter file  in  which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty  for  no passphrase): 
Enter same passphrase again: 
Your identification has been saved  in  /root/.ssh/id_rsa.
Your  public  key has been saved  in  /root/.ssh/id_rsa.pub.
The key fingerprint  is :
6e: 41 : 27 :2e:ff:fc: 09 : 00 : 42 : 13 :7f: 14 : 95 :dc:da:8d root@cacti.org
The key's randomart image  is :
+--[ RSA  2048 ]----+
|    +.  o+.o     |
|   . o .  o .    |
|    . o + .o o   |
|     . = o. E .  |
|      . S        |
|       + o       |
|        + .      |
|       . o . .   |
|          o.o    |
+-----------------+ 
[root@cacti ~]# cd /root/.ssh/
[root@cacti .ssh]# ll
总用量  8
-rw-------.  1  root root  1675  7 月    2  16 : 01  id_rsa     #公钥
-rw-r--r--.  1  root root   396  7 月    2  16 : 01  id_rsa.pub #私钥
[root@cacti .ssh]# chmod  600  *
[root@cacti .ssh]# ll
总用量  8
-rw-------.  1  root root  1675  7 月    2  16 : 01  id_rsa
-rw-------.  1  root root   396  7 月    2  16 : 01  id_rsa.pub
[root@cacti .ssh]# scp id_rsa mongodb:/root/
id_rsa                                                       100 1675      1 .6KB/s    00 : 00   
[root@cacti .ssh]# scp id_rsa.pub mongodb:/root/
id_rsa.pub                                                   100 %   396      0 .4KB/s    00 : 00 
#ON mongodb
[root@mongodb ~]# cat id_rsa.pub >> .ssh/authorized_keys 
#测试是否远程无密码登陆mongodb数据库
[root@cacti ~]# ssh mongodb
Last login: Wed Jul   2  16 : 10 : 31  2014  from cacti.org
[root@mongodb ~]# hostname
mongodb

3、配置监控脚本

拷贝模板中ssh的配置文件

1
2
3
4
5
6
7
8
[root@cacti ~]# cd better-cacti-templates- 1.1 . 8 /scripts/
[root@cacti scripts]# ll ss_get_by_ssh.php 
-rw-rw-r--.  1  cactiuser cactiuser  52856  1 月   23  2011  ss_get_by_ssh.php  #这个脚本需要放在cacti服务器端
[root@cacti scripts]# cp ss_get_by_ssh.php / var /www/html/cacti0. 88 /scripts/
[root@cacti ~]# cd / var /www/html/cacti0. 88 /scripts/
[root@cacti scripts]# chmod  755  ss_get_by_ssh.php
[root@cacti scripts]# ll ss_get_by_ssh.php 
-rwxr-xr-x.  1  root root  52846  7 月    2  14 : 49  ss_get_by_ssh.php

修改ssh的模板文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@cacti scripts]# vim ss_get_by_ssh.php 
# ============================================================================
$ssh_user   =  'root' ;                          # SSH username  
$ssh_port   =  22 ;                               # SSH port
$ssh_iden   =  '-i /root/.ssh/id_rsa' ;  # SSH identity
$ssh_tout   =  10 ;                               # SSH connect timeout
$nc_cmd     =  'nc -C -q1' ;                      # How to invoke netcat
$cache_dir  =  '/tmp' ;  # If  set this  uses caching to avoid multiple calls.
$poll_time  =  300 ; # Adjust to match your polling interval.
$use_ss     = FALSE; # Whether to  use  the script server or not
$use_ssh    = TRUE;  # Whether to connect via SSH or not ( default  yes).
$debug      = FALSE; # Define whether you want debugging behavior.
$debug_log  = FALSE; # If $debug_log  is  a filename, it'll be used. 
注释:ssh连接远程主机的用户,公钥的路径,缓存的路径和目录;大约在 39 行后

还可以修改默认的端口号,如下

1
2
3
4
5
6
7
8
9
   51  # Parameters  for  specific graphs can be specified here, or  in  the .cnf file.
   52  $status_server =  'localhost' ;             # Which server to query
   53  $status_url    =  '/server-status' ;        # Where Apache status lives
   54  $http_user     =  '' ;
   55  $http_pass     =  '' ;
   56  $memcache_port =  11211 ;                   # Which port memcached listens on
   57  $redis_port    =  6379 ;                    # Which port redis listens on
   58                                            # How to  get  openvz stats
   59  $openvz_cmd    =  'cat /proc/user_beancounters' ;

如果是mongodb不是正常端口启动,则需要这样修改。找到以下字段,添加红色字段,这里注意mongo这个命令一定要找对。

1
2
3
function  mongodb_cmdline ( $options ) { 
return  “echo \”db._adminCommand({serverStatus: 1 , repl: 1 })\” | /usr/local/mongo/mongodb/bin/mongo –port  10000 ″; 
}

以上配置完成后,保存退出

然后用命令测试是否有数据输出

1
2
3
[root@cacti ~]# php / var /www/html/cacti0. 88 /scripts/ss_get_by_ssh.php --type mongodb --host  172.16 . 3.188  --items c,de,df,dg,dh,di,dj,dk,dl,dm,dn, do ,dp,dq,dr,ds,dt,du
#如果有以下输出。表示是正常的
de: 83886080  df: 479199232  dg: 2  dh: 2  di: 0  dj: 0  dk: 39  dl: 1  dm: 0  dn: 0  do : 1  dp: 75  dq: 0  dr: 0  ds: 0  dt

4、添加mongodb模板

wKioL1Ozw2LRoftsAAb3Lz2KV-I071.jpg

wKioL1Ozw2OTjUqtAAbyiGB6Swc173.jpg

wKiom1Ozw5KTegMQAAL8NZI3NoI452.jpg

wKioL1Ozw2OhCdPwAAO8EzvYmSs251.jpg

5、cacti监控mongodb起始图,如下

 wKiom1OzxEXx5pW0AAHyucq3Cmo621.jpg

 稍等片刻,刷新页面,如下

wKioL1OzxD3jqrmlAAUsLoHlsbA912.jpg

 

短信报警附截图

wKioL1Ozx4mAkUjuAAdLMIer7I0019.jpg

 

cacti监控memcached

可以参考这个博文:http://storysky.blog.51cto.com/628458/251870

 wKiom1O1Du-y3FoAAATExtce8Fc402.jpg

 

 

cacti监控php-fpm

暂时还没有完成,模板导入后不绘图,正在研究中。。。。。。

 




     本文转自zys467754239 51CTO博客,原文链接:http://blog.51cto.com/467754239/1433409,如需转载请自行联系原作者




 

相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
打赏
0
0
0
0
349
分享
相关文章
|
4月前
|
微服务——MongoDB实战演练——需求分析
本文档《5-MongoDB实战演练》聚焦于某头条文章评论业务的需求分析与功能实现。基于MongoDB,需完成以下功能:1)提供基本的增删改查API;2)支持通过文章ID查询相关评论;3)实现评论点赞功能。结合实际业务场景,演示MongoDB在数据存储与操作中的应用,附带示意图帮助理解业务结构。
50 2
微服务——MongoDB实战演练——需求分析
微服务——MongoDB实战演练——文章评论的基本增删改查
本节介绍了文章评论的基本增删改查功能实现。首先,在`cn.itcast.article.dao`包下创建数据访问接口`CommentRepository`,继承`MongoRepository`以支持MongoDB操作。接着,在`cn.itcast.article.service`包下创建业务逻辑类`CommentService`,通过注入`CommentRepository`实现保存、更新、删除及查询评论的功能。最后,新建Junit测试类`CommentServiceTest`,对保存和查询功能进行测试,并展示测试结果截图,验证功能的正确性。
73 2
|
4月前
|
微服务——MongoDB实战演练——文章评论实体类的编写
本节主要介绍文章评论实体类的编写,创建了包`cn.itcast.article.po`用于存放实体类。具体实现中,`Comment`类通过`@Document`注解映射到MongoDB的`comment`集合,包含主键、内容、发布时间、用户ID、昵称等属性,并通过`@Indexed`和`@CompoundIndex`注解添加单字段及复合索引,以提升查询效率。同时提供了Mongo命令示例,便于理解和操作。
77 2
微服务——MongoDB实战演练——MongoTemplate实现评论点赞
本节介绍如何使用MongoTemplate实现评论点赞功能。传统方法通过查询整个文档并更新所有字段,效率较低。为优化性能,采用MongoTemplate对特定字段直接操作。代码中展示了如何利用`Query`和`Update`对象构建更新逻辑,通过`update.inc(&quot;likenum&quot;)`实现点赞数递增。测试用例验证了功能的正确性,确保点赞数成功加1。
81 0
微服务——MongoDB实战演练——根据上级ID查询文章评论的分页列表
本节介绍如何根据上级ID查询文章评论的分页列表,主要包括以下内容:(1)在CommentRepository中新增`findByParentid`方法,用于按父ID查询子评论分页列表;(2)在CommentService中新增`findCommentListPageByParentid`方法,封装分页逻辑;(3)提供JUnit测试用例,验证功能正确性;(4)使用Compass插入测试数据并执行测试,展示查询结果。通过这些步骤,实现对评论的高效分页查询。
59 0
微服务——MongoDB实战演练——文章微服务模块搭建
本节介绍文章微服务模块的搭建过程,主要包括以下步骤:(1)创建项目工程 *article*,并在 *pom.xml* 中引入依赖;(2)配置 *application.yml* 文件;(3)创建启动类 *cn.itcast.article.ArticleApplication*;(4)启动项目,确保控制台无错误提示。通过以上步骤,完成文章微服务模块的基础构建与验证。
53 0
ELK实现nginx、mysql、http的日志可视化实验
通过本文的步骤,你可以成功配置ELK(Elasticsearch, Logstash, Kibana)来实现nginx、mysql和http日志的可视化。通过Kibana,你可以直观地查看和分析日志数据,从而更好地监控和管理系统。希望这些步骤能帮助你在实际项目中有效地利用ELK来处理日志数据。
371 90
基于 PHP 的员工电脑桌面监控软件中图像差分算法的设计与实现研究
本文探讨了一种基于PHP语言开发的图像差分算法,用于员工计算机操作行为监控系统。算法通过分块比较策略和动态阈值机制,高效检测屏幕画面变化,显著降低计算复杂度与内存占用。实验表明,相比传统像素级差分算法,该方法将处理时间缩短88%,峰值内存使用量减少70%。文章还介绍了算法在工作效率优化、信息安全防护等方面的应用价值,并分析了数据隐私保护、算法准确性及资源消耗等挑战。未来可通过融合深度学习等技术进一步提升系统智能化水平。
38 2
MongoDB实战演练
本文介绍了基于Spring Boot和MongoDB实现文章评论功能的完整流程。主要包括需求分析、表结构设计、技术选型(如mongodb-driver与SpringDataMongoDB)、项目搭建及配置、实体类编写、基本增删改查功能实现、分页查询以及点赞功能的开发。通过Comment实体类、CommentRepository接口和CommentService服务层,实现了评论的存储、查询及更新操作,并利用MongoTemplate优化了点赞功能的性能。最后通过JUnit测试验证各功能的正确性。该方案适合需要高效处理非结构化数据的文章评论系统开发。
MongoDB实战演练
微服务——MongoDB实战演练——表结构分析
本文档来源于数据库articledb,展示了一张图片资源。图片宽度为1207像素,高度607像素,采用内联显示方式。内容涉及图像处理与样式设定,适用于文档或网页设计中多媒体元素的布局参考。图片来源为cdn.nlark.com,支持webp格式并附带水印处理。
53 1
微服务——MongoDB实战演练——表结构分析

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问