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

Mongodb monitoring script

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The script covers two ways to monitor mongo: using the built-in mongostat tool to view, the location of each monitoring item may have to be adjusted according to the actual mongostat output; and entering the admin library to view specific status information may need to be verified.

Complete steps:

1. Create user roles for monitoring: the permissions of mongo users are divided by user roles

> use admin > db.getRoles () > db.createRole ({role: "mongostatRole", privileges: [{resource: {cluster:true}, actions: ["serverStatus"]}], roles: []}) / / create a user role with mongostat command permissions

two。 Create a system monitoring role

> db.getUsers () > db.createUser ({user: "dbmon", pwd: "password", roles: [{role: "mongostatRole", db: "admin"}]})

3. Scripting, mongodb_sts.sh

#! / bin/bashhost= "127.0.0.1" passwd= "password" rst=''case "$1" in conn) rst= `mongostat-n 1-u dbbak-p $passwd-- authenticationDatabase=admin | awk 'NR==2 {print $(NF-1)}' `;; dirty) rst= `mongostat-n 1-u dbbak-p $passwd-- authenticationDatabase=admin | awk-F [\] + 'NR==2 {print $8}'` Used) rst= `mongostat-n 1-u dbbak-p $passwd-- authenticationDatabase=admin | awk-F [\] + 'NR==2 {print $9}' `;; qr) rst= `mongostat-n 1-u dbbak-p $passwd-- authenticationDatabase=admin | awk-F [\\ |] + 'NR==2 {print $(NF-7)}'` Qw) rst= `mongostat-n 1-u dbbak-p $passwd-- authenticationDatabase=admin | awk-F [\ |] + 'NR==2 {print $(NF-6)}' `;; res) res=$ (echo "db.serverStatus (). Mem" | mongo-u dbbak-p $passwd admin | awk-F [,\]'/ "resident" / {print $3}') rst=$ [res*1024*1024] Vsize) resize=$ (echo "db.serverStatus (). Mem" | mongo-u dbbak-p $passwd admin | awk-F [,\]'/ "virtual" / {print $3}') rst=$ [resize*1024*1024];; *) echo "aaaaaaaaaaaa" # exit 5esacif [- z $rst]; then echo 0else echo $rstfi

4. Script applications: cacti, zabbix, etc.

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

Database

Wechat

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

12
Report