Compare commits

...

3 Commits

Author SHA1 Message Date
oleg 6458974866 progress: storage check uses hosts from config service 2024-08-06 16:05:55 -04:00
oleg df761027ec progress 2024-08-05 22:41:52 -04:00
oleg 90fa146190 fix 2024-08-05 18:17:12 -04:00
6 changed files with 170 additions and 39 deletions
+17 -15
View File
@@ -5,23 +5,23 @@ usage() {
exit 1 exit 1
} }
get_hosts_json() {
curl -s http://cloud23.cvtt.vpn:6789/admin/cvtt_hosts | ${HOME}/bin/hjson -j
}
get_user_hosts() { get_user_hosts() {
User=${1} local User=${1}
Domain=${2} local Domain=${2}
get_hosts_json | jq -r \ Cmd="curl -s http://cloud23.cvtt.vpn:6789/admin/cvtt_hosts"
--arg domain "${Domain}" \ Cmd="${Cmd} | ${HOME}/bin/hjson -j"
--arg usr "${User}" \ Cmd="${Cmd} | jq -r"
'.[$domain] | to_entries[] | select(.value.users[] | contains($usr)) | .key' Cmd="${Cmd} --arg domain \"${Domain}\""
Cmd="${Cmd} --arg usr \"${User}\""
Cmd="${Cmd} '.[\$domain] | to_entries[] | select(.value.users[] | contains(\$usr)) | .key'"
# echo $Cmd ### - FOR DEBUG ONLY
eval ${Cmd}
} }
echo "Started ${0} ${*} ..."
Domain=cvtt.vpn Domain=cvtt.vpn
echo "Started ${0} ${*} ..."
RootDir=${1} RootDir=${1}
if [ ! -d "${RootDir}" ]; then if [ ! -d "${RootDir}" ]; then
@@ -35,10 +35,12 @@ echo ${Cmd} && eval ${Cmd}
for User in cvtt oleg for User in cvtt oleg
do do
echo "User=$User" echo "User=$User"
Cmd="mkdir -p ${RootDir}/${User}"
echo ${Cmd} && eval ${Cmd}
hosts=$(get_user_hosts ${User} ${Domain}) hosts=$(get_user_hosts ${User} ${Domain})
mkdir -p ${RootDir}/${User} echo ${hosts}
print ${hosts}
exit
for host in ${hosts} for host in ${hosts}
do do
echo "====================" echo "===================="
+1 -1
View File
@@ -1 +1 @@
1.3.2 1.3.5
+126
View File
@@ -0,0 +1,126 @@
#!/usr/bin/env bash
usage() {
echo "Usage: $0 [-h <host (homestore*/cloud21)>] [-d <YYYYMMDD> (yesterday*)] [-s <source> (cvttdata/cloud21*)>]"
exit 1
}
is_valid() {
local inst=$1
local valid_instances=$2
for valid_inst in "${valid_instances[@]}";
do
if [[ "$inst" == "$valid_inst" ]]; then
return 0
fi
done
return 1
}
date=""
host=homestore
source=cloud21
while getopts ":h:d:s:" opt; do
case ${opt} in
d )
date=$OPTARG
;;
h )
host=$OPTARG
;;
s )
source=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
if [ "${date}" == "" ] ; then
date="yesterday"
fi
echo "$date $host $source"
valid_hosts=('homestore' 'cloud21')
if ! is_valid "${host}" "${valid_hosts[@]}" ; then
echo h
usage
fi
valid_sources=('cloud21' 'cvttdata')
if ! is_valid ${source} ${valid_sources[@]} ; then
echo s
usage
fi
if [ "${host}" == "cloud21" ] ; then
SourceHost=cloud21.cvtt.vpn
SourceUser=cvtt
SourceRootDir="/opt/store/cvtt/md_archive/crypto/${source}"
elif [ "${host}" == "homestore" ]; then
SourceHost=homestore.cvtt.vpn
SourceUser=oleg
SourceRootDir=/works/cvtt/md_archive/crypto/${source}
else
usage
fi
echo "${SourceHost} ${SourceUser} ${SourceRootDir}"
SourceFile=$(date -d ${date} "+%Y%m%d.mktdata.db")
SourceFileZip="${SourceFile}.gz"
SourceFilePath=$(date -d ${date} "+${SourceRootDir}/%Y/%m/${SourceFileZip}")
TargetDir="/opt/jupyter_gpu/data/crypto_md"
TargetFile=$(date -d ${date} "+%Y%m%d.mktdata.ohlcv.db")
TargetFilePath="${TargetDir}/${TargetFile}"
echo ${SourceFile}
tmp_dir=$(mktemp -d)
function cleanup {
cd ${HOME}
rm -rf ${tmp_dir}
}
trap cleanup EXIT
function download_file {
Cmd="rsync"
Cmd="${Cmd} -ahv"
if tty -s; then
Cmd="${Cmd} --progress=info2"
fi
Cmd="${Cmd} ${SourceUser}@${SourceHost}:${SourceFilePath} ${tmp_dir}/"
echo ${Cmd}
eval ${Cmd}
ls -lh ${tmp_dir}
Cmd="gunzip ${tmp_dir}/${SourceFileZip}"
echo ${Cmd} && eval ${Cmd}
ls -lh ${tmp_dir}
rm -f ${TargetFilePath}
touch ${TargetFilePath}
for table in bnbfut_ohlcv_1min bnbspot_ohlcv_1min coinbase_ohlcv_1min
do
Cmd="sqlite3 ${tmp_dir}/${SourceFile} \".dump ${table}\" | sqlite3 ${TargetFilePath}"
echo ${Cmd}
eval ${Cmd}
done
chmod 600 ${TargetFilePath}
ls -lh ${TargetFilePath}
}
download_file
+26 -23
View File
@@ -10,32 +10,24 @@ StatusChannel=Status-CVTT
AlertChannel=Alerts-CVTT AlertChannel=Alerts-CVTT
Sender=${RootDir}/ops/utils/send_mmost.sh Sender=${RootDir}/ops/utils/send_mmost.sh
# ----- For DEBUGGING
# Sender=cat # Sender=cat
# StatusChannel= # StatusChannel=
Hosts= get_user_hosts() {
Hosts="${Hosts} cloud11.cvtt.vpn" local User=${1}
Hosts="${Hosts} cloud15.cvtt.vpn" local Domain=${2}
Hosts="${Hosts} cloud16.cvtt.vpn"
Hosts="${Hosts} cloud17.cvtt.vpn"
Hosts="${Hosts} cloud21.cvtt.vpn"
Hosts="${Hosts} cloud22.cryptovaltrading.com"
Hosts="${Hosts} cvttdata.cvtt.vpn" Cmd="curl -s http://cloud23.cvtt.vpn:6789/admin/cvtt_hosts"
Hosts="${Hosts} cryptoval2.cvtt.vpn" Cmd="${Cmd} | ${HOME}/bin/hjson -j"
Hosts="${Hosts} cryptoval3.cvtt.vpn" Cmd="${Cmd} | jq -r"
Cmd="${Cmd} --arg domain \"${Domain}\""
Cmd="${Cmd} --arg usr \"${User}\""
Cmd="${Cmd} '.[\$domain] | to_entries[] | select(.value.users[] | contains(\$usr)) | .key'"
Hosts="${Hosts} homestore.cvtt.vpn" Cmd="${Cmd} | sed 's/\$/.${Domain}/'"
Hosts="${Hosts} nsbackup.sheynin.home" eval ${Cmd}
Hosts="${Hosts} dtvmhost.cvtt.vpn" }
Hosts="${Hosts} ops-server.cvtt.vpn"
Hosts="${Hosts} cvtt-prod-01.cvtt.vpn"
Hosts="${Hosts} cvtt-prod-02.cvtt.vpn"
Hosts="${Hosts} cvtt-prod-03.cvtt.vpn"
Metrics=()
TempFiles=
function cleanup { function cleanup {
echo Cleaing up temporary files: ${TempFiles} echo Cleaing up temporary files: ${TempFiles}
@@ -61,12 +53,14 @@ function space_alert() {
} }
function storage_check() { function storage_check() {
local Hosts=("${@}")
result_lines=() result_lines=()
declare -a SingleMeas declare -a SingleMeas
for host in ${Hosts} for host in ${Hosts[@]}
do do
echo "storage_check host=${host}" >&2
if [[ "${host}" == *"cryptovaltrading.com" ]]; then if [[ "${host}" == *"cryptovaltrading.com" ]]; then
port=7822 port=7822
else else
@@ -98,13 +92,22 @@ function storage_check() {
done done
} }
User=oleg
Metrics=()
TempFiles=
Hosts=()
for Domain in cvtt.vpn cryptovaltrading.com ; do
Hosts=("${Hosts[@]}" "$(get_user_hosts ${User} ${Domain})")
done
tmpfile=$(mktemp) tmpfile=$(mktemp)
TempFiles="${TempFiles} ${tmpfile}" TempFiles="${TempFiles} ${tmpfile}"
tmpfile2=$(mktemp) tmpfile2=$(mktemp)
TempFiles="${TempFiles} ${tmpfile2}" TempFiles="${TempFiles} ${tmpfile2}"
storage_check > ${tmpfile2} storage_check "${Hosts[@]}" > ${tmpfile2}
echo "## :card_file_box: STORAGE HEALTH CHECK" >> ${tmpfile} echo "## :card_file_box: STORAGE HEALTH CHECK" >> ${tmpfile}
echo >> ${tmpfile} echo >> ${tmpfile}