Skip to content

Instantly share code, notes, and snippets.

@apetenchea
Last active May 19, 2024 11:28
Show Gist options
  • Save apetenchea/f1843d81bb52b82d0384c9bdd89bc2b4 to your computer and use it in GitHub Desktop.
Save apetenchea/f1843d81bb52b82d0384c9bdd89bc2b4 to your computer and use it in GitHub Desktop.
Useful ArangoDB shell functions
export ARANGODB_PATH="$HOME/arangodb"
# Continue process listening on port
function portcont() {
kill -SIGCONT $(portpid "$1")
}
# Kill process listening on port
function portkill() {
kill -9 $(portpid "$1")
}
# Get command info of process listening on port
function portinfo() {
local cmd=$(portpid "$1")
ps aux | grep "$cmd"
}
# List server endpoints
function listEndpoints() {
curl -s http://localhost:8530/_admin/cluster/health | jq ".Health | .[] |= .Endpoint"
}
# Shutdown local cluster
function shutdownLocalCluster() {
pkill -9 arangod
}
# Generate unique 5 hex digit log id
function logid() {
openssl rand -hex 3 | sed 's/.//;s/\(.*\)/"\1"/';
}
# > start=$(date +%s)
# ... do something ...
# > echo "$(duration $start)"
# 10 minutes, 32 seconds
duration() {
perl -MTime::Seconds -le \
'print Time::Seconds->new(time - $ARGV[0])->pretty' \
$1
}
# Run tests in a loop
retry_til_failure() {
(
i=1
start=$(date +%s)
while "$@"
do
rm -rf "$HOME/.rr/*"
echo "=== $i successful runs"
echo "=== $(duration $start) since start"
i=$((i+1))
done
echo "=== ${i}th try failed";
echo "=== took $(duration $start)"
)
}
# agency analyzer
function aaa() {
if [ "$#" -gt 0 ]
then
bash -c "python $ARANGODB_PATH/aaa/aaa.py $@";
else
bash -c "python $ARANGODB_PATH/aaa/aaa.py http://localhost:8530";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment