Created
July 27, 2017 16:51
-
-
Save magoon/67b3c918ffc124a8e1bfb849fa0b8bef to your computer and use it in GitHub Desktop.
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/sh | |
# <bitbar.title>Amazon SQS Message listing</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>Andy Magoon</bitbar.author> | |
# <bitbar.author.github>magoon</bitbar.author.github> | |
# <bitbar.desc>Shows queue statistics from Amazon SQS.</bitbar.desc> | |
# <bitbar.dependencies>awscli,jq</bitbar.dependencies> | |
# Dependencies: | |
# awscli (https://aws.amazon.com/cli/) | |
# jq (https://stedolan.github.io/jq/) | |
# | |
# Notes: | |
# | |
# 1) brew install bitbar | |
# | |
# 2) place this file in ~/.bitbar/ | |
# | |
# 3) install the aws-cli (maybe brew install aws-cli) | |
# | |
# 4) Make sure you have a profile named the same as the below in your AWS creds file | |
# vi ~/.aws/credentials | |
# It should be in this format: | |
# [hearst-autos] | |
# aws_access_key_id = AKIAJPQ[redacted] | |
# aws_secret_access_key = Ng[redacted] | |
# region=us-east-1 | |
AWS_ACCOUNT_NUMBER=174076200000 | |
AWS_CLI_PROFILE="my-profile-name" | |
SQS_NAMES="Exporter-prod,\ | |
Publishing-prod" | |
if [[ "$PATH" != *"/usr/local/bin/"* ]]; then | |
export PATH="$PATH:/usr/local/bin" | |
fi | |
if [ -z "$SQS_NAMES" ]; then | |
echo "Empty queue list" | |
exit 1 | |
fi | |
function mono() { | |
echo "$1 | font=Monaco trim=false" | |
} | |
function process() { | |
local IFS=, | |
local NAMES=($1) | |
for name in "${NAMES[@]}"; do | |
aws --profile=$AWS_CLI_PROFILE sqs get-queue-attributes --queue-url=https://sqs.us-east-1.amazonaws.com/$AWS_ACCOUNT_NUMBER/$name --attribute-names ApproximateNumberOfMessages | echo $name `jq .Attributes.ApproximateNumberOfMessages` | |
if [ $(($RANDOM % 2)) -eq 1 ]; then sleep 3; fi | |
done | |
} | |
process ${SQS_NAMES} | |
# Sometimes wait a little bit longer just so we're not pegging the service | |
if [ $(($RANDOM % 2)) -eq 1 ]; then sleep 30; fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment