Created
January 7, 2019 07:10
-
-
Save namnv609/28814c3736187a36c003b02e855afa96 to your computer and use it in GitHub Desktop.
Processess check and alarm
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
#!/usr/bin/env bash | |
sidekiqProcessNumber=$(ps ax | grep -i [s]idekiq | wc -l) | |
pumaProcessNumber=$(ps ax | grep -i [p]uma | wc -l) | |
function pushWarningMessage() | |
{ | |
serverIP=$(hostname -i) | |
jpTime=$(TZ=":Asia/Tokyo" date +"%Y/%m/%d %H:%M:%S") | |
vnTime=$(TZ=":Asia/Ho_Chi_Minh" date +"%Y/%m/%d %H:%M:%S") | |
pushMessage=$(cat <<-MSG | |
[info][title]Process Monitor[/title] | |
- Server: $serverIP | |
- Time (JST): $jpTime | |
- Time (VNT): $vnTime | |
- Message: Process [$1] not found[/info] | |
MSG | |
) | |
result=$(curl -s -X POST -H "X-ChatWorkToken: <ChatWork API Key>" -d "body=$pushMessage&self_unread=0" "https://api.chatwork.com/v2/rooms/<Room ID>/messages") | |
echo "$result" | |
processMonitoLog=$(cat <<-MSG | |
Time: $vnTime | |
$result | |
------------------------ | |
MSG | |
) | |
echo "$processMonitoLog" > /path/to/log/file.log | |
} | |
if [[ "$sidekiqProcessNumber" -eq "0" ]]; then | |
pushWarningMessage "Sidekiq" | |
fi | |
if [[ "$pumaProcessNumber" -eq "0" ]]; then | |
pushWarningMessage "Puma" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment