Skip to content

Instantly share code, notes, and snippets.

@fabiojose
Created Sep 30, 2021
Embed
What would you like to do?
Cálculo do request_percentage
#!/bin/bash
# Ferramentas necessárias:
# - Kafka CLI
# - bash
# - grep
# - cut
# - printf
# - tr
# Utilização
# ./request_percentage.sh <kafka server> <numero tenants>
BOOTSTRAP_SERVER=$1
TENANTS=$2
# id do primeiro broker retornado
BROKER_ID=$(kafka-configs.sh --bootstrap-server $BOOTSTRAP_SERVER \
--describe \
--entity-type brokers \
--all | grep 'broker.id=' | head -1 | cut -d'=' -f2 | cut -d' ' -f1)
CONFIGS=$(kafka-configs.sh --bootstrap-server $BOOTSTRAP_SERVER \
--describe \
--entity-type brokers \
--entity-name $BROKER_ID \
--all)
NUM_IO_THREADS=$(echo "$CONFIGS" | grep 'num.io.threads' | cut -d'=' -f2 | cut -d' ' -f1)
NUM_NETWORK_THREADS=$(echo "$CONFIGS" | grep 'num.network.threads' | cut -d'=' -f2 | cut -d' ' -f1)
QUOTA_WINDOW_SIZE_SECONDS=$(echo "$CONFIGS" | grep 'DEFAULT_CONFIG:quota.window.size.seconds' | cut -d'=' -f2 | cut -d' ' -f1)
CAPACIDADE_TOTAL=$((($NUM_IO_THREADS + $NUM_NETWORK_THREADS) * 100))
REQUEST_PERCENTAGE=$(printf %.1f "$((10**3 * $CAPACIDADE_TOTAL/$TENANTS))e-3" | tr ',' '.')
echo ''
echo "broker.id...................: $BROKER_ID"
echo "num.io.threads..............: $NUM_IO_THREADS"
echo "num.network.threads.........: $NUM_NETWORK_THREADS"
echo "quota.window.size.seconds...: $QUOTA_WINDOW_SIZE_SECONDS"
echo ''
echo "capacidade total............: $CAPACIDADE_TOTAL"
echo "tenants.....................: $TENANTS"
echo ''
echo "request_percentage p/ tenant: $REQUEST_PERCENTAGE"
echo ''
echo 'Comando atualização cota para user default:'
echo " kafka-configs.sh --bootstrap-server $BOOTSTRAP_SERVER --alter --add-config 'request_percentage=$REQUEST_PERCENTAGE' --entity-type users --entity-default"
echo ''
echo 'Comando atualização cota para client.id default:'
echo " kafka-configs.sh --bootstrap-server $BOOTSTRAP_SERVER --alter --add-config 'request_percentage=$REQUEST_PERCENTAGE' --entity-type clients --entity-default"
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment