-
-
Save brettmilford/0abe9dfc4451a5f32aaccd2e5c8f5370 to your computer and use it in GitHub Desktop.
Query etcd keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eux | |
# brettmilford: added etcd /metrics gathering | |
# This file is based on https://code.launchpad.net/~freyes/+git/experiment | |
# Modified to use xargs instead of parallel | |
# 'etcd.etcdctl' is provided by the etcd snap | |
which etcd.etcdctl | |
PARALLEL_REQS=20 | |
SLEEP_SECS=0.1 | |
KEY="/registry/services/endpoints/kube-system/kube-controller-manager" | |
TEMPLOG=$(mktemp).log | |
TEMPLOGMETRICS=$(mktemp)-metrics.log | |
[[ $(cat /var/snap/kube-apiserver/current/args) =~ --etcd-servers=(.[^ ]+) ]] | |
ETCD_ENDPOINTS=${BASH_REMATCH[1]} | |
echo "logging to $TEMPLOG" | |
echo "etcd endpoints: $ETCD_ENDPOINTS" | |
# trap ctrl-c and call ctrl_c() | |
trap ctrl_c INT | |
function ctrl_c() { | |
local DEST=query-etcd.$(date '+%Y%m%d_%H%M').log | |
local DESTMETRICS=query-etcd-metrics.$(date '+%Y%m%d_%H%M').log | |
mv $TEMPLOG $DEST | |
mv $TEMPLOGMETRICS $DESTMETRICS | |
echo -e "\noutput at $DEST \nmetrics at $DESTMETRICS" | |
exit 0 | |
} | |
set +x | |
( | |
ts_and_log() { | |
while read line; do | |
# filter comments | |
[[ "$line" =~ ^\# ]] || echo "$(date +%d-%m-%YT%H:%m:%S) $line" 2>&1 >> $TEMPLOGMETRICS | |
done | |
} | |
while true; do | |
(curl -s -X GET "${ETCD_ENDPOINTS//\"/}/metrics" --cacert /root/cdk/etcd/client-ca.pem --cert /root/cdk/etcd/client-cert.pem --key /root/cdk/etcd/client-key.pem) | ts_and_log | |
/bin/sleep 5 | |
done | |
) & | |
while true; do | |
seq $PARALLEL_REQS | xargs -I {} -P$PARALLEL_REQS sudo etcd.etcdctl --cacert /root/cdk/etcd/client-ca.pem --cert /root/cdk/etcd/client-cert.pem --key /root/cdk/etcd/client-key.pem --endpoints=$ETCD_ENDPOINTS get -w json $KEY 2>&1 >> $TEMPLOG | |
/bin/sleep $SLEEP_SECS | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment