Log real-time display method, device, computer equipment and medium based on ElasticSearch

By collecting and cutting log data on the log server, and using the index information of ElasticSearch for regular search and display, the problems of log display delay and data loss in the existing technology are solved, and real-time and complete display of log data is achieved.

CN111400378BActive Publication Date: 2024-08-27CHINA PING AN LIFE INSURANCE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202010098102.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-02-18
Publication Date
2024-08-27
Estimated Expiration
2040-02-18

AI Technical Summary

Technical Problem

In the existing technology, the pressure on the display interface is relieved by limiting the calling frequency and the number of bytes, which results in a high delay in displaying log data on the front end and the inability to display large amounts of logs in real time, causing inconvenience to users.

Method used

Adopting a real-time log display method based on ElasticSearch, by collecting log information on the log server and storing it in a preset buffer database, identifying log types for cutting processing, and using index information to search and display log data from the search database at regular intervals. And the position of the last line of log is used as the starting flag for the next search.

Benefits of technology

It realizes the real-time display of log data, avoids display delays and data loss problems caused by limiting the number of bytes and calling frequency, and ensures the timely display of large-volume logs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111400378B
    Figure CN111400378B
Patent Text Reader

Abstract

The present application belongs to the field of data processing, and discloses a real-time log display method, device, computer equipment and readable storage medium based on ElasticSearch. The method includes collecting log information from a log server, and storing the collected log information in a preset buffer database as log buffer data; if the log buffer data is a preset log type, the log buffer data is cut and processed, and the log buffer data after the cutting process is stored as log data to be displayed; when a log viewing request sent by a terminal is received, the log viewing request is parsed and processed to obtain index information; the target display log data is searched from the preset search database at preset time intervals for display, and the position of the last line of log in the target display log data is used as the starting flag of the next search. The method can avoid the technical problems of display delay caused by repeated search or incomplete display caused by missed search.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a real-time log display method, device, computer equipment and storage medium based on ElasticSearch. Background Art

[0002] In the prior art, a two-way connection can be established between the front and back ends, and the logs obtained by the back end can be displayed in real time on the front end. Chinese invention patent CN109783754 discloses a log display method based on web technology, which searches for the required log information from the log information pre-written into the search engine according to the query conditions with the query log sent by the front end, and renders and displays the obtained log information on the front end page. The technical solution disclosed by this Chinese invention patent can put the logs of the back end on the front end for display. However, when the log data is pushed to the front end interface for display, the technical solution will alleviate the display pressure of the display interface by limiting the number of bytes and the calling frequency. This method of alleviating the display pressure of the display interface by calling the frequency will cause the delay of the log data displayed on the front end to be too high, and limiting the number of bytes will cause the logs of large data volumes to be unable to be displayed, which brings great inconvenience to users. Summary of the invention

[0003] Based on this, it is necessary to address the above technical problems. The present application provides a real-time log display method, device, computer equipment and storage medium based on ElasticSearch to solve the technical problems in which the traditional technology of alleviating the display pressure of the display interface by calling the frequency will cause too high a delay in displaying the log data on the front end, and the limitation of the number of bytes will cause large data volumes of logs to be unable to be displayed.

[0004] A log real-time display method based on ElasticSearch, the method comprising:

[0005] Collecting log information from the log server and storing the collected log information in a preset buffer database as log buffer data;

[0006] Identifying a log type of the log buffer data;

[0007] If the log buffer data is of a preset log type, the log buffer data is segmented and stored in a preset search database as log data to be displayed, wherein the preset search database is ElasticSearch;

[0008] When receiving a log viewing request sent by a terminal, parsing the log viewing request to obtain index information of the log data to be displayed;

[0009] The preset search database is searched for log data matching the index information at preset intervals and displayed as target display log data, and the position of the last line of log in the target display log data in the preset search database is used as the starting mark for the next search.

[0010] A log real-time display device based on ElasticSearch, the device comprising:

[0011] The buffer module collects log information from the log server and stores the collected log information in a preset buffer database as log buffer data;

[0012] An identification module, used for identifying the log type of the log buffer data;

[0013] A decomposition module, configured to, if the log buffer data is of a preset log type, perform a segmentation process on the log buffer data, and store the segmented log buffer data in a preset search database as log data to be displayed;

[0014] A query module, configured to parse and process a log viewing request sent by a terminal to obtain index information of the log data to be displayed;

[0015] The display module is used to search the preset search database for log data matching the index information at preset intervals, display them as target display log data, and use the position of the last line of log in the target display log data in the preset search database as the starting flag for the next search.

[0016] A computer device includes a memory and a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned ElasticSearch-based real-time log display method are implemented.

[0017] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned ElasticSearch-based real-time log display method are implemented.

[0018] The above-mentioned real-time log display method, device, computer equipment and storage medium based on ElasticSearch, by storing the collected log information in the preset buffer data for buffer storage, as log buffer data; then the log buffer data is processed respectively according to the type of the log buffer data, if the type of the log buffer data is the preset log type, the log buffer data is cut, matched and processed to obtain the log data with display. Finally, according to the index information of the log viewing request, the target display log data obtained by the search is displayed at intervals, and the position of the last line of log in the log display log data in the preset search database is used as the starting flag of the next search. When the log to be displayed is obtained from the preset search database for display, because the log data in the log file on the log server will increase, but not every moment, there may be new log data that cannot be collected for a period of time, so it is necessary to query the log to be displayed from the preset search database every few seconds, and display the obtained log to be displayed as the target display log, and then obtain the offset corresponding to the last log data in the newly obtained target display log in the preset search database, and use the offset as the starting flag of the next search, so that the next search can be realized from the next log to be displayed at the starting flag. The invention solves the technical problem in the prior art that the log display is realized by limiting the number of bytes and the calling frequency to alleviate the display pressure of the display interface, resulting in the inability to realize the collected log information in real time. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0020] Figure 1 This is a schematic diagram of the application environment of the real-time log display method based on ElasticSearch;

[0021] Figure 2 This is a flowchart of the real-time log display method based on ElasticSearch;

[0022] Figure 3 for Figure 2 Schematic diagram of the process of step 202;

[0023] Figure 4 for Figure 2 Schematic diagram of the process of step 206;

[0024] Figure 5 for Figure 4 Schematic diagram of the process of step 404;

[0025] Figure 6 for Figure 4 Schematic diagram of the process of step 408;

[0026] Figure 7 Another flowchart of the real-time log display method based on ElasticSearch;

[0027] Figure 8 for Figure 2 Schematic diagram of the process of step 210;

[0028] Fig. 9 It is a schematic diagram of a log real-time display method and device based on ElasticSearch;

[0029] Fig.10 FIG. 1 is a schematic diagram of a computer device in one embodiment. DETAILED DESCRIPTION

[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0031] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0032] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0033] The real-time log display method based on ElasticSearch provided in the embodiment of the present invention can be applied to Figure 1 In the application environment shown, the application environment may include a terminal 102, a network 106, and a server 104. The network 106 is used to provide a communication link medium between the terminal 102 and the server 104. The network 106 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0034] The user can use the terminal 102 to interact with the server 104 through the network 106 to receive or send messages, etc. Various communication client applications can be installed on the terminal 102, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0035] Terminal 102 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers and desktop computers, etc.

[0036] The server 104 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal 102 .

[0037] It should be noted that the real-time log display method based on ElasticSearch provided in the embodiment of the present application is generally executed by the server / terminal, and accordingly, the real-time log display device based on ElasticSearch is generally arranged in the server / terminal device.

[0038] It should be understood that Figure 1 The number of terminals, networks and servers in the embodiment is only for illustration. Any number of terminals, networks and servers may be provided according to the implementation requirements.

[0039] Wherein, the terminal 102 communicates with the server 104 through the network. The server 104 obtains log information from the terminal 102, stores it in the preset buffer data for buffer storage, as log buffer data; then the log buffer data is processed according to the type of the log buffer data, and if the type of the log buffer data is the preset log type, the log buffer data is cut, matched, etc. to obtain the display log data. Finally, according to the index information of the log viewing request, the searched target display log data is displayed every section, and the position of the last line of log in the log display log data in the preset search database is used as the starting flag of the next search. Wherein, the terminal 102 and the server 104 are connected through a network, which can be a wired network or a wireless network, and the terminal 102 can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster composed of multiple servers.

[0040] In one embodiment, Figure 2 As shown in the figure, a real-time log display method based on ElasticSearch is provided. Figure 1 The server in the example is used as an example to illustrate, including the following steps:

[0041] Step 202: collect log information from the log server, and store the collected log information in a preset buffer database as log buffer data.

[0042] A log server is a server or server cluster that stores server logs. Log information is the server log, which can be an event log or a message log. Event logs record events that occur during system execution in order to provide tracking information that can be used to understand system activities and diagnose problems. They are essential for understanding the activities of complex systems, especially in applications with less user interaction. Internet Relay Chat (IRC), Instant Messaging (IM) programs, peer-to-peer file clients with chat functions, and multiplayer games usually also have the ability to automatically record (save) text communications. In this case, the text files that are recorded (saved) are usually information logs.

[0043] Message logs are almost universal plain text files, but IM and VoIP clients (which support text chat, such as Skype) can save them in HTML files or in a custom format for easier reading and encryption.

[0044] Collect log information from the log server and store the collected log information in the preset buffer database. The preset buffer database records mainly to ensure that data is not lost and the throughput of massive data. Specifically, data is recorded through Kafka. After Kafka sends a message, it calls back the function. If the message is sent successfully, the next message will be sent. If the message fails, it will be recorded in the log and wait for the scheduled script to scan and then resend to ensure that data is not lost.

[0045] When the amount of log information collected from the log server is too large, directly storing the large amount of collected log information in the preset search database will cause great pressure on the preset search database and cause the database to freeze. Therefore, this embodiment writes the collected data into the preset buffer database in advance to play a buffering role for the collected log data to adapt to the different message requirements of different application scenarios. For example, in a scenario with high requirements for data throughput, the collected massive data can be written into Kafka in advance to avoid directly storing the data in the preset search data and causing the database to freeze.

[0046] Step 204: Identify the log type of the log buffer data.

[0047] The log type can be ACC type, user access logs such as nginx, weblogic_acc, tomcat_acc, application background printing logs such as weblogic, tomcat, and types in developer-defined formats.

[0048] For example: 'weblogic_acc appName, agent Nanning 0.012 17:53:54-GET 675 200 / life / selfhire.getAccountInfo 202.103.238.166'.

[0049] The log type can be identified as follows:

[0050] For example, log information generally includes "NETST_LOG" for firewall configuration records, "CONTENT_LOG" for content filtering server records, "AGENT_LOG" for Java console connections to proxy servers, "USER_LOG" for user authentication server records, "TERM_LOG" for terminal shell records, "kernel" for system kernel records, activity logs executed using Tomcat Manager, etc. Other types of logs include log prefixes or keywords specified by developers. You can identify the type of log by identifying the prefix or keyword in the log information.

[0051] Step 206: If the log buffer data is of a preset log type, the log buffer data is segmented and stored in a preset search database as log data to be displayed, wherein the preset search database is ElasticSearch.

[0052] The preset search database may be ElasticSearch (ES), which is a search server based on a RESTful web interface and built on Apache Lucene. ES puts the log data to be displayed into one or more indexes, and the log data to be displayed can be indexed from ES through different index information, thereby improving search efficiency.

[0053] If the log type of the log buffer data is ACC type nginx, weblogic_acc, tomcat_acc and other user access logs or the log type set by the developer, then the log type of these log buffer data is the preset log type, and these log buffer data need to be cut.

[0054] For example, the log buffer data is: "GET / docs / images / fonts / OpenSans600.woff HTTP / 1.1"20022604, 'weblogic_acc appName agent Nanning 0.012 17:53:54-GET 675 200 / life / selfhire.getAccountInfo 202.103.238.166' or "aaaa bbbb 123 321as312.341". If the above log types are not processed, it will be inconvenient to display the information. This is mainly because it is impossible to search and query similar log information in a targeted manner according to keywords. Slicing the log buffer data means to slice the log information according to the dimension characteristics, and obtain data that can be saved in a list one by one, such as [weblogic_acc, appName, agent, Nanning, 0.012, 17:53:54]. Of course, different storage methods have different storage forms. This is just an example, and it does not limit the format of the log data to be displayed after the slice. For example, in the log type set by the developer, each string or value is separated by a space or other symbol, then the space or symbol can be used to slice the log buffer data.

[0055] The preset search database is similar to a database capable of full-text search. The preset search database establishes more than one indexing method for each log data stored therein, such as establishing an index interface through which newly added log data is added to a specified index as log data to be displayed.

[0056] Step 208: When receiving the log viewing request sent by the terminal, the log viewing request is parsed and processed to obtain index information of the log data to be displayed.

[0057] If a user wants to view a log file, he only needs to specify one or more index information of the log file and send it to the server in the form of a request. The server can then create a log display process based on the index information in the log viewing request to render and display the desired log file on the front end, app, etc.

[0058] Specifically, the index information may be the ID of the log to be viewed, the deviation amount in the log server, the type of log, the name of the log task, and the like.

[0059] The front end passes parameters and wants to display a certain log. To establish a socket long connection, only one request needs to be sent, and the server, such as the back end, searches and queries.

[0060] Step 210, searching the preset search database for log data matching the index information at preset intervals, displaying the log data as target display data, and taking the position of the last line of the target display log data in the preset search database as the starting mark for the next search.

[0061] After the backend queries the data, it returns it to the frontend for display every 5 or 10 seconds. The backend also records the index information of each query.

[0062] The byte limit in the prior art causes the large amount of data logs to be unable to be displayed in real time on the front end. The purpose of timing is to remove the byte limit, because the log information is not generated once, and new log information will be generated more or less in most time periods. After the new log information is collected, it will eventually be stored in a preset search database.

[0063] The server can query the last marked log data from ES at preset intervals to ensure that the content of the queried log data is not lost or repeated, and then display the log data obtained from the query as the target display log data. Then the position of the last line of log in the log display log data in ES, that is, the offset, is obtained as the starting flag for the next search. When the log data is searched for the next time, the search for log data can be started from the next offset of the starting flag, ensuring that the searched log data will not be repeated, because the offset is a unique identifier of the log data that is automatically generated when the log data is stored in ES and cannot be changed, so there will be no search omissions.

[0064] In the above-mentioned real-time log display method based on ElasticSearch, the collected log information is stored in the preset buffer data for buffer storage as log buffer data; then the log buffer data is processed according to the type of the log buffer data, and if the type of the log buffer data is the preset log type, the log buffer data is cut, matched, etc. to obtain the log data with display. Finally, according to the index information of the log viewing request, the target display log data obtained by the search is displayed at intervals, and the position of the last line of log in the log display log data in the preset search database is used as the starting flag of the next search. When the log to be displayed is obtained from the preset search database for display, because the log data in the log file on the log server will increase, but not every moment, there may be new log data that cannot be collected for a period of time, so it is necessary to query the log to be displayed from the preset search database every few seconds, and display the obtained log to be displayed as the target display log, and then obtain the offset corresponding to the last log data in the newly obtained target display log in the preset search database, and use the offset as the starting flag of the next search, so that the next search can be realized from the next log to be displayed at the starting flag. The invention solves the technical problem in the prior art that the log display is realized by limiting the number of bytes and the calling frequency to alleviate the display pressure of the display interface, resulting in the inability to realize the collected log information in real time.

[0065] In one embodiment, Figure 3 As shown, step 202 includes:

[0066] Step 302: Detect the specified log file in the log server.

[0067] There are many kinds of log information stored in the log file, and there are multiple log files storing log information in the log server. Not all log information in the log files is the target of real-time display, so the server needs to specify the log files on the log server for collection.

[0068] Step 304: Send the log information in the detected log file to the preset buffer database as the log buffer data.

[0069] Read the log information in the log file and send the read log information to ES for buffer storage as log buffer data. Because the log information in the log file may be updated in real time, it is necessary to detect the updated log according to the preset conditions (for example, every 5 seconds) and send the detected log to the preset buffer data as log buffer data.

[0070] Specifically, the server also needs to detect the size change of the log file in real time. If the size of the log file changes, it means that the log information in the log file has been updated, such as adding new log information, but generally there will be no situation where the log server deletes a log information in the log file. However, the log server may periodically clean up the log information in the log file and clean up the cache. At this time, the collection of log information is suspended. When the collection is restarted, a new process can be opened for processing.

[0071] If the size of the log file changes, the offset of the log information in the last collected log file can be obtained, and the log information after the offset can be read, and the read log information can be stored in the preset buffer database as log buffer data.

[0072] This embodiment detects the size of the log file at regular intervals and collects new added log information from the log server according to the offset of the log information, thereby achieving the purpose of timely collecting the newly added log information and avoiding untimely log display.

[0073] In one embodiment, Figure 4 As shown, step 206 includes:

[0074] Step 402, obtaining a preset cutting mark.

[0075] The preset cutting mark may be a character without specific meaning in the log buffer data, such as “;”, “|”, etc.

[0076] Step 404: locate the coordinates of the preset cutting mark in the log buffer data as the cutting coordinates.

[0077] In the log buffer data, each two characters are usually separated by a symbol, such as "\t" to separate two characters to prevent character adhesion. When the preset cutting mark is "\t", locate the position of "\t" in the log buffer data, generally obtain the subscript of the preset cutting mark in the log buffer data, such as list[1], list[3], list[5], etc., and then use these subscripts as cutting coordinates.

[0078] Step 406, cutting the log buffer data according to the cutting coordinates to obtain the fields to be parsed.

[0079] The log buffer data is cut according to the obtained cutting coordinates to obtain a sequence of strings. Specifically, if a line of log data with "|" as the preset cutting mark is randomly input, for example:

[0080] "123|000|ttter|sdfds*=123|dfwe", the output data after cutting is:

[0081] [123,000,ttter,sdfds*=123,dfwe], the characters in the list are the fields to be parsed.

[0082] Step 408: Match the to-be-analyzed field with the parsed field according to the preset matching condition to obtain a structured log, and store the structured log in a preset search database.

[0083] If we cut the log buffer data according to \t, we get:

[0084] [Elife-meb, / wls / applog / …… / DMZ120012.acc, weblog_acc, wangxiao] these four fields.

[0085] Then, according to the preset matching conditions, a field matching operation is performed for each field to be parsed after the cutting, so that each field to be parsed can be matched with a parsed field, and then the data obtained after the field matching is stored as a structured log in the preset search database.

[0086] for example:

[0087] The four parsing fields of system_name, source, type, and appname can be matched with the four fields obtained by the above cutting according to the preset matching conditions. Among them, the preset matching conditions can be to obtain the subscript of the value, string or symbol in each field to be parsed, and then compare it with the subscript of the value, string or symbol in the parsing field. If the two subscripts are consistent, the field is assigned to the parsing field, and the data obtained after the assignment is written into ES as a structured log. Among them, the parsing field is obtained according to the log type of the log buffer data. For example, if the log buffer data is log data customized by the developer, it is impossible to know what the value or string in the log data means, but there will generally be a parsing field in the form of a list generated according to the order of each value or string in the log data. The order of the values ​​or strings in the parsing field generally corresponds to the order of the values ​​or strings in the field to be parsed.

[0088] Optionally, the data format written to ES is:

[0089] system_name: Elife-meb

[0090] source: / wls / applog / …… / DMZ120012.acc

[0091] This format can be stored in ES for easy searching, for example:

[0092] Character matching: method:"POST"

[0093] Field value fuzzy matching: source:*access*

[0094] Field value range: status:[400TO 500] or status:>400

[0095] Simple regular expression: instance_name: / ng-elis-[az]{3}-alsDMZ[0-9]{5} /

[0096] Of course, the above query methods can also be combined arbitrarily:

[0097] message

[0098] message:"information" AND(NOT type:"tomcat_acc")

[0099] source

[0100] source:*access*AND byte:>50AND clientip: / 223.104.176.[0-7]{3} /

[0101] }

[0102] You can also perform aggregate queries through ES, such as querying the acctime values ​​of the top ten requesturls within 1 hour on a certain system server. Of course, you can also configure alerts based on queries:

[0103] In this embodiment, the log buffer data is segmented by a preset segmentation identifier, and then matched with the parsed field to obtain structured data and store it in ES, thereby improving the convenience of data search.

[0104] In one embodiment, Figure 5 As shown, step 404 includes:

[0105] Step 502: The occurrence frequency of each character string in the preset number of lines of log buffer data is used as a frequency array, and the variance of the frequency array is calculated.

[0106] You can first select a certain type of log data from the collected log buffer data to obtain the cutting coordinates. Specifically, you can select 10 lines of log data customized by the developer, treat each string, value or symbol as a string, and then get the frequency of each string in each of the 10 lines of log data. List an array like (10,10,9,8,10,11,10,9,9,10) as the frequency array, and then calculate the variance of the frequency array.

[0107] Step 504: if the variance of the frequency group is less than a specific value, the character string is used as a preset cutting mark, and the coordinates of the preset cutting mark in the log buffer data are located as cutting coordinates.

[0108] If the obtained variance is less than a specific value, the string is used as a preset cutting mark, and the coordinates of the preset cutting mark in the log buffer data are located, such as list[1], list[3], list[5] as the cutting coordinates.

[0109] In this embodiment, the preset cutting mark is determined by calculating the frequency of occurrence of the character string, numerical value or symbol in the log buffer data, thereby increasing the accuracy of cutting the log buffer data.

[0110] In one embodiment, Figure 6 As shown, step 408 includes:

[0111] Step 602: Get the field subscripts of the to-be-parsed field and the parsed field. The field subscripts of the to-be-parsed field can be the subscripts of each string, value, or symbol in the to-be-parsed field: list[0], list[2], list[4]..., and the field subscripts of the parsed field can also be the subscripts of each string, value, or symbol in the to-be-parsed field: list[0], list[2], list[4]...

[0112] Step 604: If the field subscript of the field to be parsed is consistent with the field subscript of the parsing field, the field to be parsed is assigned to the parsing field for matching to obtain a structured log.

[0113] If the subscript list[0] of a string in the field to be parsed is consistent with the subscript list[0] of a string in the parsing field, the string in the field to be parsed can be assigned to the string in the parsing field to obtain structured data, and store it in ES as a log to be displayed.

[0114] Through this embodiment, the to-be-parsed fields whose meanings could not be directly known can be parsed, and each to-be-parsed field is matched with a corresponding parsed field, so that structured data is generated for easy storage and query.

[0115] In one embodiment, Figure 7 As shown, after step 204 and before step 208, the following further includes:

[0116] Step 702, if the log buffer data is not a preset log type, the log buffer data is stored in a preset search database as log data to be displayed. Of course, there are some log types of log buffer data that can be stored in ES without structural processing for subsequent query.

[0117] Non-preset log types can be: logs printed by application backgrounds such as weblogic and tomcat. Non-preset log types are data types that do not require message segmentation. For example, error messages printed by the program background have no regularity and cannot be segmented. Therefore, users only need to be able to see this information without segmenting it.

[0118] This embodiment saves processing memory and improves the processing efficiency of log data of the preset log type by directly saving the log buffer data that does not conform to the preset log type in the ES.

[0119] In one embodiment, Figure 8 As shown, step 210 includes:

[0120] Step 802: Obtain the offset corresponding to the last log to be displayed in the target display log in the preset search data.

[0121] The offset may be the log position of each log message / line in the preset search database. The preset search database generates an offset for each newly stored log data as one of the unique identifiers of each log data. The offset may be an ID generated by the preset search database for the log data.

[0122] Step 804: Use the offset as the starting flag for the next search in the preset search database, wherein the last log to be displayed is the log obtained by the last search in this search.

[0123] When obtaining the log to be displayed from the preset search database for display, because the log data in the log file on the log server will increase, but not every moment, and new log data may not be collected for a period of time, it is necessary to query the log to be displayed from the preset search database every few seconds, and display the obtained log to be displayed as the target display log, and then obtain the offset corresponding to the last log data in the newly obtained target display log in the preset search database, and use the offset as the starting flag for the next search, so as to realize the next search from the next log to be displayed from the starting flag.

[0124] This embodiment can avoid the technical problems of display delay caused by repeated searches or incomplete display caused by missed searches.

[0125] It should be understood that although Figure 2-Figure 8 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-Figure 8 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages do not necessarily have to be executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages does not have to be sequentially, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0126] In one embodiment, Fig. 9As shown, a real-time log display device based on ElasticSearch is provided, and the real-time log display device based on ElasticSearch corresponds to the real-time log display method based on ElasticSearch in the above embodiment. The real-time log display device based on ElasticSearch includes:

[0127] The buffer module 902 is used to collect log information from the log server and store the collected log information in a preset buffer database as log buffer data.

[0128] The identification module 904 is used to identify the log type of the log buffer data.

[0129] The decomposition module 906 is used to perform segmentation processing on the log buffer data if the log buffer data is of a preset log type, and store the segmented log buffer data in a preset search database as log data to be displayed, wherein the preset search database is ElasticSearch.

[0130] The query module 908 is used to parse and process the log viewing request sent by the terminal when receiving the log viewing request, and obtain index information of the log data to be displayed.

[0131] Display module 910 is used to search for log data matching the index information from a preset search database at preset intervals, display it as target display log data, and use the position of the last line of the target display log data in the preset search database as the starting flag for the next search.

[0132] Furthermore, after the identification module 904 and before the query module 908, the following is further included:

[0133] The storage module 912 is used to store the log buffer data in a preset search database as log data to be displayed if the log buffer data is not of the preset log type.

[0134] Furthermore, the buffer module 902 includes:

[0135] The detection submodule is used to detect the specified log file in the log server.

[0136] The cache submodule is used to send the log information in the detected log file to a preset buffer database as log buffer data.

[0137] Furthermore, the decomposition module 906 includes:

[0138] The mark acquisition submodule is used to obtain the preset cutting mark.

[0139] The mark positioning submodule is used to locate the coordinates of the preset cutting mark in the log buffer data as the cutting coordinates.

[0140] The data cutting submodule is used to cut the log buffer data according to the cutting coordinates to obtain the fields to be parsed.

[0141] The data parsing submodule is used to match the parsing field with the to-be-parsed field according to the preset matching condition, obtain the structured log, and store the structured log in the preset search database.

[0142] Furthermore, the identification and positioning submodule includes:

[0143] The frequency calculation unit is used to take the occurrence frequency of each string in the log buffer data of a preset number of lines as a frequency array, and calculate the variance of the frequency array.

[0144] The identification confirmation unit is used to use the character string as a preset cutting identification if the variance of the frequency group is less than a specific value, and locate the coordinates of the preset cutting identification in the log buffer data as cutting coordinates.

[0145] Furthermore, the data parsing submodule includes:

[0146] The subscript unit is used to obtain the field subscripts of the to-be-parsed field and the parsed field.

[0147] The assignment unit is used to assign the field to be parsed to the parsing field for matching if the field subscript of the field to be parsed is consistent with the field subscript of the parsing field, so as to obtain a structured log.

[0148] Furthermore, the display module 910 includes:

[0149] The offset submodule is used to obtain the offset corresponding to the last log to be displayed in the target display log in the preset search data.

[0150] The marking submodule is used to use the offset as the starting flag for the next search in the preset search database, wherein the last log to be displayed is the log obtained by the last search in this search.

[0151] The above-mentioned real-time log display device based on ElasticSearch stores the collected log information in the preset buffer data for buffer storage as log buffer data; then processes the log buffer data according to the type of the log buffer data, and if the type of the log buffer data is the preset log type, the log buffer data is cut, matched, and processed to obtain the displayed log data. Finally, according to the index information of the log viewing request, the searched target display log data is displayed at intervals, and the position of the last line of log in the log display log data in the preset search database is used as the starting flag of the next search. The technical problem that the collected log information cannot be realized in real time by limiting the number of bytes and the calling frequency to alleviate the display pressure of the display interface in the prior art is solved.

[0152] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store user order data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a real-time log display method based on ElasticSearch is implemented.

[0153] Among them, technicians in this technical field can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0154] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0155] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the real-time log display method based on ElasticSearch in the above embodiment are implemented, for example: Figure 2 Steps 202 to 210 shown, or when the processor executes the computer program, the functions of each module / unit of the real-time log display device based on ElasticSearch in the above-mentioned embodiment are realized, for example Fig. 9 The functions of modules 902 to 910 are shown in Figure 9. To avoid repetition, they are not described here again.

[0156] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the real-time log display method based on ElasticSearch in the above embodiment are implemented, for example: Figure 2 Steps 202 to 210 shown, or when the processor executes the computer program, the functions of each module / unit of the real-time log display device based on ElasticSearch in the above-mentioned embodiment are realized, for example Fig. 9 The functions of modules 902 to 910 are shown in Figure 9. To avoid repetition, they are not described here again.

[0157] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0158] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0159] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0160] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for those of ordinary skill in the art, without departing from the concept of the present application, several modifications, improvements or equivalent replacements of some technical features can be made, and these modifications or replacements do not make the essence of the same technical solution depart from the spirit and scope of the technical solution of each embodiment of the present invention, and all belong to the protection scope of the present application. Therefore, the protection scope of the patent of this application shall be subject to the attached claims.

Claims

1. A real-time log display method based on ElasticSearch, characterized in that: include: Collecting log information from the log server and storing the collected log information in a preset buffer database as log buffer data; Identifying a log type of the log buffer data; If the log buffer data is of a preset log type, the log buffer data is segmented and stored in a preset search database as log data to be displayed, wherein the preset search database is ElasticSearch; When receiving a log viewing request sent by a terminal, parsing the log viewing request to obtain index information of the log data to be displayed; Searching the preset search database for log data matching the index information at preset intervals, displaying the log data as target display log data, and taking the position of the last line of the target display log data in the preset search database as the starting mark for the next search; The cutting process of the log buffer data and storing the cut log buffer data in a preset search database includes: Get the preset cutting mark; Locate the coordinates of the preset cutting mark in the log buffer data as cutting coordinates; Cut the log buffer data according to the cutting coordinates to obtain fields to be parsed; Matching the to-be-parsed field with the parsed field according to a preset matching condition to obtain a structured log, and storing the structured log in the preset search database; The step of locating the coordinates of the preset cutting mark in the log buffer data as cutting coordinates includes: Taking the occurrence frequency of each character string in the log buffer data of a preset number of lines as a frequency array, and calculating the variance of the frequency array; If the variance of the frequency group is less than a specific value, the character string is used as the preset cutting mark, and the coordinates of the preset cutting mark in the log buffer data are located as the cutting coordinates; The step of matching the to-be-parsed field with the parsed field according to the preset matching condition to obtain a structured log includes: Obtain the field subscripts of the field to be parsed and the parsed field; If the field subscript of the field to be parsed is consistent with the field subscript of the parsing field, the field to be parsed is assigned to the parsing field for matching to obtain the structured log.

2. The method according to claim 1, characterized in that: The step of collecting log information from the log server and storing the collected log information in a preset buffer database as log buffer data includes: Detect the specified log file in the log server; The log information in the detected log file is sent to the preset buffer database as the log buffer data.

3. The method according to claim 1, characterized in that After identifying the log type of the log buffer data, upon receiving a log viewing request sent by a terminal, parsing the log viewing request, and before obtaining the index information of the log data to be displayed, the method further includes: If the log buffer data is not of the preset log type, the log buffer data is stored in the preset search database as the log data to be displayed.

4. The method according to claim 1, characterized in that: The step of using the position of the last line of the target display log data to be displayed in the preset search database as the starting flag of the next search includes: Obtaining the offset corresponding to the last log to be displayed in the target display log in the preset search data; The offset is used as a starting flag for the next search in the preset search database, wherein the last log to be displayed is the log obtained by the last search in this search.

5. A real-time log display device based on ElasticSearch, characterized in that: The real-time log display device based on ElasticSearch implements the steps of the method described in any one of claims 1 to 4, and the real-time log display device based on ElasticSearch includes: The buffer module collects log information from the log server and stores the collected log information in a preset buffer database as log buffer data; An identification module, used for identifying the log type of the log buffer data; A decomposition module, for, if the log buffer data is of a preset log type, performing a segmentation process on the log buffer data, and storing the segmented log buffer data in a preset search database as log data to be displayed, wherein the preset search database is ElasticSearch; A query module, configured to parse and process a log viewing request sent by a terminal to obtain index information of the log data to be displayed; The display module is used to search the preset search database for log data matching the index information at preset intervals, display them as target display log data, and use the position of the last line of log in the target display log data in the preset search database as the starting flag for the next search.

6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • A log display method and system realized based on a WEB technology

    CN109783754A

  • Log file processing method and device, computer device and storage medium

    CN109324996A

  • Log analysis method and device

    CN109325009A

  • Log management method and device, computer device and computer readable storage medium

    CN109977089A

  • Log data processing method and device, terminal and storage medium

    CN110347716A