Skip to content

Instantly share code, notes, and snippets.

View drakonstein's full-sized avatar

Drakonstein drakonstein

View GitHub Profile
@drakonstein
drakonstein / birdawk.sh
Last active May 23, 2023 16:49
Birdhunt CFT challenge done in bash and then AWK. Find the coordinates for the birds in the grid and finish all 200 rounds before the timeout.
#!/bin/bash
inround=false
exec 5<>/dev/tcp/35.231.207.196/15830
while true; do
if $inround; then
awk 'BEGIN {coords=""} /B|^$/ {
if(NF == 0)
exit
for(i=2;i<=NF;i++) {
#!/bin/bash
API="https://registry.hub.docker.com/v2/repositories"
HASH_DIR="/home/david/k8s/scripts/hash"
# image tag namespace { space deliminated list of labels }
IMAGES="wordpress latest friends app=george
beamdog/nwserver latest games app=nwn
itzg/minecraft-server latest games app=minecraft instance=mc-persistent"
do_sleep=false
var SEVERITY_COLORS = [
'#97AAB3', '#7499FF', '#FFC859',
'#FFA059', '#E97659', '#E45959'
];
var RESOLVE_COLOR = '#009900';
var SLACK_MODE_HANDLERS = {
alarm: handlerAlarm,
event: handlerEvent
@drakonstein
drakonstein / rbd_snapshots.sh
Last active May 19, 2023 02:50
Script to automate snapshots for all RBDs in a pool based on key/value settings on RBDs
#!/bin/bash
[[ "$1" == *list* ]] && list=true || list=false
[[ "$1" == *force* ]] && force=true || force=false
ENABLED=true
# List of features to ensure are enabled on each RBD
FEATURES='layering exclusive-lock object-map fast-diff'
# Prefix for the metadata keys on RBDs for the backup snapshots
KEY_PREFIX=backsnap
# How many hours between backups. Anything over 24 will back up once/day.
pg_state=backfilling
counts=$(ceph pg dump pgs_brief 2>/dev/null | awk -F'.' '/'${pg_state}'/ {print $1}' | sort | uniq -c)
pools=$(echo "$counts" | awk '{print $2}' | sed 's/^/ /' | sed 's/$/\$\\\|/' | sed 's/\\|$//')
output=$(ceph df | awk '{print $1" "$3" "$2}' | grep "$pools")
while read count pool; do
output=$(echo "$output" | sed "s/ $pool$/ $count/")
done <<< "$counts"
echo "pool used #pgs $pg_state
$output" | column -t -s' '
@drakonstein
drakonstein / osd_omap_compaction.sh
Created February 13, 2019 18:32
Compacting omaps on OSDs
#!/bin/bash
# Name: osd_omap_compaction.sh
#
# This will compact the omap dbs on OSDs
# Wait until the cluster is Healthy
HEALTH_OK=${1:-"HEALTH_OK"}
while [[ "$(ceph health)" != "$HEALTH_OK" ]]; do
sleep 10
#!/bin/bash
# folder to place logs
logging_folder=/root/fio_testing
mkdir -p "$output_folder"
# use all mapped RBDs in the specified pool with the specified prefix
pool=rbd
rbd_prefix=test
rbds=$(echo $(ls /dev/rbd/${pool}/${rbd_prefix}*) | sed 's/ /:/g')
@drakonstein
drakonstein / ceph_avg_objs_per_pg.sh
Last active December 5, 2017 20:38
Find the average objects per pg in each Ceph pool
#!/bin/bash
declare -A pool_pgs
declare -A pool_objs
output=$(ceph pg dump 2>/dev/null | awk '/active/ {print $1,$2}' | sed 's/\.[[:alnum:]]*//')
while read pool objs; do
pool_objs[$pool]=$(( ${pool_objs[$pool]:-0} + $objs))
pool_pgs[$pool]=$(( ${pool_pgs[$pool]} + 1 ))
done <<< "$output"
output="pool+objects+pgs+per"
@drakonstein
drakonstein / gen_maps.sh
Last active May 19, 2023 02:58
Ceph cluster rewighting scripts. Not for the feint of heart. (Note, this is no longer necessary if you can use the balancer module)
#!/bin/bash
print_help() {
echo "
usage: gen_maps.sh [options] [variables]
--cluster Specify cluster (default is ceph)
--crush Specify custom crush map
"
@drakonstein
drakonstein / pg_subfolder_splitting.sh
Last active May 28, 2019 17:54
Split Ceph Filestore OSDs offline
#!/bin/bash
merge_num=-2
split_num=16
while [[ "$(ceph health)" != "HEALTH_OK" ]]; do
sleep 10
done
# Some method to set your ceph.conf file to the subfolder splitting settings you want.