Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created August 5, 2025 17:19
Show Gist options
  • Save yaauie/c7350c91bd84b824e749d118762f6143 to your computer and use it in GitHub Desktop.
Save yaauie/c7350c91bd84b824e749d118762f6143 to your computer and use it in GitHub Desktop.
A quick and dirty tool for reading a logstash persisted queue checkpoint file

Usage

Single Checkpoint:

lsq-cpdump "${LOGSTASH_HOME}/data/queue/main/checkpoint.head"

All Checkpoints for a given queue:

find "${LOGSTASH_HOME}/data/queue/main" -name 'checkpoint*' | sort | xargs -L1 lsq-cpdump
#/usr/bin/env bash
filename="${1?:path to file}"
if [ ! -f "$filename" ]; then
echo "ENOENT: ${filename}"
exit 1
fi
# extract hexdump as array of bytes
hexdump=($(xxd -u -l40 -ps "${filename}" | awk '{printf "%s", $0}' | sed 's/.\{2\}/& /g'))
# ensure we have 34 bytes
checkpoint_size_bytes="${#hexdump[@]}"
if (( $checkpoint_size_bytes != 34 )); then
>&2 echo "WARN: CHECKPOINT FILE SIZE MISMATCH (${checkpoint_size_bytes}})"
fi
fmt_raw() {
local concat=$(printf '%s' "${@}")
printf '[%16s]' "${concat}"
}
fmt_int() {
local concat=$(printf '%s' "${@}")
local decimal=$((0x${concat}))
printf '[%16s]: %s' "${concat}" "${decimal}"
}
echo "# CHECKPOINT ${filename}"
echo "VERSION $(fmt_int ${hexdump[@]:0:2})" # short
echo "PAGENUM $(fmt_int ${hexdump[@]:2:4})" # int
echo "1UNAKPG $(fmt_int ${hexdump[@]:6:4})" # int
echo "1UNAKSQ $(fmt_int ${hexdump[@]:10:8})" # long
echo "MINSEQN $(fmt_int ${hexdump[@]:18:8})" # long
echo "ELEMNTS $(fmt_int ${hexdump[@]:26:4})" # int
echo "CHECKSM $(fmt_raw ${hexdump[@]:30:4})" # int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment