Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb monitoring script

Shulou Source: shulou.com Published: 2022-06-01 17:00:36 10月21日 Update

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.

Tags: Monitoring users roles scripts permissions locations information commands actual tools methods steps status system application adjustment output verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Shulou Tech Info NVidia vpn