Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update script #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions gluster-server/gluster-server.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#!/bin/bash
#!/usr/bin/env bash

#Gluster server status

METRIC=$1
SUDO="/usr/bin/sudo"
PIDOF="/bin/pidof"
GLUSTER="/usr/sbin/gluster"
METRIC="${1}"
SUDO="$(which sudo)"
PIDOF="$(which pidof)"
GLUSTER_CMD="$(which gluster)"
GLUSTER_LOG_LEVEL="--log-level=WARNING"

if [[ -z "$1" ]]; then
GLUSTER=("${GLUSTER_CMD}" "${GLUSTER_LOG_LEVEL}")

if [[ -z "${1}" ]]; then
echo "Please choose metric"
exit 1
fi

case $METRIC in
case ${METRIC} in
'glusterd')
if ! $PIDOF glusterd &>/dev/null; then
if ! ${PIDOF} glusterd &>/dev/null; then
echo 0
exit 1
else
echo 1
fi
;;
'glusterfsd')
if ! $PIDOF glusterfsd &>/dev/null; then
if ! ${PIDOF} glusterfsd &>/dev/null; then
echo 0
exit 1
else
Expand All @@ -31,66 +34,64 @@ case $METRIC in
;;
'discover-peers')
echo -n '{"data":['
peers=$($SUDO $GLUSTER peer status | grep '^Hostname: ' | awk '{print $2}')
for peer in $peers; do
echo -n "{\"{#PEER}\": \"$peer\"},"
peers=$(${SUDO} "${GLUSTER[@]}" peer status | grep --only-matching --perl-regexp '^Hostname:\s+\K.*')
for peer in ${peers}; do
echo -n "{\"{#PEER}\": \"${peer}\"},"
done | sed -e 's:,$::'
echo -n ']}'
;;
'check-peer-state')
peer="$2"
test -z "$peer" && echo 'Peer not specified' && exit 1
state=$($SUDO $GLUSTER peer status | \
grep -A2 $peer | \
grep '^State: ' | \
test -z "${peer}" && echo 'Peer not specified' && exit 1
state=$(${SUDO} "${GLUSTER[@]}" peer status | \
grep --after-context 2 "${peer}" | \
grep '^State: ' | \
sed -nre 's/State: ([[:graph:]])/\1/p')
test -z "$state" && echo 'Peer not found' && exit 1
echo $state
echo "$state"
;;
'discover-volumes')
echo -n '{"data":['
volumes=$($SUDO $GLUSTER volume list)
for volume in $volumes; do
bricks=$($SUDO $GLUSTER volume heal $volume info | \
grep 'Brick' | \
awk '{print $2}')
for brick in $bricks; do
echo -n "{\"{#VOLUME}\": \"$volume\", \"{#BRICK}\": \"$brick\"},"
volumes=$(${SUDO} "${GLUSTER[@]}" volume list)
for volume in ${volumes}; do
bricks=$(${SUDO} "${GLUSTER[@]}" volume info "${volume}" | \
grep --only-matching --perl-regexp '^Brick[0-9]+:\s\K.*')
for brick in ${bricks}; do
echo -n "{\"{#VOLUME}\": \"${volume}\", \"{#BRICK}\": \"${brick}\"},"
done
done | sed -e 's:,$::'
echo -n ']}'
;;
'volume-heal-info')
volume=$2
brick=$3
test -z "$volume" && echo 'Volume not specified' && exit 1
test -z "$brick" && echo 'Brick not specified' && exit 1
entries=$($SUDO $GLUSTER volume heal $volume info | \
grep -A3 $brick | \
test -z "${volume}" && echo 'Volume not specified' && exit 1
test -z "${brick}" && echo 'Brick not specified' && exit 1
entries=$(${SUDO} "${GLUSTER[@]}" volume heal "${volume}" info | \
grep --after-context 3 "${brick}" | \
grep '^Number of entries: ' | \
sed -nre 's/Number of entries: ([[:graph:]])/\1/p')
test -z "$entries" && echo 'Brick not found' && exit 1
echo $entries
test -z "${entries}" && echo 'Brick not found' && exit 1
echo "${entries}"
;;
'volume-heal-info-splitbrain')
volume=$2
brick=$3
test -z "$volume" && echo 'Volume not specified' && exit 1
test -z "$brick" && echo 'Brick not specified' && exit 1
entries=$($SUDO $GLUSTER volume heal $volume info split-brain | \
grep -A3 $brick | \
test -z "${volume}" && echo 'Volume not specified' && exit 1
test -z "${brick}" && echo 'Brick not specified' && exit 1
entries=$(${SUDO} "${GLUSTER[@]}" volume heal "${volume}" info split-brain | \
grep -A3 "${brick}" | \
grep '^Number of entries in split-brain: ' | \
sed -nre 's/Number of entries in split-brain: ([[:graph:]])/\1/p')
test -z "$entries" && echo 'Brick not found' && exit 1
echo $entries
test -z "${entries}" && echo 'Brick not found' && exit 1
echo "${entries}"
;;
'volume-status-offline')
volume=$2
test -z "$volume" && echo 'Volume not specified' && exit 1
offline=$($SUDO $GLUSTER volume status $volume | \
grep -e ".*\sN\s.*" | \
wc -l)
echo $offline
test -z "${volume}" && echo 'Volume not specified' && exit 1
offline=$(${SUDO} "${GLUSTER[@]}" volume status "${volume}" | \
grep --count --extended-regexp ".*\sN\s.*")
echo "${offline}"
;;
*)
echo "Metric not selected"
Expand Down