Skip to content

Commit

Permalink
collector: improve the log time format
Browse files Browse the repository at this point in the history
    - Now we can get more accurate timestamp

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng authored and c3y1huang committed Jun 20, 2024
1 parent 1224f69 commit 366d823
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions hack/collector-harvester
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -ux

source /tmp/common
HOST_PATH=$1
BUNDLE_DIR=$2

Expand Down Expand Up @@ -99,18 +100,18 @@ mv $HOST_PATH/var/log/scc_supportconfig_$SUPPORT_BUNDLE_NODE_NAME.txz ./scc
mkdir -p logs
cd logs

chroot $HOST_PATH /usr/bin/journalctl -k > kernel.log
chroot $HOST_PATH $JOURNALCTL -k > kernel.log
# also collect logs of previous two boots
for ((i=1; i<=2; i++)); do
log_name="kernel.log.$i"
chroot $HOST_PATH /usr/bin/journalctl -k -b $((-i)) > $log_name
chroot $HOST_PATH $JOURNALCTL -k -b $((-i)) > $log_name
[ ! -s $log_name ] && rm -f $log_name
done

units=(rke2-server rke2-agent rancherd rancher-system-agent wicked iscsid)

for unit in ${units[@]}; do
chroot $HOST_PATH /usr/bin/journalctl -b all -u $unit | tail -c 10m > $unit.log
chroot $HOST_PATH $JOURNALCTL -b all -u $unit | tail -c 10m > $unit.log
done

cp ${HOST_PATH}/var/lib/rancher/rke2/agent/logs/kubelet.log .
Expand Down
7 changes: 4 additions & 3 deletions hack/collector-longhorn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -ux

source /tmp/common
HOST_PATH=$1
BUNDLE_DIR=$2

Expand Down Expand Up @@ -33,11 +34,11 @@ function collect_syslog(){
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
chroot ${HOST_PATH} $JOURNALCTL -r -u kubelet > kubelet.log

# For K3s cluster
chroot ${HOST_PATH} /usr/bin/journalctl -r -u k3s.service > k3s-service.log
chroot ${HOST_PATH} /usr/bin/journalctl -r -u k3s-agent.service > k3s-agent-service.log
chroot ${HOST_PATH} $JOURNALCTL -r -u k3s.service > k3s-service.log
chroot ${HOST_PATH} $JOURNALCTL -r -u k3s-agent.service > k3s-agent-service.log

if [ -f ${RKE2_KUBELET_LOG_PATH} ]; then
cp ${RKE2_KUBELET_LOG_PATH} .
Expand Down
2 changes: 2 additions & 0 deletions hack/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

JOURNALCTL="/usr/bin/journalctl -o short-precise"
2 changes: 2 additions & 0 deletions package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ RUN chmod +x /usr/bin/support-bundle-kit
ADD hack/collector-* /usr/bin/
RUN chmod +x /usr/bin/collector-*

ADD hack/common /tmp/

ENTRYPOINT ["entrypoint.sh"]

0 comments on commit 366d823

Please sign in to comment.