Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the visual monitoring of MongoDB graphics for development?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What is the visual monitoring of MongoDB graphics for development? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Brief introduction

A visual MongoDB graphic monitoring tool for R & D personnel draws lessons from the monitoring indicators output by Percona PMM Grafana and the official mongostat tool, and removes some unnecessary and incomprehensible monitoring items. At present, the number of database connections, QPS/TPS, memory utilization statistics, replica set replset status information and synchronous replication delay are collected.

Remote connection is used to get data, so there is no need to deploy relevant agent or planning tasks on the database server, and Wechat and e-mail alarm can be realized.

Note: the monitoring environment is MongoDB version 3.2 or above, and version 2.x is not tested.

Mongo status monitoring. Click on the chart to view the history graph:

1. Number of connections

2. QPS chart

Environment building

1. Php-mysql driver installation:

Shell > yum install-y php-pear php-devel php gcc openssl openssl-devel cyrus-sasl cyrus-sasl-devel httpd mysql php-mysql

2. Php-mongo driver installation:

Shell > pecl install mongo

Add extension=mongo.so to the last line of / etc/php.ini

Restart the httpd service, service httpd restart

Note: if an error is reported through the pecl installation, please refer to the link below for source code installation. The driver version corresponding to PHP version 5.4 is mongodb-1.3.4.tgz.

Reference link: https://www.runoob.com/mongodb/mongodb-install-php-driver.html

3. Create MongoDB super user permissions (used when monitoring and collecting data):

First, we create an authorized account on the monitored database side to allow the collector server to connect to the MongoDB database. Because you need to execute the commands db.runCommand ({serverStatus:1,repl:1}) .repl and db.adminCommand ({replSetGetStatus: 1}) .members, you need to grant the root role as follows:

> use admin > db.createUser ({user: "admin", pwd: "123456", roles: [{role: "root", db: "admin"}]})

Mongo_monitor deployment

Extract the https://github.com/hcymysql/mongo_monitor/archive/master.zip installation package to the / var/www/html/ directory:

Cd / var/www/html/mongo_monitor/

Chmod 755. / mail/sendEmail

Chmod 755. / weixin/wechat.py

Note: email and Wechat alarms are called by third-party tools, so here to give executable permission 755.

1. Import the Mongo Monitor monitoring tool table structure (mongo_ monitor library):

Cd / var/www/html/mongo_monitor/

Mysql-uroot-p123456

< mongo_monitor_schema.sql 2、录入被监控主机的信息: INSERT INTO `mongo_status_info` (ip,tag,USER,pwd,PORT,authdb,send_mail_to_list,send_weixin_to_list,threshold_alarm_connection,threshold_alarm_repl) VALUES('10.10.159.31','MongoDB测试机1','admin','hechunyang','27017','admin','hechunyang','hechunyang@126.com',1000,60); 注,以下字段可以按照需求变更: ip字段含义:输入被监控Mongo的IP地址 tag字段含义:输入被监控Mongo的业务名字 user字段含义:输入被监控Mongo的用户名(ROOT权限) pwd字段含义:输入被监控Mongo的密码 port字段含义:输入被监控MySQL的端口号 authdb字段含义:输入被监控Mongo的数据库登录权限认证库名 monitor字段含义:0为关闭监控(也不采集数据,直接跳过);1为开启监控(采集数据) send_mail字段含义:0为关闭邮件报警;1为开启邮件报警 send_mail_to_list字段含义:邮件人列表 send_weixin字段含义:0为关闭微信报警;1为开启微信报警 send_weixin_to_list字段含义:微信公众号 threshold_alarm_connection字段含义:设置连接数阀值(单位个) threshold_alarm_repl字段含义:设置主从复制延迟阀值(单位秒) 3、修改conn.php配置文件: vim /var/www/html/mongo_monitor/conn.php $con = mysqli_connect("127.0.0.1","admin","hechunyang","mongo_monitor","3306") or die("数据库链接错误".mysql_error()); 改成你的Mongo Monitor监控工具表结构(mongo_monitor库)连接信息。 4、修改邮件报警信息: cd /var/www/html/mongo_monitor/mail/ vim mail.php system("./mail/sendEmail -f chunyang_he@139.com -t '{$this->

Send_mail_to_list}'- s smtp.139.com:25-u'{$this- > alarm_subject}'- o message-charset=utf8-o message-content-type=html-m 'alarm message:

{$this- > alarm_info}'- xu chunyang_he@139.com-xp '123456'-o tls=no ")

Change it to your sender's address and account password without changing the variables in it.

5. Modify Wechat alarm message:

Cd / var/www/html/mongo_monitor/weixin/

Vim wechat.py

Wechat Enterprise account setting step https://github.com/X-Mars/Zabbix-Alert-WeChat/blob/master/README.md see the configuration of this tutorial.

6. Scheduled tasks are crawled every minute:

Crontab-l

* / 1 * cd / var/www/html/mongo_monitor; / usr/bin/php / var/www/html/mongo_monitor/check_mongo_status.php > / dev/null 2 > & 1 * / 1 * cd / var/www/html/mongo_monitor; / usr/bin/php / var/www/html/mongo_monitor/check_mongo_repl.php > / dev/null 2 > & 1

Check_mongo_status.php (used to collect Mongo status information and trigger alarm at the monitored end)

Check_mongo_repl.php (used to collect the master-slave replication information of the monitored Mongo and trigger the alarm)

7. Change the automatic refresh frequency of the page:

Vim mongo_replset_monitor.php

Http-equiv= "refresh" content= "600"

The default page automatically refreshes every 600 seconds.

8. Page visit:

Http://yourIP/mongo_monitor/mongo_replset_monitor.php

Add a hyperlink for easy access to your automated operation and maintenance platform.

The answer to the question about the visual monitoring of MongoDB graphics for development is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report