Created
March 29, 2025 22:32
-
-
Save jfinstrom/d8cc7a00bc7aa2b6e658de1f7bdb5b8c to your computer and use it in GitHub Desktop.
Collects system metrics and creates markdown tables.
This file contains hidden or 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 | |
# pip-boy.sh - Collects system metrics and creates markdown tables. | |
# Copyright (C) 2025 James Finstrom | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU Affero General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU Affero General Public License for more details. | |
# | |
# You should have received a copy of the GNU Affero General Public License | |
# along with this program. If not, see <https://www.gnu.org/licenses/>. | |
echo "This may take a moment, patience is a virtue" >&2 | |
# Section: Directory Sizes | |
echo -n "Collecting directory sizes... " >&2 | |
var_size=$(du -sh /var/ 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
usr_size=$(du -sh /usr --exclude=/usr/local 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
usr_local_size=$(du -sh /usr/local 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
boot_size=$(du -sh /boot 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
home_size=$(du -sh /home 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
root_size=$(du -sh / 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
echo "" >&2 | |
# Section: Asterisk Storage | |
echo -n "Collecting Asterisk storage sizes... " >&2 | |
monitor_size=$(du -sh /var/spool/asterisk/monitor/ 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
voicemail_size=$(du -sh /var/spool/asterisk/voicemail/default/ 2> /dev/null | awk '{print $1}') | |
echo -n "." >&2 | |
echo "" >&2 | |
# Section: Counts | |
echo -n "Collecting counts... " >&2 | |
mailbox_count=$(find /var/spool/asterisk/voicemail/default/ -maxdepth 1 -type d -not -path '/var/spool/asterisk/voicemail/default/' 2> /dev/null | wc -l) | |
echo -n "." >&2 | |
recording_count=$(find /var/spool/asterisk/monitor/ -type f 2> /dev/null | wc -l) | |
echo -n "." >&2 | |
user_count=$(php -r 'include "/etc/freepbx.conf"; echo count(FreePBX::Core()->getAllUsers());' 2> /dev/null) | |
echo -n "." >&2 | |
device_count=$(php -r 'include "/etc/freepbx.conf"; echo count(FreePBX::Core()->getAllValidDevices());' 2> /dev/null) | |
echo -n "." >&2 | |
oss_modules=$(fwconsole ma list 2> /dev/null | grep -v Commercial | grep -v '+---' | grep -v Signature | wc -l) | |
echo -n "." >&2 | |
commercial_modules=$(fwconsole ma list 2> /dev/null | grep Commercial | grep -v '+---' | grep -v Signature | wc -l) | |
echo -n "." >&2 | |
echo "" >&2 | |
# Section: Averages | |
echo -n "Calculating averages... " >&2 | |
average_size=$(find /var/spool/asterisk/monitor/ -mindepth 1 -type d -print0 2> /dev/null | xargs -0 du -sb 2> /dev/null | awk '{ sum+=$1; n++ } END { if (n>0) avg=sum/n; else avg=0; print avg }' | numfmt --to=iec --format='%f') | |
echo -n "." >&2 | |
average_length=$(find /var/spool/asterisk/monitor/ -type f -name "*.wav" -print0 2> /dev/null | xargs -0 soxi -D 2> /dev/null | awk '{ sum += $1; count++ } END { if (count > 0) avg = sum / count; else avg = 0; minutes = int(avg / 60); seconds = int(avg) % 60; printf "%d:%02d\n", minutes, seconds }') | |
echo -n "." >&2 | |
echo "" >&2 | |
# Output in markdown format | |
echo "### Directory Sizes" | |
echo "" | |
echo "| Directory | Size |" | |
echo "|----------------------------|------------|" | |
echo "| /var/ | $var_size |" | |
echo "| /usr/ (excluding /usr/local) | $usr_size |" | |
echo "| /usr/local | $usr_local_size |" | |
echo "| /boot | $boot_size |" | |
echo "| /home | $home_size |" | |
echo "| / | $root_size |" | |
echo "" | |
echo "### Asterisk Storage" | |
echo "" | |
echo "| Item | Size |" | |
echo "|-----------------------------------|---------------|" | |
echo "| Call Recordings (/var/spool/asterisk/monitor/) | $monitor_size |" | |
echo "| Voicemail Storage (/var/spool/asterisk/voicemail/default/) | $voicemail_size |" | |
echo "" | |
echo "### Counts" | |
echo "" | |
echo "| Item | Count |" | |
echo "|-----------------------|------------|" | |
echo "| Mailboxes | $mailbox_count |" | |
echo "| Call Recordings | $recording_count |" | |
echo "| Users | $user_count |" | |
echo "| Devices | $device_count |" | |
echo "| Open Source Modules | $oss_modules |" | |
echo "| Commercial Modules | $commercial_modules |" | |
echo "" | |
echo "### Averages" | |
echo "" | |
echo "| Item | Value |" | |
echo "|-----------------------|------------|" | |
echo "| Average Recording Size| $average_size |" | |
echo "| Average Recording Length | $average_length |" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment