From a081e684c05022a987640f521024e9cef9bd917a Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Thu, 20 Jun 2024 11:56:38 +0800 Subject: [PATCH] collector: improve the log time format - Now we can get more accurate timestamp Signed-off-by: Vicente Cheng --- hack/collector-harvester | 7 ++++--- hack/collector-longhorn | 7 ++++--- hack/common | 2 ++ package/Dockerfile | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 hack/common diff --git a/hack/collector-harvester b/hack/collector-harvester index afec64c1..ee7bd17c 100755 --- a/hack/collector-harvester +++ b/hack/collector-harvester @@ -1,5 +1,6 @@ #!/bin/bash -ux +source /tmp/common HOST_PATH=$1 BUNDLE_DIR=$2 @@ -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 . diff --git a/hack/collector-longhorn b/hack/collector-longhorn index daf0533e..0fc55d99 100644 --- a/hack/collector-longhorn +++ b/hack/collector-longhorn @@ -1,5 +1,6 @@ #!/bin/bash -ux +source /tmp/common HOST_PATH=$1 BUNDLE_DIR=$2 @@ -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} . diff --git a/hack/common b/hack/common new file mode 100644 index 00000000..29cf57a5 --- /dev/null +++ b/hack/common @@ -0,0 +1,2 @@ + +JOURNALCTL="/usr/bin/journalctl -o short-precise" diff --git a/package/Dockerfile b/package/Dockerfile index d9c9035a..68e75703 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -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"]