Skip to content

Commit

Permalink
feat: add collector-default to collect host info and log, e.g., dmesg
Browse files Browse the repository at this point in the history
Signed-off-by: Ray Chang <ray.chang@suse.com>
  • Loading branch information
weizhe0422 authored and bk201 committed Mar 16, 2023
1 parent c16cc5f commit 22744b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions hack/collector-default
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

HOST_PATH=$1
BUNDLE_DIR=$2

# RKE2: Logs for the kubelet are save in rke2 agent log folder
RKE2_KUBELET_LOG_PATH=${HOST_PATH}/var/lib/rancher/rke2/agent/logs/kubelet.log

function collect_sysinfo(){
cd ${BUNDLE_DIR}
mkdir -p hostinfos
cd hostinfos

echo "hostname : " `cat ${HOST_PATH}/etc/hostname` > hostinfo
echo "os-release : " `cat ${HOST_PATH}/etc/os-release` >> hostinfo
echo "system-info : " `uname -a` >> hostinfo

# Boot Configuration
cat ${HOST_PATH}/boot/config-$(uname -r) > kernel_config
}

function collect_dmesg(){
dmesg -HTx &> dmesg.log
}

function collect_syslog(){
tail -c 10m ${HOST_PATH}/var/log/syslog > syslog.log
}

function collect_kubelet_log(){
# On Linux nodes that use systemd, the kubelet and container runtime write to journald by default.
# ref. https://kubernetes.io/docs/concepts/cluster-administration/logging/#log-location-node
chroot ${HOST_PATH} /usr/bin/journalctl -r -u kubelet > kubelet.log

if [ -f ${RKE2_KUBELET_LOG_PATH} ]; then
cp ${RKE2_KUBELET_LOG_PATH} .
fi
}

function collect_logs(){
cd ${BUNDLE_DIR}
mkdir -p logs
cd logs

collect_dmesg
collect_syslog
collect_kubelet_log
}

collect_sysinfo
collect_logs
2 changes: 1 addition & 1 deletion hack/support-bundle-collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ if [ -x "$(which $OS_COLLECTOR)" ]; then
$OS_COLLECTOR $HOST_PATH $BUNDLE_DIR
else
echo "No OS collector found"
collector-default $HOST_PATH $BUNDLE_DIR
fi


cd ${OUTPUT_DIR}
zip -r node_bundle.zip $(basename ${BUNDLE_DIR})
rm -rf bundle
Expand Down

0 comments on commit 22744b6

Please sign in to comment.