Skip to content

Instantly share code, notes, and snippets.

@artifactsauce
Last active October 30, 2016 11:57
Show Gist options
  • Save artifactsauce/23bb8390e9e1d552bfe77d541be86a38 to your computer and use it in GitHub Desktop.
Save artifactsauce/23bb8390e9e1d552bfe77d541be86a38 to your computer and use it in GitHub Desktop.
BitBarでMySQLサーバーの状態を常に意識する ref: http://qiita.com/artifactsauce/items/d111bb1e6676f235094d
Start | bash=/usr/local/bin/mysql.server param1=start refresh=true terminal=false
$ /usr/local/bin/mysqladmin -u root status
Uptime: 5 Threads: 1 Questions: 4 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.800
$ /usr/local/bin/mysqladmin -u root status | sed -e "s/ /\n/g"
Uptime: 518nThreads: 1nQuestions: 22nSlow queries: 0nOpens: 67nFlush tables: 1nOpen tables: 60nQueries per second avg: 0.042
$ export LF=$'\\\x0A'; /usr/local/bin/mysqladmin -u root status | sed -e "s/ /$LF/g"
Uptime: 858
Threads: 1
Questions: 46
Slow queries: 0
Opens: 67
Flush tables: 1
Open tables: 60
Queries per second avg: 0.053
Uptime: 858 | color=red
$ export LF=$'\\\x0A'; /usr/local/bin/mysqladmin -u root status | sed -e "s/ / \| color=green $LF/g"
Uptime: 6015 | color=green
Threads: 1 | color=green
Questions: 66 | color=green
Slow queries: 0 | color=green
Opens: 67 | color=green
Flush tables: 1 | color=green
Open tables: 60 | color=green
Queries per second avg: 0.010
$ export LF=$'\\\x0A'; /usr/local/bin/mysqladmin -u root status | sed -e "s/$/ /" | sed -e "s/ / \| color=green $LF/g"
Uptime: 6323 | color=green
Threads: 1 | color=green
Questions: 78 | color=green
Slow queries: 0 | color=green
Opens: 67 | color=green
Flush tables: 1 | color=green
Open tables: 60 | color=green
Queries per second avg: 0.012 | color=green
#!/usr/bin/env bash
# <bitbar.title>MySQL server status</bitbar.title>
# <bitbar.version>v1.1</bitbar.version>
# <bitbar.author>Kenji Akiyama</bitbar.author>
# <bitbar.author.github>artifactsauce</bitbar.author.github>
# <bitbar.desc>Show the status of MySQL server installed by Homebrew on localhost and manage server boot with shortcut menus</bitbar.desc>
# <bitbar.image>http://i.imgur.com/Y85ENFb.png</bitbar.image>
# <bitbar.dependencies>bash,mysql</bitbar.dependencies>
set -eu
# Change here depending on your preference
MENUBAR_ICON_ENABLED=":dolphin:"
MENUBAR_ICON_DISABLED=":sleepy:"
STATUS_ITEM_COLOR="green"
DISABLED_ITEM_COLOR="#C0C0C0"
# Below is no need to change basically.
SERVER_CMD="/usr/local/bin/mysql.server"
SUBCMD_START="start"
SUBCMD_STOP="stop"
SUBCMD_RESTART="restart"
SUBCMD_RELOAD="reload"
SUBCMD_F_RELOAD="force-reload"
SUBCMD_STATUS="status"
if $SERVER_CMD $SUBCMD_STATUS | grep -Fq 'SUCCESS'; then
IS_SERVER_RUNNING=true
echo "$MENUBAR_ICON_ENABLED"
else
IS_SERVER_RUNNING=false
echo "$MENUBAR_ICON_DISABLED"
fi
# Server Status from `mysqladmin status`
if $IS_SERVER_RUNNING; then
echo "---"
LF=$'\\\x0A' # return code
/usr/local/bin/mysqladmin -u root status | sed -e "s/$/ /" | sed -e "s/ / \| color=$STATUS_ITEM_COLOR $LF/g"
fi
# Server management shortcuts
echo "---"
if $IS_SERVER_RUNNING; then
echo "Start | color=$DISABLED_ITEM_COLOR"
echo "Stop | bash=$SERVER_CMD param1=$SUBCMD_STOP refresh=true terminal=false"
echo "Restart | bash=$SERVER_CMD param1=$SUBCMD_RESTART refresh=true terminal=false"
echo "Reload | bash=$SERVER_CMD param1=$SUBCMD_RELOAD refresh=true terminal=false"
echo "Force-reload | bash=$SERVER_CMD param1=$SUBCMD_F_RELOAD refresh=true terminal=false"
else
echo "Start | bash=$SERVER_CMD param1=$SUBCMD_START refresh=true terminal=false"
echo "Stop | color=$DISABLED_ITEM_COLOR"
echo "Restart | color=$DISABLED_ITEM_COLOR"
echo "Reload | color=$DISABLED_ITEM_COLOR"
echo "Force-reload | color=$DISABLED_ITEM_COLOR"
fi
echo "---"
echo "Refresh | refresh=true color=$DISABLED_ITEM_COLOR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment