mdiag script for gathering MongoDB’s system & h/w diagnostic info.

mdiag is a shell script which will gather a wide variety of system and hardware diagnostic information of the MongoDB server.
Please see below for how it works.
 
mdiag shell script: 

[Lab root @ hostname /tmp]# cat mdiag.sh 
#!/bin/sh
# ===================================
# mdiag.sh: MongoDB Diagnostic Report
# ===================================
#
# Copyright MongoDB, Inc, 2014
#
# Gather a wide variety of system and hardware diagnostic information.
#
# LICENSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
version="1.6.0"
diagfile="/tmp/mdiag-`hostname`.txt"
msection() {
 section="$1"
 shift
 echo -n "Gathering $section info... "
 (
 echo ""
 echo ""
 echo "=========== start section $section ==========="
 if [ $# -eq 0 ]; then
 eval "`cat`"
 else
 "$@"
 fi
 echo "============ end section $section ============"
 ) >> "$diagfile" 2>&1
 echo "done"
}
msubsection() {
 subsection="$1"
 shift
 echo "--> start subsection $subsection <--"
 if [ $# -eq 0 ]; then
 eval "`cat`"
 else
 "$@"
 fi
 echo "--> end subsection $subsection <--"
}
printeach() {
 for i; do
 echo "$i"
 done
}
getfiles() {
 for f; do
 echo ""
 ls -l "$f"
 msubsection "$f" cat "$f"
 done
}
getstdinfiles() {
 while read i; do
 getfiles "$i"
 done
}
getfilesfromcommand() {
 "$@" | getstdinfiles
}
lsfiles() {
 somefiles=
 restfiles=
 for f; do
 if [ "x$restfiles" = "x" ]; then
 case "$f" in
 --) restfiles=y ;;
 -*) ;;
 *)
 somefiles=y
 break
 ;;
 esac
 else
 somefiles=y
 break
 fi
 done
 if [ "x$somefiles" != "x" ]; then
 ls -la "$@"
 fi
}
PATH="$PATH${PATH+:}/usr/sbin:/sbin:/usr/bin:/bin"
echo "========================="
echo "MongoDB Diagnostic Report"
echo "mdiag.sh version $version"
echo "========================="
if [ "$1" ]; then
 echo
 echo "Ticket: https://jira.mongodb.org/browse/$1"
fi
echo 
echo "Please wait while diagnostic information is gathered"
echo "into the $diagfile file..."
echo
echo "If the display remains stuck for more than 5 minutes,"
echo "please press Control-C."
echo
[ -e "$diagfile" ] && mv -f "$diagfile" "$diagfile.old"
(
echo "========================="
echo "MongoDB Diagnostic Report"
echo "mdiag.sh version $version"
echo "========================="
) > "$diagfile" 2>&1
shopt -s nullglob >> "$diagfile" 2>&1
# Generic/system/distro/boot info
msection args printeach "$@"
msection date date
msection whoami whoami
msection path echo "$PATH"
msection ld_library_path echo "$LD_LIBRARY_PATH"
msection ld_preload echo "$LD_PRELOAD"
msection pythonpath echo "$PYTHONPATH"
msection pythonhome echo "$PYTHONHOME"
msection distro getfiles /etc/*release /etc/*version
msection uname uname -a
msection glibc lsfiles /lib*/libc.so* /lib/*/libc.so*
msection glibc2 /lib*/libc.so* '||' /lib/*/libc.so*
msection ld.so.conf getfiles /etc/ld.so.conf /etc/ld.so.conf.d/*
msection lsb lsb_release -a
msection rc.local getfiles /etc/rc.local
msection sysctl sysctl -a
msection sysctl.conf getfiles /etc/sysctl.conf /etc/sysctl.d/*
msection ulimit ulimit -a
msection limits.conf getfiles /etc/security/limits.conf /etc/security/limits.d/*
msection selinux sestatus
msection timezone_config getfiles /etc/timezone /etc/sysconfig/clock
msection timedatectl timedatectl
msection localtime lsfiles /etc/localtime
msection localtime_matches find /usr/share/zoneinfo -type f -exec cmp -s \{\} /etc/localtime \; -print
# Block device/filesystem info
msection blockdev blockdev --report
msection lsblk lsblk
msection fstab getfiles /etc/fstab
msection mount mount
msection df-h df -h
msection df-k df -k
msection mdstat getfiles /proc/mdstat
msection mdadm_detail_scan mdadm --detail --scan
msection mdadm_detail <<EOF
sed -ne 's,^\(md[0-9]\+\) : .*$,/dev/\1,p' < /proc/mdstat | xargs -n1 --no-run-if-empty mdstat --detail
EOF
msection dmsetup dmsetup ls
msection device_mapper lsfiles -R /dev/mapper /dev/dm-*
msection lvm_pvs pvs -v
msection lvm_vgs vgs -v
msection lvm_lvs lvs -v
msection nr_requests getfilesfromcommand find /sys -name nr_requests
msection read_ahead_kb getfilesfromcommand find /sys -name read_ahead_kb
msection scheduler getfilesfromcommand find /sys -name scheduler
# Network info
msection ifconfig ifconfig -a
msection route route -n
msection iptables iptables -L -v -n
msection iptables_nat iptables -t nat -L -v -n
msection ip_link ip link
msection ip_addr ip addr
msection ip_route ip route
msection ip_rule ip rule
msection hosts getfiles /etc/hosts
msection host.conf getfiles /etc/host.conf
msection resolv getfiles /etc/resolv.conf
msection nsswitch getfiles /etc/nsswitch.conf
msection networks getfiles /etc/networks
msection rpcinfo rpcinfo -p
msection netstat netstat -anpoe
# Hardware info
msection dmesg dmesg
msection lspci lspci -vvv
msection dmidecode dmidecode --type memory
msection sensors sensors
msection mcelog getfiles /var/log/mcelog
# Process/kernel info
msection procinfo getfiles /proc/mounts /proc/self/mountinfo /proc/cpuinfo /proc/meminfo /proc/zoneinfo /proc/swaps /proc/modules /proc/vmstat /proc/loadavg
msection transparent_hugepage getfilesfromcommand find /sys/kernel/mm/{redhat_,}transparent_hugepage -type f
msection ps ps -eLFww
# Dynamic/monitoring info
msection top <<EOF
COLUMNS=512
export COLUMNS
top -b -d 1 -n 30 -c | sed -e 's/ *$//g'
EOF
msection top_threads <<EOF
COLUMNS=512
export COLUMNS
top -b -d 1 -n 30 -c -H | sed -e 's/ *$//g'
EOF
msection iostat iostat -xtm 1 120
# Mongo process info
mongo_pids="`pgrep mongo`"
msection mongo_summary ps -Fww -p $mongo_pids
for pid in $mongo_pids; do
 msection proc/$pid <<-EOF
 lsfiles /proc/$pid/cmdline
 msubsection cmdline xargs -n1 -0 < /proc/$pid/cmdline
 xargs -n1 -0 < /proc/$pid/cmdline | awk '\$0 == "-f" || \$0 == "--config" { getline; print; }' | getstdinfiles
 getfiles /proc/$pid/limits /proc/$pid/mounts /proc/$pid/mountinfo /proc/$pid/smaps /proc/$pid/numa_maps
 lsfiles /proc/$pid/fd 
 getfiles /proc/$pid/fdinfo/*
 EOF
done
msection global_mongodb_conf getfiles /etc/mongodb.conf /etc/mongod.conf
msection global_mms_conf getfiles /etc/mongodb-mms/*
# Hardware info with a risk of hanging
msection smartctl <<EOF
smartctl --scan | sed -e "s/#.*$//" | while read i; do smartctl --all \$i; done
EOF
msection scsidevices getfiles /sys/bus/scsi/devices/*/model
cat <<EOF
==============================================================
MongoDB Diagnostic information has been recorded in: $diagfile
Please attach the contents of $diagfile to the Jira ticket${1+ at:
 https://jira.mongodb.org/browse/$1}
==============================================================
EOF
[Lab root @ hostname /tmp]

mdiag script execution: 
 
[Lab root @ hostname /tmp]# sh mdiag.sh
=========================
MongoDB Diagnostic Report
mdiag.sh version 1.6.0
=========================
Please wait while diagnostic information is gathered
into the /tmp/mdiag-hostname.txt file...
If the display remains stuck for more than 5 minutes,
please press Control-C.
Gathering args info... done
Gathering date info... done
Gathering whoami info... done
Gathering path info... done
Gathering ld_library_path info... done
Gathering ld_preload info... done
Gathering pythonpath info... done
Gathering pythonhome info... done
Gathering distro info... done
Gathering uname info... done
Gathering glibc info... done
Gathering glibc2 info... done
Gathering ld.so.conf info... done
Gathering lsb info... done
Gathering rc.local info... done
Gathering sysctl info... done
Gathering sysctl.conf info... done
Gathering ulimit info... done
Gathering limits.conf info... done
Gathering selinux info... done
Gathering timezone_config info... done
Gathering timedatectl info... done
Gathering localtime info... done
Gathering localtime_matches info... done
Gathering blockdev info... done
Gathering lsblk info... done
Gathering fstab info... done
Gathering mount info... done
Gathering df-h info... done
Gathering df-k info... done
Gathering mdstat info... done
Gathering mdadm_detail_scan info... done
Gathering mdadm_detail info... done
Gathering dmsetup info... done
Gathering device_mapper info... done
Gathering lvm_pvs info... done
Gathering lvm_vgs info... done
Gathering lvm_lvs info... done
Gathering nr_requests info... done
Gathering read_ahead_kb info... done
Gathering scheduler info... done
Gathering ifconfig info... done
Gathering route info... done
Gathering iptables info... done
Gathering iptables_nat info... done
Gathering ip_link info... done
Gathering ip_addr info... done
Gathering ip_route info... done
Gathering ip_rule info... done
Gathering hosts info... done
Gathering host.conf info... done
Gathering resolv info... done
Gathering nsswitch info... done
Gathering networks info... done
Gathering rpcinfo info... done
Gathering netstat info... done
Gathering dmesg info... done
Gathering lspci info... done
Gathering dmidecode info... done
Gathering sensors info... done
Gathering mcelog info... done
Gathering procinfo info... done
Gathering transparent_hugepage info... done
Gathering ps info... done
Gathering top info... done
Gathering top_threads info... done
Gathering iostat info... done
Gathering mongo_summary info... done
Gathering proc/18984 info... done
Gathering proc/18987 info... done
Gathering proc/18989 info... done
Gathering proc/18991 info... done
Gathering proc/18994 info... done
Gathering proc/18995 info... done
Gathering proc/18997 info... done
Gathering proc/19000 info... done
Gathering proc/19311 info... done
Gathering proc/24096 info... done
Gathering global_mongodb_conf info... done
Gathering global_mms_conf info... done
Gathering smartctl info... done
Gathering scsidevices info... done
==============================================================
MongoDB Diagnostic information has been recorded in: /tmp/mdiag-hostname.txt
Please attach the contents of /tmp/mdiag-hostname.txt to the Jira ticket
==============================================================
[Lab root @ hostname /tmp]

mdiag shell script o/p in short: 
 
[Lab root @ hostname ~]# wc -l /tmp/mdiag-hostname.txt
82199 /tmp/mdiag-hostname.txt
[Lab root @ hostname ~]# ll -lhtr /tmp/mdiag-hostname.txt
-rw-r--r-- 1 root root 7.2M Oct 22 01:14 /tmp/mdiag-hostname.txt
[Lab root @ hostname ~]
[Lab root @ hostname ~]# head -100 /tmp/mdiag-hostname.txt 
=========================
MongoDB Diagnostic Report
mdiag.sh version 1.6.0
=========================
=========== start section args ===========
============ end section args ============
=========== start section date ===========
Wed Oct 22 01:11:22 EDT 2014
============ end section date ============
=========== start section whoami ===========
root
============ end section whoami ============
=========== start section path ===========
/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/datapalette/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/sbin:/sbin:/usr/bin:/bin
============ end section path ============
=========== start section ld_library_path ===========
============ end section ld_library_path ============
=========== start section ld_preload ===========
============ end section ld_preload ============
=========== start section pythonpath ===========
============ end section pythonpath ============
=========== start section pythonhome ===========
============ end section pythonhome ============
=========== start section distro ===========
-rw-r--r-- 1 root root 55 Oct 30 2013 /etc/redhat-release
--> start subsection /etc/redhat-release <--
Red Hat Enterprise Linux Server release 6.5 (Santiago)
--> end subsection /etc/redhat-release <--
-rw-r--r-- 1 root root 38 Feb 11 2014 /etc/SOErelease
--> start subsection /etc/SOErelease <--
6.5.GSF-A0 SOE Linux Release 02/11/14
--> end subsection /etc/SOErelease <--
lrwxrwxrwx 1 root root 14 Aug 27 15:48 /etc/system-release -> redhat-release
--> start subsection /etc/system-release <--
Red Hat Enterprise Linux Server release 6.5 (Santiago)
--> end subsection /etc/system-release <--
============ end section distro ============
=========== start section uname ===========
Linux hostname 2.6.32-431.17.1.el6.x86_64 #1 SMP Fri Apr 11 17:27:00 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
============ end section uname ============
=========== start section glibc ===========
lrwxrwxrwx 1 root root 12 Aug 27 15:47 /lib64/libc.so.6 -> libc-2.12.so
lrwxrwxrwx 1 root root 12 Aug 27 15:48 /lib/libc.so.6 -> libc-2.12.so
============ end section glibc ============
=========== start section glibc2 ===========
GNU C Library stable release version 2.12, by Roland McGrath et al.
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.7 20120313 (Red Hat 4.4.7-4).
Compiled on a Linux 2.6.32 system on 2013-11-05.
Available extensions:
 The C stubs add-on version 2.1.2.
 crypt add-on version 2.1 by Michael Glad and others
 GNU Libidn by Simon Josefsson
 Native POSIX Threads Library by Ulrich Drepper et al
 BIND-8.2.3-T5B
 RT using linux kernel aio
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
============ end section glibc2 ============
=========== start section ld.so.conf ===========
-rw-r--r-- 1 root root 28 Jul 24 2013 /etc/ld.so.conf
--> start subsection /etc/ld.so.conf <--
[Lab root @ hostname ~]
#
[Lab root @ hostname ~]# 
[Lab root @ hostname ~]# tail -10 /tmp/mdiag-hostname.txt 
-r--r--r-- 1 root root 4096 Oct 22 01:14 /sys/bus/scsi/devices/3:0:2:4/model
--> start subsection /sys/bus/scsi/devices/3:0:2:4/model <--
2145 
--> end subsection /sys/bus/scsi/devices/3:0:2:4/model <--
-r--r--r-- 1 root root 4096 Oct 22 01:14 /sys/bus/scsi/devices/3:0:2:5/model
--> start subsection /sys/bus/scsi/devices/3:0:2:5/model <--
2145 
--> end subsection /sys/bus/scsi/devices/3:0:2:5/model <--
============ end section scsidevices ============
[Lab root @ hostname ~]

Source script : https://github.com/mongodb/support-tools/raw/master/mdiag/mdiag.sh

  • Ask Question