#!/bin/bash zone=smf1 service_account=nighthawk_revenue_backend service=nighthawk_haplolite_fanout_timelines_backend_a service_name=haplolite port_name=redis_0 nInstance=1 rcli=$HOME/redis32/src/redis-cli mkdir log 2>/dev/null mkdir keys 2>/dev/null mkdir klen 2>/dev/null mkdir info 2>/dev/null mkdir ttl 2>/dev/null # set -e # set -x # rm log/* 2>/dev/null # pkill -9 -f redis-cli # trap -e "pkill -9 -f redis-cli" function prepare() { cd $HOME; packer fetch --cluster=smf1 aurora aurora live; } # get the host and port of Redis instance function get_host_port() { zone=$1 service_account=$2 service=$3 service_name=$4 host_port_file=${service_name}_host_port jobListStr=$($HOME/aurora job list ${zone}/${service_account}/prod|grep prod|grep ${service}) declare -a jobList=($jobListStr) for job in ${jobList[@]}; do jobInfo=$($HOME/aurora job status ${job} --write-json) for idx in `seq 0 $((nInstance-1))`; do host=$(echo $jobInfo|jq ".[0].active[${idx}].assignedTask.slaveHost" | sed 's/"//g') port=$(echo $jobInfo|jq ".[0].active[${idx}].assignedTask.assignedPorts.${port_name}") echo "$host $port" echo $host $port $job >> ${host_port_file} done done } # collect the logs from host and port function collect_redis() { service_name=$1 host=$2 port=$3 cnt=20000000 echo -e "info" | ${rcli} -h $host -p $port --no-raw > info/info.${host}.${port} for db in `seq 1 256`; do echo ${host} db${db} grep db${db} info/info.${host}.${port} > /dev/null if [[ $? == 1 ]]; then break fi sleep 2 echo -e "select ${db}\nscan 0 count ${cnt}" | ${rcli} -h $host -p $port --no-raw >> keys/keys.${host}.${port}.${db} python3 getkey.py keys/keys.${host}.${port}.${db} ${db} # cat keys/keys.${host}.${port}.pipe | ${rcli} -h $host -p $port # get klen cat keys/keys.${host}.${port}.${db}.pipe | nc $host $port >> klen/keylen.${host}.${port} # get ttl # cat keys.${host}.prod.twitter.com.${port}.${i}.pipe | nc $host $port > ttl/ttl.${host}.prod.twitter.com.${port}.${i} rm keys/keys.${host}.${port}.${db} keys/keys.${host}.${port}.${db}.pipe done if ! ( screen -ls | grep monitor.${host}.${port} > /dev/null); then screen -dmS monitor.${host}.${port}; fi screen -S monitor.${host}.${port} -X stuff $"${rcli} -h $host -p $port monitor >> log/${service_name}.${host}.${port}.log\n" } function collect_all() { service=$1 service_name=$2 host_port_file=${service_name}_host_port rm ${host_port_file} 2>/dev/null get_host_port ${zone} ${service_account} ${service} ${service_name} while read -r line do host=$(echo $line|cut -d " " -f1); port=$(echo $line|cut -d " " -f2); job_path=$(echo $line|cut -d " " -f3); echo '*****************************************' collect_redis ${service_name} ${host} ${port} done < ${host_port_file} # for line in $(cat ${host_port_file}); do # host=$(echo $line|cut -d " " -f1); # port=$(echo $line|cut -d " " -f2); # job_path=$(echo $line|cut -d " " -f3); # echo '*****************************************' # collect_redis ${service_name} ${host} ${port} # done } collect_all nighthawk_haplolite_prod_backend_a haplolite collect_all nighthawk_haplolite_fanout_timelines_backend_a fanout # collect_all nighthawk_dm_backend dm # collect_all nighthawk_notificationservice_api_prod1_backend notification # collect haplolite smf1-hlh-30-sr1.prod 31272 # collect fanout smf1-hif-21-sr1.prod 31938 # sleep 2; # while true; do logrotate -f ../rotate.conf -s state & sleep 3600; done