forked from instaclustr/instacollector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster_collector.sh
More file actions
executable file
·87 lines (70 loc) · 2.23 KB
/
cluster_collector.sh
File metadata and controls
executable file
·87 lines (70 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
help_function()
{
echo ""
echo "Usage: $0"
echo "Usage: $0 -u username -p password"
echo -e "\t-u Remote JMX agent username."
echo -e "\t-p Password."
exit 1 # Exit script after printing help
}
# Handles parameters
while getopts "u:p:" opt
do
case "$opt" in
u ) parameter_username="$OPTARG" ;;
p ) parameter_password="$OPTARG" ;;
? ) help_function ;; # Print help_function in case parameter is non-existent
esac
done
#GLOBAL VARIABLES
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
INFO_DIR=/tmp/InstaCollection_$(date +%Y%m%d%H%M)
#Collect user info.
read -p "Enter username for login on Cassandra cluster nodes (Press Enter for default admin) :" user
[ -z "${user}" ] && user='admin'
read -p "Enter Identity file path:" id_file
if [[ ! -f ${id_file} || ! -s ${id_file} ]]; then
echo "$id_file File not found!"
exit 1
fi
read -p "Enter file containing ip addresses/host names of Cassandra cluster nodes:" peers_file
if [[ ! -f ${peers_file} || ! -s ${peers_file} ]]; then
echo "$peers_file File not found!"
exit 1
fi
#Execute the node_collector on each node
if ! [[ -z "${parameter_username}" && -z "${parameter_password}" ]];
then
while read peer
do
if [ -z "$(ssh-keygen -F $peer)" ]; then
ssh-keyscan -H $peer >> ~/.ssh/known_hosts
fi
ssh -i $id_file $user@$peer "bash -s" < node_collector.sh -u $parameter_username -p $parameter_password &
done < "$peers_file"
else
while read peer
do
if [ -z "$(ssh-keygen -F $peer)" ]; then
ssh-keyscan -H $peer >> ~/.ssh/known_hosts
fi
ssh -i $id_file $user@$peer "bash -s" < node_collector.sh &
done < "$peers_file"
fi
#waiting for all node_collectors to complete
wait
mkdir $INFO_DIR
#copy the data from each node
while read peer
do
mkdir $INFO_DIR/$peer
scp -i $id_file $user@$peer:/tmp/InstaCollection.tar.gz $INFO_DIR/$peer/InstaCollection_$peer.tar.gz &
done < "$peers_file"
#waiting for all scp to complete
wait
#compress the info directory
result_file=/tmp/InstaCollection_$(date +%Y%m%d%H%M).tar.gz
tar -zcf $result_file -C $INFO_DIR .
rm -r $INFO_DIR
echo "Process complete. File generated : " $result_file