Add -e option
This commit is contained in:
parent
52d8f293b6
commit
acb1171422
|
@ -11,12 +11,14 @@ usage() {
|
||||||
echo "Error: $*"
|
echo "Error: $*"
|
||||||
fi
|
fi
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
usage: $0 [-d] [username]
|
usage: $0 [-e] [-d] [username]
|
||||||
|
|
||||||
Creates a testnet dev metrics database
|
Creates a testnet dev metrics database
|
||||||
|
|
||||||
username InfluxDB user with access to create a new database
|
username InfluxDB user with access to create a new database
|
||||||
-d Delete the database instead of creating it
|
-d Delete the database instead of creating it
|
||||||
|
-e Assume database already exists and SOLANA_METRICS_CONFIG is
|
||||||
|
defined in the environment already
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
|
@ -24,8 +26,9 @@ EOF
|
||||||
|
|
||||||
loadConfigFile
|
loadConfigFile
|
||||||
|
|
||||||
|
useEnv=false
|
||||||
delete=false
|
delete=false
|
||||||
while getopts "hd" opt; do
|
while getopts "hde" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h|\?)
|
h|\?)
|
||||||
usage
|
usage
|
||||||
|
@ -34,6 +37,9 @@ while getopts "hd" opt; do
|
||||||
d)
|
d)
|
||||||
delete=true
|
delete=true
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
useEnv=true
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
usage "Error: unhandled option: $opt"
|
usage "Error: unhandled option: $opt"
|
||||||
;;
|
;;
|
||||||
|
@ -41,29 +47,34 @@ while getopts "hd" opt; do
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
username=$1
|
if $useEnv; then
|
||||||
[[ -n "$username" ]] || usage "username not specified"
|
[[ -n $SOLANA_METRICS_CONFIG ]] ||
|
||||||
|
usage "Error: SOLANA_METRICS_CONFIG is not defined in the environment"
|
||||||
|
else
|
||||||
|
username=$1
|
||||||
|
[[ -n "$username" ]] || usage "username not specified"
|
||||||
|
|
||||||
read -rs -p "InfluxDB password for $username: " password
|
read -rs -p "InfluxDB password for $username: " password
|
||||||
[[ -n $password ]] || { echo "Password not specified"; exit 1; }
|
[[ -n $password ]] || { echo "Password not specified"; exit 1; }
|
||||||
echo
|
echo
|
||||||
|
|
||||||
query() {
|
query() {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
curl -XPOST \
|
curl -XPOST \
|
||||||
"https://metrics.solana.com:8086/query?u=${username}&p=${password}" \
|
"https://metrics.solana.com:8086/query?u=${username}&p=${password}" \
|
||||||
--data-urlencode "q=$*"
|
--data-urlencode "q=$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
query "DROP DATABASE \"$netBasename\""
|
query "DROP DATABASE \"$netBasename\""
|
||||||
! $delete || exit 0
|
! $delete || exit 0
|
||||||
query "CREATE DATABASE \"$netBasename\""
|
query "CREATE DATABASE \"$netBasename\""
|
||||||
query "ALTER RETENTION POLICY autogen ON \"$netBasename\" DURATION 7d"
|
query "ALTER RETENTION POLICY autogen ON \"$netBasename\" DURATION 7d"
|
||||||
query "GRANT READ ON \"$netBasename\" TO \"ro\""
|
query "GRANT READ ON \"$netBasename\" TO \"ro\""
|
||||||
query "GRANT WRITE ON \"$netBasename\" TO \"scratch_writer\""
|
query "GRANT WRITE ON \"$netBasename\" TO \"scratch_writer\""
|
||||||
|
|
||||||
echo "export \
|
SOLANA_METRICS_CONFIG="db=$netBasename,u=scratch_writer,p=topsecret"
|
||||||
SOLANA_METRICS_CONFIG=\"db=$netBasename,u=scratch_writer,p=topsecret\" \
|
fi
|
||||||
" >> "$configFile"
|
|
||||||
|
echo "export SOLANA_METRICS_CONFIG=\"$SOLANA_METRICS_CONFIG\"" >> "$configFile"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue