Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person skilled in the art based on the embodiments in the present specification without any inventive step are within the scope of the present application.
In the current application using process, the application is generally based on a large-scale distributed system, wherein a large number of machines are required to collect thousands of log data every day, and due to the maturity of virtualization technology, logs of multiple applications may be collected on one machine at the same time. Currently, there are two general ways to collect logs:
1, a log collection scheduling strategy of first come and first served. The method comprises the steps of providing a queue, sequentially putting files into a scheduling queue according to the sequence of log file changes, scheduling and distributing a log collection processor for execution according to the sequence of the files entering the queue. The files which enter the queue firstly can share the processor resource, so that under the condition of a single thread, once one file is struggled with the processor resource, the file can run all the time until the file is changed and the processing is finished, and when a certain file generates logs rapidly and uninterruptedly, the phenomenon that other log files cannot be acquired and processed and are starved occurs.
And 2, a scheduling strategy of polling by a plurality of independent threads. The method creates a single thread for processing each collected log file object, and in one processing thread, the log file change is polled regularly to collect and process the log files. For example, open source products logstack, fluent and nxlog generally adopt a plurality of independent threads for log collection. When a server needs to collect a large number of log files, a very large number of log analysis processing threads are occupied, a large amount of overhead is caused to an inner core, context switching between threads also has a large influence on program efficiency, and under a scene of log sparsity, most threads are in an idle state, so that the resource utilization rate is low.
Based on this, the present specification provides a log collection scheme, which reads and collects target logs based on a time slice scheduling method, ensures fair collection of all target logs, avoids a phenomenon that a certain target log occupies system resources for a long time, and does not need additional system resource overhead.
Fig. 1 is a schematic flow chart of a log collection method provided in an embodiment of the present specification, which specifically includes the following steps:
s101, sequentially calling a target log acquisition configuration file from a pre-established acquisition configuration file queue, wherein the target log acquisition configuration file comprises a target log identifier and a position to be acquired.
As described above, the target logs to be collected generally have a plurality of target logs, based on which, we use a collection profile queue to control the execution operation of the collected target logs, each target log has a corresponding target log collection profile in the queue, and implement fair collection of the target logs by maintaining the target log collection profiles, as shown in fig. 2, fig. 2 is a schematic diagram of the collection profile queue and the target log collection profiles provided in this embodiment of the present disclosure.
The target log collection configuration file includes at least two parts: target log identification and a position to be collected. The target log id may be a specific target log name, for example, "xx _ app.log", or may be a code number having a correspondence, for example, "1", where "1" points to "xx _ app.log" through a correspondence table. The location to be collected may be a specific location in the target log, for example, beginning with the first letter of line 9 of the target log; it may be a position offset, for example, the offset is "0 x 11" with respect to the starting position of the target log.
It should be noted that, in the queue file, the target log identifiers included in all the target log collection configuration files are unique, and there are no two identical target log identifiers, so that the target logs can be determined in a one-to-one correspondence manner according to the configuration files, or the log collection configuration files can be determined according to the target log identifiers, so as to execute related operations. In addition, when the target log collection configuration files in the queue file are called, the target log collection configuration files are not called in sequence, as long as the probability that each file is called is ensured to be the same, so that fair collection reading of each target log file is realized, and the mode of calling in sequence is simplest under the principle.
S103, aiming at any called target log collection configuration file, executing log collection operation according to the target log identification and the position to be collected contained in the target log collection configuration file within a specified time slice.
Time slices are the time that the system allocates to each process to allow execution. On the basis of the configuration file queue, the log collection processing time is specified (for example, each time slice is set to be 100 milliseconds, that is, the time allowed to be executed for each target log configuration file is 100 milliseconds), and the system sequentially traverses each element in the configuration file queue to perform collection processing on the corresponding target log. And for the target log corresponding to each configuration file in the file queue, each acquisition and processing occupies at most one time slice of the system. If the target log finishes the acquisition processing in advance in a time slice, resources are immediately and actively released, otherwise, the use right of the configuration file for the system resources is deprived after the time slice, and the next ready target log acquisition configuration file is scheduled to start to perform acquisition. In the above-mentioned collection process, the collection position of the target log is given by the position to be collected in the configuration file. The collection operation is generally to read an external target log file to obtain specific content thereof. For the initial position to be collected, an appropriate assignment may be performed according to actual needs when the configuration file is created, for example, it is desirable to set the position to be collected (offset from the starting position of the target log) to "0" for the target log to be collected from the beginning.
According to the scheme, the acquisition configuration files of the target logs to be acquired are established in advance and form a queue, then the configuration files are sequentially called, the target logs are acquired according to the configuration files in a specified time slice, the acquisition is immediately finished when the time length is up, and the positions to be acquired are updated in the configuration files. Then, the next acquisition profile is called and acquisition continues to be performed under the specified time slice. By the scheduling mode based on the time slice, all the configuration files have the opportunity of being scheduled to run, fair acquisition of all the target logs is guaranteed, the phenomenon that a certain target log occupies system resources for a long time is avoided, and extra system resource overhead is not needed.
As a specific implementation manner, for performing the log collection operation according to the target log identifier and the to-be-collected position contained in the time slice specified in S103, the following manner may be adopted: within a specified time slice, starting from the position to be collected, executing collection operation on the target log (namely, the log corresponding to the target log identifier); determining the acquisition interruption position of the acquisition operation when the time slice is finished; and updating the position to be acquired in the target log acquisition configuration file according to the acquisition interruption position so as to continuously acquire the target log from the acquisition interruption position when the target log is called next time.
Specifically, within a time slice, target logs are read, which may be completely read for smaller target logs, and typically only a portion of target logs that have larger variations or that continue to produce log variations. When the time slice length is one, the reading is finished, and the acquisition is interrupted. When the configuration file of the target log is scheduled next time, the reading from the interrupted reading place is required to be continued, so that the interrupted reading position is required to be saved, namely, the position to be read is updated according to the interrupted position. In general, the address or offset of the interrupt location is directly assigned to the location to be read. For example, for the target log, in the reading, the offset is read to be "0 x 01" relative to the starting position, that is, the value is given to the position to be read, so that in the next scheduling, the offset is calculated according to the value of the position to be read, and the reading position is determined. By determining the value of the position to be read according to the interrupt position, the reading of the same target file can be ensured to be continuous and effective, and the reading cannot be repeated.
In addition, as a specific implementation manner, the collecting configuration file for the target log may further include: and processing the state identification. The processing state identification may have two corresponding values for characterizing the target log collection state: characterizing the value to be processed and characterizing the processed value. For example, representing that the acquisition of the target log is completed and the processing is completed by using '0'; and (3) representing that the target log changes and needs to be acquired by using '1', or representing that the acquisition is not complete and needs to be continuously acquired to be processed. It will be readily appreciated that the characterization values herein may be in other forms of representation. It is only necessary that the system can recognize two corresponding values, which may also be, for example, corresponding values such as "T" or "F", "Y" or "N", and so on.
Therefore, the judgment can be carried out in advance according to the characteristic value of the processing state identifier. If the representation value of the processing state identifier in the target log collection configuration file is '0', the file can be skipped quickly without executing operation on the target log, or the target log collection configuration file is deleted, so that the scheduling of other target logs is accelerated. And when the representation value of the processing state identifier in the target log acquisition configuration file is '1', continuously executing acquisition operation on the target log according to the position to be processed. By setting a characteristic value for the target log in the configuration file, the configuration files of the log files which are processed or not processed can be quickly ignored or deleted, so that system resources can be more effectively saved during sequential scheduling, and the reading efficiency is improved.
In practical application, the characteristic value of the processing state identifier in the above scheme may be preset as follows: receiving a target log file change message carrying a target log identifier; inquiring whether a target log acquisition configuration file containing the same target log identification exists in the acquisition configuration file queue, and if so, setting a representation value of a processing state identification in the target log acquisition configuration file containing the same target log identification as a value to be processed; and if the target log is not existed, creating a target log acquisition configuration file containing the target log identifier into the configuration file queue, wherein in the created target log acquisition configuration file, the representation value of the processing state identifier is set as a value representing to-be-processed.
Specifically, the target log file change message only needs to notify which target log has changed, and does not need to notify the content of the specific change. Taking the example that "0" represents processed and "1" represents pending, when the system receives a change message, it will first determine whether the target log id exists in the configuration file queue: if the target log does not exist, a target log collection configuration file is newly built into a file queue, and a state processing identifier is set to be 1; if so, the status process flag of the target log collection profile is set to "1".
In addition, for the characteristic value of the processing state identifier in the above scheme, the characteristic value may be generated as follows: determining whether all the target logs are completely collected within a specified time slice; if yes, setting the representation value of the processing state identifier as a processed representation value; if not, setting the representation value of the processing state identifier as a value representing to-be-processed.
That is, within the time slice, if the current target log processing is finished (that is, all the current logs are collected), the reference count is modified to be "0", otherwise, the count is kept to be "1", and meanwhile, the current processing position is recorded, and the processing is continued when the next scheduling comes. As shown in fig. 3, fig. 3 is a diagram of an example of scheduling processing of a configuration file queue provided in an embodiment of this specification, in this example, a system schedules and finishes reading a target log "3. log" in a time slice, modifies a characteristic value of a processing state identifier of the system from "1" to "0", and continues to schedule a next target log collection configuration file to read the target log "4. log". When the acquisition configuration file of the target log 3.log is read next time, the configuration file of the target log 3 can be ignored or deleted according to the state representation value 0.
After the log is collected, because the scheme provided in the embodiment of the present specification performs discontinuous collection according to the time slice, further classification and archiving of the collected target log information (i.e., specific change content) may be performed according to the target log identifier in the configuration file, and subsequent services such as monitoring or report display may be performed according to the archived content. As shown in fig. 4, fig. 4 is a schematic diagram of an architecture involved in a log collection processing flow provided in an embodiment of the present disclosure.
Based on the same idea, the present invention further provides a log collecting device, as shown in fig. 5, where fig. 5 is a schematic structural diagram of the log collecting device provided in the embodiment of this specification, and the log collecting device includes:
the file transferring module 501 sequentially transfers a target log collection configuration file from a collection configuration file queue established in advance, wherein the target log collection configuration file comprises a target log identifier and a position to be collected;
the acquisition execution module 503 is configured to execute, within a specified time slice, a log acquisition operation according to the target log identifier and the to-be-acquired position included in any of the retrieved target log acquisition configuration files.
Further, the acquisition execution module 503 executes acquisition operation on the target log from the position to be acquired within a specified time slice; determining the acquisition interruption position of the acquisition operation when the time slice is finished; and updating the position to be acquired in the target log acquisition configuration file according to the acquisition interruption position so as to continuously acquire the target log from the acquisition interruption position when the target log is called next time.
Further, the target log collection configuration file further includes: processing the state identifier; the device further comprises a determining module 505, which determines to execute a deleting operation on the target log collection configuration file according to the processed value represented by the processing state identifier; or determining to execute log collection operation on the target log according to the value representing the to-be-processed of the processing state identifier.
Further, the device also comprises a first assignment module 507 for receiving a target log file change message carrying a target log identifier; inquiring whether a target log acquisition configuration file containing the same target log identification exists in the acquisition configuration file queue; if the target log identification exists, setting the representation value of the processing state identification in the target log collection configuration file containing the same target log identification as a value representing to-be-processed; and if the target log is not existed, creating a target log acquisition configuration file containing the target log identifier into the configuration file queue, wherein in the created target log acquisition configuration file, the representation value of the processing state identifier is set as a value representing to-be-processed.
Further, the apparatus further includes a second assignment module 509, which determines whether all the target logs are completely collected within a specified time slice; if yes, setting the representation value of the processing state identifier as a processed representation value; if not, setting the representation value of the processing state identifier as a value representing to-be-processed.
Further, the apparatus further includes a classifying and archiving module 511, which classifies and archives the acquired target log information according to the target log identifier.
Correspondingly, an embodiment of the present application further provides a log collecting device, including:
the memory stores a log acquisition program;
the processor calls the log collection program in the memory and executes:
sequentially calling a target log acquisition configuration file from a pre-established acquisition configuration file queue, wherein the target log acquisition configuration file comprises a target log identifier and a position to be acquired;
and executing log collection operation according to the target log identification and the position to be collected contained in the target log collection configuration file within a specified time slice aiming at any called target log collection configuration file.
Based on the same inventive concept, embodiments of the present application further provide a corresponding non-volatile computer storage medium, in which computer-executable instructions are stored, where the computer-executable instructions are configured to:
sequentially calling a target log acquisition configuration file from a pre-established acquisition configuration file queue, wherein the target log acquisition configuration file comprises a target log identifier and a position to be acquired;
and executing log collection operation according to the target log identification and the position to be collected contained in the target log collection configuration file within a specified time slice aiming at any called target log collection configuration file.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. Especially, as for the device, apparatus and medium type embodiments, since they are basically similar to the method embodiments, the description is simple, and the related points may refer to part of the description of the method embodiments, which is not repeated here.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps or modules recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functions of the units may be implemented in the same software and/or hardware or in one or more pieces of software and/or hardware when implementing the embodiments of the present description.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include transitory computer readable media (transient media) such as modulated data signal numbers and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
Embodiments of the present description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular transactions or implement particular abstract data types. Embodiments of the present description may also be practiced in distributed computing environments where transactions are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.