在阿里云Kubernetes集群或自建Kubernetes集群中使用Logtail采集日志发生异常时,您可以通过Logtail容器自助诊断工具查看客户端是否存在异常情况,根据工具提示快速定位并解决问题。诊断工具仅通过必要资源的信息进行诊断。诊断过程中,对您的Kubernetes环境无侵入。本文主要介绍如何使用Logtail容器快速诊断工具。

步骤一:下载及运行诊断工具

  1. 登录Linux服务器。
    注意 诊断工具仅支持通过Linux系统的服务器进行检测,且该服务器需具备可访问Kubernetes集群的kubeconfig配置文件。
  2. 执行以下命令,下载诊断工具。
    wget http://logtail-release.oss-cn-hangzhou.aliyuncs.com/linux64/ilogtail-trace-tool

    如果返回如下内容,表示下载完成。

    2022-01-14 16:26:57 (11.4 MB/s) - ‘ilogtail-trace-tool’ saved [15913536/15913536]
  3. 执行如下命令,运行诊断工具。
    chmod u+x ./ilogtail-trace-tool
    ./ilogtail-trace-tool
  4. 切换诊断工具的语言。

    目前支持中文和英文。

    [QUESTION]: 2022/01/14 16:27:10 please choose language Please input [0,1] to choose which item you want to check:
    0: English
    1: Chinese
  5. 根据页面提示,完成如下配置。
    • 问题1~问题3:配置为您在采集容器日志时所设置的Project、Logstore和Logtail采集配置。
    • 问题4:输入Y
    • 问题5:配置为kubeconfig文件的位置。如果是在默认路径(~/.kube/config),输入d即可。
    • 问题6~问题8:关于Logtail组件相关的配置。

      在Kubernetes集群中,Logtail组件默认部署在kube-system空间中。如果没有修改Logtail组件所属的命名空间,输入d即可。

    [QUESTION]: 2022/01/14 16:28:10 Please input your Project name:
    k8s-log-cc47****954428
    [QUESTION]: 2022/01/14 16:28:13 Please input your LogStore name:
    test-stdout
    [QUESTION]: 2022/01/14 16:28:17 Please input your LogConfig name:
    test-stdout
    [QUESTION]: 2022/01/14 16:28:21 Is the ilogtail running in kubernetes? Please input Y/N.:
    Y
    [QUESTION]: 2022/01/14 16:28:34 please input your kube config position [Default value is ~/.kube/config, enter `d` to choose it]
    d
    [QUESTION]: 2022/01/14 16:28:36 please input your logtail-ds position with {logtail-daemonset}/{namespace} pattern [Default value is logtail-ds/kube-system, enter `d` to choose it]:
    d
    [QUESTION]: 2022/01/14 16:28:49 please input your log-controller position with {alibaba-log-configuration}/{namespace} pattern [Default value is alibaba-log-configuration/kube-system, enter `d` to choose it]:
    d
    [QUESTION]: 2022/01/14 16:28:59 please input your log-controller position with {alibaba-log-controller-deployment}/{namespace} pattern [Default value is alibaba-log-controller/kube-system, enter `d` to choose it]:
    d
    如果返回如下信息,表示诊断工具开始运行。
    [OK]: 2022/01/14 16:29:28 logtail daemonSet resource exist
    [WARNING]: 2022/01/14 16:29:28 Default logtail daemonset timezone is UTC
    [OK]: 2022/01/14 16:29:28 logtail daemonSet mount hostpath correct
    [INFO]: 2022/01/14 16:29:29 Logtail version: 0.16.62

步骤二:开始诊断

说明 诊断工具会将诊断的必要信息存储于ilogtail-trace.tar文件中。如果诊断通过后,仍存在问题,您可以提交提工单进行进一步排查。
诊断工具支持心跳问题诊断和采集问题诊断。您可以根据您所遇到的问题,进行选择。
[QUESTION]: 2022/01/14 16:30:04 please choose which item you want to check : Please input [0,1] to choose which item you want to check:
0: MachineGroup heartbeat fail.
1: MachineGroup heartbeat is ok, but log files have not been collected.

心跳问题检测

说明 在Kubernetes集群中,Logtail通过环境变量挂载alibaba-log-configuration/kube-system的方式定义基础的配置信息。心跳问题检测仅仅通过轻量读取此资源信息进行检测,不会对您Kubernetes集群造成影响。

根据页面提示,完成如下配置。

[QUESTION]: 2022/01/14 16:30:23 Does your aliuid exist in xxxxxxx Please input Y/N.:
y
[OK]: 2022/01/14 16:30:30 aliuid correct
[QUESTION]: 2022/01/14 16:30:30 Does your region[cn-beijing] and endpoint[cn-beijing-intranet.log.aliyuncs.com] correct? Please input Y/N.:
y
[OK]: 2022/01/14 16:30:33 region and endpoint correct
[QUESTION]: 2022/01/14 16:30:33 Does your machine group with the user deined id k8s-group-xxxxx? Please input Y/N.:
y
[OK]: 2022/01/14 16:30:35 user defined id correct
[WARNING]: 2022/01/14 16:30:35 If the problem persists,please contact with the sls developer and provide the ilogtail-trace.tar file.
[OK]: 2022/01/14 16:30:35 All tests are passed

采集问题检测

根据页面提示,设置容器所在位置,该容器为产生待采集日志的容器。配置格式为{podName}/{namespace},例如nginx-log-sidecar-demo-zlx5x/default。

[QUESTION]: 2022/01/14 16:31:49 please input the position of your pod having collection problem with {podName}/{namespace} pattern
nginx-log-sidecar-demo-zlx5x/default
  • 如果问题Pod中存在多个容器,检测工具将自动显示容器内所有容器,请您选择产生日志的容器。
    [QUESTION]: 2022/01/14 16:32:40  Please input [0,1] to choose which item you want to check:
    0: nginx-log-demo container
    1: logtail container
    0
  • 如果问题Pod中只有一个容器,则自动跳过此选项。

输入容器位置后,检测工具将首先进行Logtail容器Label、容器环境变量或Kubernetes基础信息的匹配性检测。如果机器匹配,继续进行容器路径探测,检查容器路径可达性(Logtail通过标准Docker或CRI接口获取容器路径,但是某些自建集群或其他云平台会存在自定义路径情况,可能存在路径不可达问题)。Logtail容器Label、容器环境变量的配置说明,请参见通过DaemonSet-控制台方式采集容器文本日志通过DaemonSet-控制台方式采集容器标准输出

  • 如果返回如下信息,表示容器匹配失败。请先检查您的配置。
    [ERROR]: 2022/01/14 16:33:34 centos/centos/default container label isn't mapping to config ##1.0##qs-demos$file-collect: .......
  • 如果返回如下信息,表示容器匹配成功,开始对日志采集问题进行检测。
    [INFO]: 2022/01/14 16:33:47 centos/centos/default pod mapping config ##1.0##qs-demos$file-collect: true
    [OK]: 2022/01/14 16:33:47 Pod is mapping to your LogConfig
    如果存在问题,会返回提示信息。例如:
    [ERROR]: 2022/01/14 16:33:47 config: ##1.0##qs-demos$test find unaviable path: /logtail_host/var/lib/docker/overlay2/eb23efaa3e4afdfce0638da6e11f0ee2a020e7fa891f7a0cfa2c761102bf4ceb/diff/trace-log-demos
    [SUGGESTION]: 2022/01/14 16:33:47 Other config: ##1.0##qs-demos$test is also sniffing the container, maybe conflicts.
    [ERROR]: 2022/01/14 16:33:47 config: ##1.0##qs-demos$sls-mall find unaviable path: /logtail_host/var/lib/docker/overlay2/eb23efaa3e4afdfce0638da6e11f0ee2a020e7fa891f7a0cfa2c761102bf4ceb/diff/sls-mall
    [SUGGESTION]: 2022/01/14 16:33:47 Other config: ##1.0##qs-demos$sls-mall is also sniffing the container, maybe conflicts.
    [INFO]: 2022/01/14 16:33:48 find files in centos container path: total 1868
    drwxr-xr-x 4 root root    4096 Nov 30 04:05 .
    drwxr-xr-x 9 root root    4096 Nov 30 03:58 ..
    dr-xr-xr-x 2 root root    4096 Nov  9 09:00 bin
    dr-xr-xr-x 3 root root    4096 Nov  9 09:00 lib
    -rw------- 1 root root 1880970 Dec  3 06:09 nohup.out
    -rw-r--r-- 1 root root     172 Nov 30 04:05 run.sh
    [ERROR]: 2022/01/14 16:33:47 Failed to get time zone of pod: nginx-log-sidecar-4hwbk under namespace default
    [WARNING]: 2022/01/14 16:33:47 Work pod timezone: is not same as the logtail pod:+0000
    
    [WARNING]: 2022/01/14 16:33:47 If the problem persists,please contact with the sls developer and provide the ilogtail-trace.tar file.
    • 检测容器内文件采集模式路径是否存在

      采集文本日志时,Logtail会将源采集信息存储于Logtail Pod的/usr/local/ilogtail/docker_path_config.json文件,检测工具通过此文件进行检测,无需担心成本开销。

    • 检测是否存在重复采集

      由于配置问题,导致一份日志被多个Logtail采集。诊断工具会判断采集冲突的Logtail采集配置,您可以根据提示进行修复。

    • 检测容器时间是否正确
      如果遇到采集时区的问题,一般为采集容器与Logtail容器时区不匹配,默认Logtail为UTC时区。此时您可以通过挂载宿主机/etc/localtime进行处理。
      volumeMounts:
          - name: timezone
          mountPath: /etc/localtime
      volumes:
         - name: timezone
           hostPath: /etc/localtime