Log collection method, device, equipment and readable storage medium
By obtaining the log types of business pods in the Daemonset pod of the kubernetes cluster, mounting and collecting logs, the problem of difficulty in collecting non-standard logs in the cluster is solved, and efficient collection and persistence of different types of logs is achieved.
Patent Information
- Application Number
- CN202111574945.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2041-12-21
AI Technical Summary
In kubernetes clusters, it is difficult to collect other types of logs inside pods except standard logs.
By obtaining the type of log to be collected in the business pod in the Daemonset pod, mount the corresponding log to the local disk, and generate the corresponding directory on the local disk, mount the directory to the Daemonset pod, generate configuration files according to the log path, and collect logs.
It realizes the collection of different types of logs inside the pod, improves the reliability and accuracy of log collection, and facilitates understanding of the cluster operation status and error exclusion.
Smart Images

Figure CN114237759B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of kubernetes clusters, and more specifically, to a log collection method, apparatus, device, and readable storage medium. Background Art
[0002] In a kubernetes (k8s for short) cluster, collecting logs can help you understand the running status of the cluster and troubleshoot errors.
[0003] Currently, in a kubernetes cluster, fluentbit (an open source log collection tool) or fluentd (a log collection, processing, and forwarding system) is often deployed to the Node nodes of the kubernetes cluster (a kubernetes cluster requires many servers, which are called Node nodes) to collect logs. However, this method can only collect standard logs in pods (the smallest scheduling unit in k8s), but cannot collect other types of logs inside pods.
[0004] In summary, how to collect different types of logs inside a pod is a technical problem that needs to be urgently solved by those skilled in the art. Summary of the invention
[0005] In view of this, the purpose of this application is to provide a log collection method, apparatus, device and readable storage medium for collecting different types of logs inside a pod.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] A log collection method, applied to Daemonset pod in a Kubernetes cluster, includes:
[0008] Obtain the type of each log to be collected in the business pod, and mount the log corresponding to the type in the business pod to the local disk;
[0009] Generate a directory corresponding to the log on the local disk, mount the directory into the Daemonset pod, and obtain a path corresponding to the log;
[0010] A configuration file is generated according to the path corresponding to the log, and the logs in the directory are collected according to the configuration file.
[0011] Preferably, it also includes:
[0012] When a business pod is destroyed, it is determined whether the destroyed business pod is currently included in the kubernetes cluster;
[0013] If the destroyed business pod is not currently included in the kubernetes cluster, obtain the last write time of the log corresponding to the destroyed business pod;
[0014] Determine whether the time difference between the last write time of the log and the current time is greater than a preset value;
[0015] If the time difference between the last writing time of the log and the current time is not greater than a preset value, retain the log;
[0016] If the time difference between the last writing time of the log and the current time is greater than a preset value, the log is deleted.
[0017] Preferably, it also includes:
[0018] When a business pod is rebuilt, the log corresponding to the type in the rebuilt business pod is mounted to the local disk, and the step of generating a directory corresponding to the log on the local disk is returned to be executed.
[0019] Preferably, when collecting logs in the directory according to the configuration file, it also includes:
[0020] Each time a line of content in the log is collected, a mark is made on the corresponding line in the log.
[0021] Preferably, mounting the log corresponding to the type in the business pod to a local disk includes:
[0022] The log corresponding to the type in the business pod is mounted to the local disk through the hostpath mounting method.
[0023] Preferably, generating a directory corresponding to the log on the local disk includes:
[0024] A directory named after the business pod is generated on the local disk through subpathexpr.
[0025] Preferably, after collecting the logs in the directory according to the configuration file, the method further includes:
[0026] Send the collected logs to the message queue.
[0027] A log collection device, applied to a Daemonset pod in a kubernetes cluster, includes:
[0028] The first mounting module is used to obtain the type of each log to be collected in the business pod, and mount the log corresponding to the type in the business pod to the local disk;
[0029] A second mounting module is used to generate a directory corresponding to the log on the local disk, mount the directory into the Daemonset pod, and obtain a path corresponding to the log;
[0030] The log collection module is used to generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file.
[0031] A log collection device, comprising:
[0032] Memory for storing computer programs;
[0033] A processor is used to implement the steps of the log collection method as described in any one of the above when executing the computer program.
[0034] A readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the log collection method described in any one of the above items are implemented.
[0035] The present application provides a log collection method, apparatus, device and readable storage medium, wherein the method is applied to a Daemonset pod in a kubernetes cluster, and includes: obtaining the type of each log to be collected in a business pod, and mounting the log corresponding to the type in the business pod to a local disk; generating a directory corresponding to the log on the local disk, mounting the directory to the Daemonset pod, and obtaining the path corresponding to the log; generating a configuration file according to the path corresponding to the log, and collecting the logs in the directory according to the configuration file.
[0036] The above technical solution disclosed in the present application is as follows: first, the Daemonset pod in the kubernetes cluster obtains the type of log to be collected in the business pod, then mounts the log corresponding to the aforementioned type in the business pod to the local disk, and generates a directory corresponding to the log on the local disk, so as to collect the log with the help of the local disk, and use the local disk to realize the persistence of the log to improve the reliability of log collection. After that, the directory is mounted to the Daemonset pod, and the path corresponding to the log is obtained according to the aforementioned operation of the log, and then, a configuration file is generated according to the path corresponding to the log, and log collection is performed according to the generated configuration file, thereby realizing the collection of different types of logs inside the business pod, and then facilitating a better understanding of the operation status of the cluster and troubleshooting based on the collected multiple types of logs. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0038] Figure 1 A flow chart of a log collection method provided in an embodiment of the present application;
[0039] Figure 2 A schematic diagram of the structure of a log collection device provided in an embodiment of the present application;
[0040] Figure 3 A schematic diagram of the structure of a log collection device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] Currently, in a k8s cluster, fluentbit or fluentd is usually deployed to the Node node of the k8s cluster for log collection. However, it can only collect standard logs in the pod, but cannot collect multiple types of logs in different directories inside the pod.
[0042] To this end, the present application provides a log collection method, apparatus, device and readable storage medium for collecting different types of logs inside a pod.
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] See also Figure 1 , which shows a flow chart of a log collection method provided in an embodiment of the present application. A log collection method provided in an embodiment of the present application is applied to a Daemonset pod in a kubernetes cluster and may include:
[0045] S11: Obtain the type of each log to be collected in the business pod, and mount the log corresponding to the type in the business pod to the local disk.
[0046] First of all, it should be noted that the present application can be applied to the Daemonset pod in the kubernetes cluster, wherein Daemonset is a way of deploying applications within kubernetes, which will automatically run a pod on each Node node, and when a new Node node joins the cluster, no configuration is required, and the new Node node will also automatically run the set process (including the process corresponding to the log collection program), without additional operation, and the Daemonset pod is a pod deployed to the kubernetes cluster through the Daemonset deployment method. Daemonset pod can be used for log collection, that is, the log collection program can be deployed in the Daemonset pod, and the log collection program can be deployed specifically through the k8s Daemonset method, so that when a new Node node joins the cluster later, the process corresponding to the set log collection program can be automatically run without manual intervention, so as to realize the automation of log collection and save labor costs. In addition, it should be noted that in the present application, the log collection program can be deployed specifically in yaml format.
[0047] When collecting logs, the Daemonset pod can first obtain the types of logs to be collected in the business pod in the Node node, where the business pod refers to the pod in the Node node where the application is deployed. The types of logs to be collected can be sent to the Daemonset pod by relevant personnel so that the Daemonset pod can obtain the types of logs to be collected, or the log collection specification can be directly customized when deploying the log collection program so that the Daemonset pod can obtain the types of logs to be collected from the customized log collection specification. In addition, the Daemonset pod can also obtain the names of the logs to be collected at the same time, so that the logs can be mounted based on the names of the logs to be collected later, thereby improving the accuracy of log confirmation and mounting. It should be noted that Daemonset pod can obtain the types of logs to be collected in each business pod in the Node node, that is, only one Daemonset pod needs to be deployed in each Node node to use the Daemonset pod to collect the logs to be collected in all business pods in the Node node where it is located, without running a special log collection container in each business pod to collect logs. Therefore, the resources of the Node node can be saved and the resource occupation of the Node node by log collection can be reduced.
[0048] After the Daemonset pod obtains the types of logs to be collected in the business pod, the logs corresponding to the types of logs to be collected in the business pod can be mounted to the local disk, where the local disk mentioned here is the disk of the Node node where the Daemonset pod and the business pod are located. By mounting the logs corresponding to the types of logs to be collected in the business pod to the local disk, it is convenient to collect logs with the help of the local disk, and the logs corresponding to the types of logs to be collected in the business pod can be persisted to avoid the loss of logs in the directory of the business pod due to the restart of the business pod, thereby improving the reliability of log collection.
[0049] It should be noted that when the type of each log to be collected in the business pod is obtained while the name of each log to be collected is obtained, when the logs corresponding to the type of each log to be collected in the business pod are mounted to the local disk, the corresponding logs in the business pod can be determined according to the type of each log to be collected and the name of each log to be collected, and the determined logs can be mounted to the local disk to improve the accuracy of log determination and mounting, thereby facilitating improving the accuracy of log collection.
[0050] S12: Generate a directory corresponding to the log on the local disk, mount the directory to the Daemonset pod, and obtain the path corresponding to the log.
[0051] After mounting the logs to the local disk, the Daemonset pod can generate a directory corresponding to the logs on the local disk according to the mounting of the logs on the local disk, and can mount the generated directory into the Daemonset pod (specifically, the directory can be mounted into the Daemonset of the log collection program in the Daemonset pod), so that the Daemonset pod can collect logs based on the directory mounted inside itself.
[0052] After mounting the directory to the Daemonset pod itself, the Daemonset pod can automatically detect that a new directory is generated. At this time, the path corresponding to the log can be obtained according to the operations on the log in step S11 and step S12. The path is specifically the mount path of the log.
[0053] S13: Generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file.
[0054] After obtaining the path corresponding to the log, the Daemonset pod can generate a configuration file based on the path corresponding to the log, the log collection rules, the name of the business pod where the log is located, and other information. In this application, the configuration file can be automatically generated in the directory / usr / share / filebeat / data / config / . After that, the Daemonset pod can collect the logs mounted in the directory inside the Daemonset pod according to the configuration file, wherein the filebeat (a lightweight log collector, a log data collector for local files) inside the Daemonset pod can be used to automatically collect logs. Specifically, when filebeat detects the configuration file, it can automatically collect the logs mounted in the directory inside the Daemonset pod according to the configuration file, that is, to realize the collection of each log to be collected in the business pod, that is, to realize the collection of logs in the directory in the business pod. Of course, other log collection tools can also be used to collect logs, and this application does not make any restrictions on this.
[0055] The above technical solution disclosed in the present application is as follows: first, the Daemonset pod in the kubernetes cluster obtains the type of log to be collected in the business pod, then mounts the log corresponding to the aforementioned type in the business pod to the local disk, and generates a directory corresponding to the log on the local disk, so as to collect the log with the help of the local disk, and use the local disk to realize the persistence of the log to improve the reliability of log collection. After that, the directory is mounted to the Daemonset pod, and the path corresponding to the log is obtained according to the aforementioned operation of the log, and then, a configuration file is generated according to the path corresponding to the log, and log collection is performed according to the generated configuration file, thereby realizing the collection of different types of logs inside the business pod, and then facilitating a better understanding of the operation status of the cluster and troubleshooting based on the collected multiple types of logs.
[0056] A log collection method provided in an embodiment of the present application may further include:
[0057] When a business pod is destroyed, it is determined whether the destroyed business pod is currently included in the kubernetes cluster;
[0058] If the destroyed business pod is not currently included in the Kubernetes cluster, obtain the last write time of the log corresponding to the destroyed business pod;
[0059] Determine whether the time difference between the last write time of the log and the current time is greater than the preset value;
[0060] If the time difference between the last write time of the log and the current time is not greater than the preset value, the log is retained;
[0061] If the time difference between the last write time of the log and the current time is greater than the preset value, the log is deleted.
[0062] In this application, when a business pod in a Node node is destroyed, it can be determined whether the destroyed business pod is still included in the kubernetes cluster. If the destroyed business pod is not currently included in the kubernetes cluster, the last write time of the log corresponding to the destroyed business pod is obtained at this time. The last write time of the log mentioned here refers to the time when the log was last updated.
[0063] Determine whether the time difference between the last write time of the log and the current time is greater than a preset value, where the preset value can be 1 day, and of course, it can also be adjusted as needed. If it is determined that the time difference between the last write time of the log and the current time is greater than the preset value, the log is deleted to release the Node node's disk resources, thereby avoiding log residues that occupy too many Node node disk resources, and thus avoiding affecting the log mounting of other normal business pods; if it is determined that the time difference between the last write time of the log and the current time is not greater than the preset value, the log is retained to reserve time for the Daemonset pod to collect the logs corresponding to the destroyed business pod, so that the Daemonset pod can collect the logs corresponding to the destroyed business pod, so as to avoid the loss of these logs due to the excessive log collection pressure of the Daemonset pod.
[0064] A log collection method provided in an embodiment of the present application may further include:
[0065] When a business pod is rebuilt, the logs corresponding to the type in the rebuilt business pod are mounted to the local disk, and the process returns to the step of generating a directory corresponding to the logs on the local disk.
[0066] In the present application, when a business pod in a Node node is rebuilt, the logs corresponding to the type in the rebuilt business pod are mounted to the local disk, and the step of generating a directory corresponding to the log on the local disk is returned to execute. That is, when the Node node contains a business pod that has been rebuilt, the Daemonset pod can re-mount the logs corresponding to the type in the rebuilt business pod to the local disk, rebuild and mount the directories corresponding to these logs to the local disk, re-mount the directories to the Daemonset pod, and regenerate the configuration file to continue log collection to avoid omissions in log collection, thereby improving the reliability of log collection.
[0067] Among them, when there is a new business pod on the Node node, similar steps as last time can be performed, which will not be repeated here.
[0068] A log collection method provided in an embodiment of the present application may further include, when collecting logs in a directory according to a configuration file:
[0069] Each time a line of content in the log is collected, a mark is placed on the corresponding line in the log.
[0070] In the present application, when collecting logs in a directory according to a configuration file, the logs can be collected line by line, and each time a line of content in a log is collected, a mark is made on the corresponding line in the log (specifically, the line where the content has been collected). Specifically, a collection mark can be put at the end of the corresponding line, so that the collection mark can be used to know the specific location of the collected log, and when the business pod is restarted or other reasons cause the log collection to be interrupted, the collection can be continued along the mark in the log without restarting the collection. That is, the breakpoint of log collection can be determined according to the mark, and the log collection can be continued along the breakpoint of log collection, thereby avoiding collecting from the beginning again, so as to improve the efficiency of log collection.
[0071] A log collection method provided in an embodiment of the present application mounts logs corresponding to a type in a business pod to a local disk, which may include:
[0072] Use the hostpath mounting method to mount the logs corresponding to the type in the business pod to the local disk.
[0073] In the present application, when mounting the logs corresponding to the type in the business pod to the local disk, the logs corresponding to the type in the business pod can be mounted to the local disk by hostpath mounting. The hostpath mounting will not disappear due to the removal of the business pod from the Node node. Therefore, you can wait for the Daemonset pod to slowly collect logs to avoid log loss, thereby improving the reliability of log collection.
[0074] A log collection method provided in an embodiment of the present application generates a directory corresponding to the log on a local disk, which may include:
[0075] Generate a directory named after the business pod on the local disk through subpathexpr.
[0076] In this application, when a directory corresponding to the log is generated on the local disk, a directory named after the business pod is generated on the local disk through subpathexpr, where subpathexpr is used to declare variables, that is, to declare the name of the directory. Since this application only needs to obtain the name of the business pod, a directory named after the business pod is generated on the Node node to distinguish which application the log belongs to, without requiring any advanced permissions such as container permissions or server root permissions, it can be completely isolated from the server and only requires k8s-related permissions. Therefore, it will not affect any other applications running on the Node node, so security can be guaranteed and the scope of application of log collection can be improved.
[0077] A log collection method provided in an embodiment of the present application may further include, after collecting logs in a directory according to a configuration file:
[0078] Send the collected logs to the message queue.
[0079] After collecting the logs in the directory according to the configuration file, the collected logs can be sent to the message queue, specifically to Kafka (a high-throughput distributed publish-subscribe message system). Of course, they can also be sent to other message queues to facilitate the application of the collected logs based on the message queue.
[0080] The present application embodiment also provides a log collection device, which is applied to the Daemonset pod in the kubernetes cluster, see Figure 2 , which shows a schematic diagram of the structure of a log collection device provided in an embodiment of the present application, which may include:
[0081] The first mounting module 21 is used to obtain the type of each log to be collected in the business pod, and mount the log corresponding to the type in the business pod to the local disk;
[0082] The second mounting module 22 is used to generate a directory corresponding to the log on the local disk, mount the directory to the Daemonset pod, and obtain the path corresponding to the log;
[0083] The log collection module 23 is used to generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file.
[0084] A log collection device provided in an embodiment of the present application may further include:
[0085] The first judgment module is used to determine whether the destroyed business pod is currently included in the kubernetes cluster when a business pod is destroyed;
[0086] The acquisition module is used to obtain the last write time of the log corresponding to the destroyed business pod if the destroyed business pod is not currently included in the kubernetes cluster;
[0087] The second judgment module is used to judge whether the time difference between the last write time of the log and the current time is greater than a preset value;
[0088] A retention module is used to retain the log if the time difference between the last write time of the log and the current time is not greater than a preset value;
[0089] The deletion module is used to delete the log if the time difference between the last write time of the log and the current time is greater than a preset value.
[0090] A log collection device provided in an embodiment of the present application may further include:
[0091] The third mounting module is used to mount the log corresponding to the type in the rebuilt business pod to the local disk when a business pod is rebuilt, and return to execute the step of generating a directory corresponding to the log on the local disk.
[0092] A log collection device provided in an embodiment of the present application may further include:
[0093] The marking module is used to mark the corresponding line in the log when collecting logs in the directory according to the configuration file.
[0094] In a log collection device provided in an embodiment of the present application, the first mounting module 21 may include:
[0095] The mount unit is used to mount the logs corresponding to the type in the business pod to the local disk through the hostpath mount method.
[0096] In a log collection device provided in an embodiment of the present application, the second mounting module 22 may include:
[0097] The generation unit is used to generate a directory named after the business pod on the local disk through subpathexpr.
[0098] A log collection device provided in an embodiment of the present application may further include:
[0099] The sending module is used to send the collected logs to the message queue after collecting the logs in the directory according to the configuration file.
[0100] The present application also provides a log collection device. Figure 3 , which shows a schematic diagram of the structure of a log collection device provided in an embodiment of the present application, which may include:
[0101] A memory 31, used for storing computer programs;
[0102] The processor 32 can implement the following steps when executing the computer program:
[0103] Get the type of logs to be collected in the business pod, and mount the logs corresponding to the type in the business pod to the local disk; generate a directory corresponding to the log on the local disk, mount the directory to the Daemonset pod, and obtain the path corresponding to the log; generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file.
[0104] The present application also provides a readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the following steps can be implemented:
[0105] Get the type of logs to be collected in the business pod, and mount the logs corresponding to the type in the business pod to the local disk; generate a directory corresponding to the log on the local disk, mount the directory to the Daemonset pod, and obtain the path corresponding to the log; generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file.
[0106] The readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0107] For the description of the relevant parts of a log collection device, equipment, and computer-readable storage medium provided in the present application, reference can be made to the detailed description of the corresponding parts in a log collection method provided in an embodiment of the present application, which will not be repeated here.
[0108] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment that includes a series of elements are inherent to the elements. In the absence of more restrictions, the elements limited by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or equipment that includes the elements. In addition, the above-mentioned technical solution provided in the embodiment of the present application is consistent with the corresponding technical solution in the prior art in principle, and the part is not described in detail, so as not to repeat too much.
[0109] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A log collection method, characterized in that: Daemonset pods used in kubernetes clusters include: The Daemonset pod obtains the type of each log to be collected in each business pod, and mounts the log corresponding to the type in the business pod to the local disk; the business pod refers to the pod in the Node node where the application is deployed; the local disk is the disk of the Node node where the Daemonset pod and the business pod are located; wherein each Node node deploys only one Daemonset pod; Generate a directory corresponding to the log on the local disk, mount the directory into the Daemonsetpod, and obtain a path corresponding to the log; Generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file; The step of generating a configuration file according to a path corresponding to the log, and collecting the logs in the directory according to the configuration file comprises: Generate the configuration file according to the path corresponding to the log, the log collection rule, and the name of the business pod where the log is located; The filebeat inside the Daemonset pod is used to automatically collect logs. When the filebeat detects the configuration file, the logs in the directory mounted inside the Daemonset pod are automatically collected according to the configuration file. When a business pod is destroyed, it is determined whether the destroyed business pod is currently included in the kubernetes cluster; If the destroyed business pod is not currently included in the kubernetes cluster, obtain the last write time of the log corresponding to the destroyed business pod; Determine whether the time difference between the last write time of the log and the current time is greater than a preset value; If the time difference between the last writing time of the log and the current time is not greater than a preset value, retain the log; If the time difference between the last writing time of the log and the current time is greater than a preset value, the log is deleted; When a business pod is rebuilt, the log corresponding to the type in the rebuilt business pod is mounted to the local disk, and the step of generating a directory corresponding to the log on the local disk is returned to be executed.
2. The log collection method according to claim 1, characterized in that: When collecting logs in the directory according to the configuration file, it also includes: Each time a line of content in the log is collected, a mark is made on the corresponding line in the log.
3. The log collection method according to claim 1, characterized in that: Mount the logs corresponding to the type in the business pod to the local disk, including: The log corresponding to the type in the business pod is mounted to the local disk through the hostpath mounting method.
4. The log collection method according to claim 1, characterized in that: Generate a directory corresponding to the log on the local disk, including: A directory named after the business pod is generated on the local disk through subpathexpr.
5. The log collection method according to claim 1, characterized in that: After collecting the logs in the directory according to the configuration file, the method further includes: Send the collected logs to the message queue.
6. A log collection device, characterized in that: Daemonset pods used in kubernetes clusters include: The first mounting module is used for the Daemonset pod to obtain the type of each log to be collected in each business pod, and mount the log corresponding to the type in the business pod to the local disk; the business pod refers to the pod in the Node node where the application is deployed; the local disk is the disk of the Node node where the Daemonset pod and the business pod are located; wherein each Node node deploys only one Daemonset pod; A second mounting module is used to generate a directory corresponding to the log on the local disk, mount the directory into the Daemonset pod, and obtain a path corresponding to the log; A log collection module, used to generate a configuration file according to the path corresponding to the log, and collect the logs in the directory according to the configuration file; wherein the log collection module is specifically used to: generate the configuration file according to the path corresponding to the log, the log collection rule, and the name of the business pod where the log is located; use the filebeat inside the Daemonset pod to automatically collect the logs, and when the filebeat detects the configuration file, automatically collect the logs in the directory mounted inside the Daemonset pod according to the configuration file; The first judgment module is used to determine whether the destroyed business pod is currently included in the kubernetes cluster when a business pod is destroyed; The acquisition module is used to obtain the last write time of the log corresponding to the destroyed business pod if the destroyed business pod is not currently included in the kubernetes cluster; The second judgment module is used to judge whether the time difference between the last write time of the log and the current time is greater than a preset value; A retention module is used to retain the log if the time difference between the last write time of the log and the current time is not greater than a preset value; A deletion module is used to delete a log if the time difference between the last write time of the log and the current time is greater than a preset value; The third mounting module is used to mount the log corresponding to the type in the rebuilt business pod to the local disk when a business pod is rebuilt, and return to execute the step of generating a directory corresponding to the log on the local disk.
7. A log collection device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the log collection method according to any one of claims 1 to 5 when executing the computer program.
8. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the log collection method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Cluster log collection method and system, equipment and medium
CN111258722A