github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/observability/access-logs.md (about)

     1  ---
     2  title: Access logs
     3  description: How to access cluster log files
     4  keywords: [access logs]
     5  sidebar_position: 3
     6  ---
     7  
     8  # Access logs
     9  
    10  The KubeBlocks log enhancement function aims to simplify troubleshooting. With `kbcli`, the command line tool of KubeBlocks, you can view all kinds of logs generated by the database clusters running on KubeBlocks, such as slow logs, error logs, audit logs, and the container running logs (Stdout and Stderr). For Redis, only the running log is supported.
    11  
    12  The KubeBlocks log enhancement function uses methods similar to kubectl exec and kubectl logs to ensure a self-closed loop and lightweight.
    13  
    14  ## Before you start
    15  
    16  - The container image supports `tail` and `xargs` commands.
    17  - Install KubeBlocks: You can install KubeBlocks by [kbcli](./../installation/install-with-kbcli/install-kubeblocks-with-kbcli.md) or by [Helm](./../installation/install-with-helm/install-kubeblocks-with-helm.md).
    18  - In this guide, we take the MySQL engine as an example, the operation is the same for all database engines.
    19  
    20  ## Steps
    21  
    22  1. Enable the log enhancement function.
    23  
    24     * Enable this function when creating a cluster.
    25  
    26       * If you create a cluster by running the `kbcli cluster create` command, add the `--enable-all-logs=true` option to enable the log enhancement function. When this option is `true`, all the log types defined by `spec.componentDefs.logConfigs` in `ClusterDefinition` are enabled automatically.
    27  
    28         ```bash
    29         kbcli cluster create mysql --enable-all-logs=true mycluster
    30         ```
    31  
    32     * Update this cluster if you did not enable it when creating a cluster.
    33  
    34         ```bash
    35         kbcli cluster update mycluster --enable-all-logs=true -n <namespace>
    36         ```
    37  
    38      :::note
    39  
    40      The default namespace in which a cluster is created is `default`. If you specify a namespace when creating a cluster, fill in `<namespace>` with your customized one.
    41  
    42      :::
    43  
    44  2. View the supported logs.
    45  
    46     Run the `kbcli cluster list-logs` command to view the enabled log types of the target cluster and the log file details. INSTANCE of each node is displayed.
    47  
    48     ***Example***
    49  
    50     ```bash
    51     kbcli cluster list-logs mycluster
    52     >
    53     INSTANCE                     LOG-TYPE        FILE-PATH                                   SIZE        LAST-WRITTEN                          COMPONENT
    54     mycluster-mysql-0        error           /data/mysql/log/mysqld-error.log            6.4K        Feb 06, 2023 09:13 (UTC+00:00)        mysql
    55     mycluster-mysql-0        general         /data/mysql/log/mysqld.log                  5.9M        Feb 06, 2023 09:13 (UTC+00:00)        mysql
    56     mycluster-mysql-0        slow            /data/mysql/log/mysqld-slowquery.log        794         Feb 06, 2023 09:13 (UTC+00:00)        mysql       
    57     ```
    58  
    59  3. Access the cluster log file.
    60  
    61     Run the `kbcli cluster logs` command to view the details of the target log file generated by the target instance on the target cluster. You can use different options to view the log file details you need.
    62     You can also run `kbcli cluster logs -h` to see the examples and option descriptions.
    63  
    64     ```bash
    65     kbcli cluster logs -h
    66     ```
    67  
    68      <details>
    69  
    70      <summary>Output</summary>
    71  
    72     ```bash
    73     Access cluster log file
    74  
    75     Examples:
    76       # Return snapshot logs from cluster mycluster with default primary instance (stdout)
    77       kbcli cluster logs mycluster
    78  
    79       # Display only the most recent 20 lines from cluster mycluster with default primary instance (stdout)
    80       kbcli cluster logs --tail=20 mycluster
    81  
    82       # Return snapshot logs from cluster mycluster with specify instance my-instance-0 (stdout)
    83       kbcli cluster logs mycluster --instance my-instance-0
    84  
    85       # Return snapshot logs from cluster mycluster with specify instance my-instance-0 and specify container
    86       # my-container (stdout)
    87       kbcli cluster logs mycluster --instance my-instance-0 -c my-container
    88  
    89       # Return slow logs from cluster mycluster with default primary instance
    90       kbcli cluster logs mycluster --file-type=slow
    91  
    92       # Begin streaming the slow logs from cluster mycluster with default primary instance
    93       kbcli cluster logs -f mycluster --file-type=slow
    94  
    95       # Return the specify file logs from cluster mycluster with specify instance my-instance-0
    96       kbcli cluster logs mycluster --instance my-instance-0 --file-path=/var/log/yum.log
    97  
    98       # Return the specify file logs from cluster mycluster with specify instance my-instance-0 and specify
    99       # container my-container
   100       kbcli cluster logs mycluster --instance my-instance-0 -c my-container --file-path=/var/log/yum.log
   101     ```
   102     </details>
   103  
   104  4. (Optional) Troubleshooting.
   105  
   106       The log enhancement function does not affect the core process of KubeBlocks. If a configuration exception occurs, a warning shows to help troubleshoot.
   107       `warning` is recorded in the `event` and `status.Conditions` of the target database cluster.
   108  
   109       View `warning` information.
   110  
   111       - Run `kbcli cluster describe <cluster-name>` to view the status of the target cluster. You can also run `kbcli cluster list events <cluster-name>` to view the event information of the target cluster directly.
   112  
   113         ```bash
   114         kbcli cluster describe mycluster
   115         ```
   116  
   117         ```bash
   118         kbcli cluster list-events mycluster
   119         ```
   120  
   121       - Run `kubectl describe cluster <cluster-name>` to view the warning.
   122  
   123         ```bash
   124         kubectl describe cluster mycluster
   125         ```
   126    
   127          ***Example***
   128  
   129          ```bash
   130          Status:
   131            Cluster Def Generation:  3
   132            Components:
   133                Replicasets:
   134                  Phase:  Running
   135            Conditions:
   136              Last Transition Time:  2022-11-11T03:57:42Z
   137              Message:               EnableLogs of cluster component replicasets has invalid value [errora slowa] which isn't defined in cluster definition component replicasets
   138              Reason:                EnableLogsListValidateFail
   139              Status:                False
   140              Type:                  ValidateEnabledLogs
   141            Observed Generation:     2
   142            Operations:
   143              Horizontal Scalable:
   144                  Name:  replicasets
   145              Restartable:
   146                replicasets
   147              Vertical Scalable:
   148                replicasets
   149            Phase:  Running
   150          Events:
   151            Type     Reason                      Age   From                Message
   152            ----     ------                      ----  ----                -------
   153            Normal   Creating                    49s   cluster-controller  Start Creating in Cluster: release-name-error
   154            Warning  EnableLogsListValidateFail  49s   cluster-controller  EnableLogs of cluster component replicasets has invalid value [errora slowa] which isn't defined in cluster definition component replicasets
   155            Normal   Running                     36s   cluster-controller  Cluster: release-name-error is ready, current phase is Running
   156          ```