Created
November 6, 2020 21:47
-
-
Save icelander/107fbd643e41f16d29cf23ab9e08058b to your computer and use it in GitHub Desktop.
Gets diagnostic information for Mattermost application servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
timestamp_string=`date -Iseconds` | |
parent_dir=`pwd` | |
dirname="$HOSTNAME-$timestamp_string" | |
dirpath="$parent_dir/$dirname" | |
tarname="$dirname.tgz" | |
tarpath="$parent_dir/$tarname" | |
if [[ $1 == "--help" || $1 == "-h" ]]; then | |
cat <<EOF | |
ABOUT | |
This script collects diagnostic data from a Mattermost server in a tgz | |
file at: | |
$dirpath.tgz | |
The following information is collected. | |
- Current mattermost.log | |
- Journalctl for the mattermost user | |
- CPU, RAM, process, and packages installed on the server | |
- A 30 second CPU profile | |
- A heap memory profile | |
- The ldd output for the Mattermost binary | |
- (Optional) The journalctl output when quitting or killing the Mattermost | |
process | |
USAGE | |
./get_info.sh [--quit, -q], [--kill, -k] | |
PARAMETERS | |
--help, -h Print this help message and exit | |
--quit, -q SIGQUIT the Mattermost process and capture journalctl output. | |
NOTE: Must be the only parameter. | |
--kill, -k SIGKILL the Mattermost process and capture journalctl output. | |
NOTE: Must be the only parameter. | |
INSTRUCTIONS | |
Copy this script to the Mattermost server you want to capture diagnostics from | |
to the directory where you want the archive to be, then run the script as | |
described in USAGE. If you want to record the output, run it like this: | |
./get_info.sh [PARAMETERS] | tee get_info.log | |
Once the script has run it will create a .tgz file in the same directory with | |
the diagnostic output to send to Mattermost support. | |
EOF | |
exit 0 | |
fi | |
if [[ $USER != "root" ]]; then | |
echo "This script must be run as root!" | |
exit 1 | |
fi | |
echo "--- Creating $dirpath ---" | |
mkdir -p $dirpath | |
if [[ ! -d "$dirpath" ]]; then | |
echo "ERROR could not create $dirpath" | |
exit 1 | |
fi | |
cd $dirpath | |
echo "Changing to `pwd`" | |
echo "... done" | |
echo "" | |
echo "--- Getting current mattermost.log ---" | |
cp /opt/mattermost/logs/mattermost.log ./ | |
echo "... done" | |
echo "" | |
echo "--- Getting Mattermost journalctl log ---" | |
journalctl -u mattermost -n 4000 --no-pager > journalctl.log | |
echo "... done" | |
echo "" | |
echo "--- Getting Server Information --- " | |
fname=`hostname`.server_info.txt | |
echo "" > $fname | |
echo "======= CPU INFO =======" >> $fname | |
echo "" >> $fname | |
cat /proc/cpuinfo >> $fname | |
echo "" >> $fname | |
echo "===== MEMORY INFO =====" >> $fname | |
echo "" >> $fname | |
free -m >> $fname | |
echo "" >> $fname | |
echo "===== RPM Packages =====" >> $fname | |
echo "" >> $fname | |
rpm -qa >> $fname | |
echo "" >> $fname | |
echo "===== Running Processes =====" >> $fname | |
echo "" >> $fname | |
ps auxfwww >> $fname | |
echo "" >> $fname | |
echo "===== Yum Packages =====" >> $fname | |
echo "" >> $fname | |
# TODO Detect package manager and switch accordingly | |
yum list installed >> $fname | |
echo "... done" | |
echo "" | |
# TODO Detect if 8067 is listening | |
echo "--- Getting 30 second CPU Profile ---" | |
curl http://localhost:8067/debug/pprof/profile?seconds=30 -o "`hostname`.30s.cpuprof" | |
echo "... done" | |
echo "" | |
echo "--- Getting Heap Profile ---" | |
curl http://localhost:8067/debug/pprof/heap -o "`hostname`.heapprof" | |
echo "... done" | |
echo "" | |
# TODO Detect the binary location | |
echo "--- Getting ldd for mattermost binary ---" | |
ldd /opt/mattermost/bin/mattermost > `hostname`.ldd | |
echo "... done" | |
echo "" | |
if [[ ($1 == "--quit" || $1 == "-q") && $# == 1 ]]; then | |
echo "--- Sending SIQUIT Signal to Mattermost ---" | |
kill -SIGQUIT $(pgrep mattermost) | |
echo "--- Collecting Journalctl ---" | |
journalctl -u mattermost -n 4000 --no-pager > "`hostname`.siqquit.log" | |
echo "... done" | |
fi | |
if [[ ($1 == "--kill" || $1 == "-k") && $# == 1 ]]; then | |
echo "--- Sending SIQUIT Signal to Mattermost ---" | |
echo "THIS WILL STOP MATTERMOST ON THIS SERVER" | |
kill -SIGKILL $(pgrep mattermost) | |
echo "--- Collecting Journalctl" | |
journalctl -u mattermost -n 4000 --no-pager > "`hostname`.sigkill.log" | |
echo "... done" | |
echo "" | |
fi | |
cd $parent_dir | |
echo "--- Creating $tarname ---" | |
tar -C $parent_dir -czf $tarpath $dirname | |
echo "... done" | |
echo "" | |
cat <<EOF | |
--- DIAGNOSTICS COMPLETE! --- | |
Diagnostic archive available at: | |
$tarpath | |
Thank you for using Mattermost! | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment