CN115905110A - Log file dynamic cleaning method and device and computer equipment - Google Patents

Log file dynamic cleaning method and device and computer equipment Download PDF

Info

Publication number
CN115905110A
CN115905110A CN202211355694.1A CN202211355694A CN115905110A CN 115905110 A CN115905110 A CN 115905110A CN 202211355694 A CN202211355694 A CN 202211355694A CN 115905110 A CN115905110 A CN 115905110A
Authority
CN
China
Prior art keywords
log file
target service
cleaning
log
storage
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211355694.1A
Other languages
Chinese (zh)
Inventor
王栋梁
韩一曼
王春燕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202211355694.1A priority Critical patent/CN115905110A/en
Publication of CN115905110A publication Critical patent/CN115905110A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The method comprises the steps of obtaining a target service of a log file to be cleaned and the current running state of the target service; judging whether the current state of the target service is a running state or not; if yes, judging whether the log file of the target service is in an executed state or not; if yes, the log file is reserved; if not, cleaning the log file according to the size and the storage time length of the log file; and if the current state of the target service is a non-running state, cleaning all log files of the target service. The method provided by the text determines the target service of the job to be cleaned according to the configuration file, and then executes different cleaning operations on the log file according to the state of the target service and the state of the log file; the release of the storage space is realized, and the storage pressure of the storage space is greatly reduced; meanwhile, the mistaken deletion of the log file is avoided.

Description

Log file dynamic cleaning method and device and computer equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for dynamically cleaning log files, and a computer device.
Background
The application service can generate a large amount of work logs in daily test and running work, and the work logs are used for recording information such as test and running states, debugging and execution results of the application service. The log files are usually stored in the disk, the log files are produced quickly, and the disk space is often exploded in two or three days, so that the normal operation of the service is influenced. So that the log file needs to be cleaned up.
An existing method for cleaning log files is as follows: when the disk space is tense or after the disk space is used, the log file is manually cleared by maintenance personnel. The method ensures that the disk space is in a tense state for a long time, and the utilization rate of the disk space is reduced; moreover, the log files need to be checked by a user, and the risk of mistaken deletion of some log files which need to be checked exists while the work efficiency is low. The other method is as follows: recording the storage allowance of the disk to the log files and the space occupied by each log file stored in the disk, and deleting one or more log files occupying larger space according to the size of each log file when the storage allowance is smaller than a certain threshold value. Although the method can avoid that the disk space is in a tense state for a long time, the risk of mistaken deletion also exists, and the corresponding log file is lacked when the related information needs to be checked in the later period.
In view of the above, the present disclosure aims to provide a method, an apparatus and a computer device for dynamically cleaning log files.
Disclosure of Invention
In view of the foregoing problems in the prior art, an object of the present disclosure is to provide a method and an apparatus for dynamically cleaning a log file, and a computer device, so as to solve the problem in the prior art that it is difficult to consider both efficiency and accuracy when cleaning the log file.
In order to solve the technical problems, the specific technical scheme is as follows:
in a first aspect, a method for dynamically cleaning log files is provided, including:
acquiring a target service of a log file to be cleaned and a current running state of the target service;
judging whether the current state of the target service is a running state or not;
if the current state of the target service is the running state, judging whether the log file of the target service is an executed state or not;
if yes, the log file is reserved;
if not, acquiring the size and the storage duration of the target service log file so as to clean the log file according to the size and the storage duration of the log file;
and if the current state of the target service is a non-running state, cleaning all log files of the target service.
Specifically, the obtaining of the size and the storage duration of the target service log file to clean the log file according to the size and the storage duration of the log file includes:
judging whether the size of the log file is larger than a first threshold value or not;
if the size of the log file is larger than the first threshold, judging whether the storage time length of the log file is larger than a preset first time length threshold or not;
and if the storage time of the log file is longer than the first time threshold, cleaning the log file.
Further, the method further comprises:
if the size of the log file is smaller than or equal to the first threshold, judging whether the size of the log file is larger than a second threshold, wherein the second threshold is smaller than the first threshold;
if the size of the log file is larger than the second threshold, judging whether the storage time length of the log file is larger than a preset second time length threshold, wherein the second time length threshold is larger than the first time length threshold;
and if the storage time of the log file is greater than the second time threshold, cleaning the log file.
Still further, the method further comprises:
if the size of the file is smaller than the second threshold, judging whether the storage time length of the log file is larger than a preset third time length threshold, wherein the third time length threshold is larger than the second time length threshold;
and if the storage time of the log file is greater than the third time threshold, cleaning the log file.
Specifically, the obtaining of the size and the storage duration of the target service log file to clean the log file according to the size and the storage duration of the log file further includes:
calculating to obtain a cleaning coefficient of the log file according to the current running state of the target service and the size and storage duration of the log file;
comparing the cleaning coefficient with a preset cleaning coefficient threshold value;
and when the cleaning coefficient is less than or equal to the cleaning coefficient, cleaning the log file.
Preferably, the cleaning coefficient is calculated by the following formula:
Figure BDA0003921075260000031
wherein R is the cleaning coefficient of each log file; s is the current running state of the target service corresponding to each log file, when the target service is in a running state, the value of S is 1, and when the target service is in a non-running state, the value of S is 0; v is the size of each log file, h is a first threshold, and in this specification, the value of h may be 30; l is a second threshold value, and the value of l can take 20; ti is the generation time of each log file, and T is the current time node.
Specifically, when the current state of the target service is a running state and the log file of the target service is not in an executed state, the method further includes:
acquiring the type of the target service log file, wherein the type of the log file at least comprises an error report log, a reminding log, an information log and a debugging log;
and clearing the log file according to the size, the storage time and the type of the log file.
Preferably, before determining whether the current state of the target service is a running state, the method further includes:
acquiring a storage path of the target service log file;
and judging whether the log file of the target service reaches a condition for triggering cleaning according to the storage path.
Further, the determining, according to the storage path, whether the log file of the target service meets a condition for triggering cleaning includes:
acquiring a total storage space and a used storage space corresponding to the storage path;
and when the ratio of the used storage space to the total storage space is greater than or equal to a preset occupancy rate, determining that the log file of the target service reaches a condition of triggering cleaning.
In a second aspect, provided herein is an apparatus for dynamically cleaning log files, the apparatus comprising:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a target service of a log file to be cleaned and the current running state of the target service;
the first judgment module is used for judging whether the current state of the target service is an operation state or not;
the second judging module is used for judging whether the log file of the target service is in an executed state or not when the current state of the target service is in an operating state;
the reservation module is used for reserving the log file when the log file is in an executed state;
the first cleaning module is used for acquiring the size and the storage duration of the target service log file when the log file is not in the executed state so as to clean the log file according to the size and the storage duration of the log file;
and the second cleaning module is used for cleaning all log files of the target service when the current state of the target service is a non-running state.
In a third aspect, a computer device is provided herein, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the method provided in the above technical solution is implemented.
In a fourth aspect, a computer-readable storage medium is provided herein, which stores a computer program, which when executed by a processor implements the method provided in the above technical solution.
In a fifth aspect, this document also provides a computer program product comprising at least one instruction or at least one program, which is loaded and executed by a processor to implement the method as provided in the above technical solution.
By adopting the technical scheme, the method, the device and the computer equipment for dynamically cleaning the log file, provided by the invention, firstly determine the target service of the job to be cleaned according to the configuration file, secondly judge whether the target service is in the running state and whether the log file of the target service is in the executed state, and select different cleaning strategies for the log file according to different states of the target service and the log file: when the target service is in a non-running state, cleaning all log files of the target service; when the target service is in a running state and a log file of the target service is in an executed state, the log file is reserved; when the target service is in a running state and the log file of the target service is not in an executed state, selectively cleaning at least part of the log file based on the size and the storage duration of the log file; the release of the storage space is realized, and the storage pressure of the storage space is greatly reduced; meanwhile, the mistaken deletion of the log file is avoided.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments or technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating steps of a method for dynamically cleaning a log file according to an embodiment of the present disclosure;
FIG. 2 is a schematic diagram illustrating a first step of cleaning a log file provided by an embodiment herein;
FIG. 3 is a diagram illustrating a second step of cleaning a log file provided by an embodiment herein;
FIG. 4 is a schematic diagram illustrating steps in an embodiment herein for determining whether a log file of a target service meets a trigger clean-up condition;
fig. 5 shows a schematic structural diagram of a log file dynamic cleaning apparatus provided in an embodiment of the present disclosure;
fig. 6 shows a schematic structural diagram of a computer device provided in an embodiment herein.
Description of the symbols of the drawings:
51. an acquisition module;
52. a first judgment module;
53. a second judgment module;
54. a reservation module;
55. a first cleaning module;
56. a second cleaning module;
602. a computer device;
604. a processor;
606. a memory;
608. a drive mechanism;
610. an input/output module;
612. an input device;
614. an output device;
616. a presentation device;
618. a graphical user interface;
620. a network interface;
622. a communication link;
624. a communication bus.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below clearly and completely with reference to the drawings in the embodiments of the present invention, and it is obvious that the embodiments described are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments herein without making any creative effort, shall fall within the scope of protection.
It should be noted that the terms "first," "second," and the like in the description and claims herein and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments herein described are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, apparatus, article, or device that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or device.
An existing method for cleaning log files is as follows: when the disk space is tense or used, the log file is manually cleared by maintenance personnel. The method can lead the disk storage space to be in a tense state for a long time, and the utilization rate of the disk space is reduced; and because the manual processing of maintenance personnel is needed, the working efficiency is low, and the risk of mistakenly deleting the log file exists. The other cleaning method comprises the following steps: recording the storage allowance of the disk to the log files and the space occupied by each log file stored in the disk, and deleting one or more log files occupying larger space according to the size of each log file when the storage allowance is smaller than a certain threshold value. Although the method can avoid the situation that the disk space is in a tense state for a long time, the deletion is carried out one by one according to the size of each log file, so that the risk of mistaken deletion also exists.
In order to solve the above problems, embodiments herein provide a log file dynamic cleaning method, and it should be noted that the log file dynamic cleaning method, apparatus, and computer device provided herein may be used in the financial field, and may also be used in any other field except the financial field. Fig. 1 is a schematic diagram of steps of a log file dynamic cleaning method provided in an embodiment of the present disclosure, and this specification provides method operation steps as described in an embodiment or a flowchart, but more or fewer operation steps may be included based on conventional or non-inventive labor. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. In the actual implementation of the system or the device product, the method according to the embodiments or shown in the drawings can be executed in sequence or in parallel. Specifically, as shown in fig. 1, the method may include:
s110: the method comprises the steps of obtaining a target service of a log file to be cleaned and the current running state of the target service.
The target service to be cleaned may have one or more target services, and the storage paths of the log files of the one or more target services may be the same or different; the target service to be cleaned and the storage path of the log file thereof can be read from a pre-written configuration file. Therefore, the log file of the target service can be subjected to refined cleaning operation according to the configuration file.
S120: and judging whether the current state of the target service is an operating state or not.
The current running state of the target service can be obtained through a special linux instruction query.
S130: and if the current state of the target service is the running state, judging whether the log file of the target service is the executed state or not.
I.e., whether the log file is being written to or read from.
S140: if yes, the log file is reserved.
S150: and if not, acquiring the size and the storage duration of the target service log file so as to clear the log file according to the size and the storage duration of the log file.
The log file of the target service can be used to trace back the target service to analyze and locate possible problems of the target service. When a target service is in a running state, the target service may be currently generating a log file. When the log file is in the executed state, the log file may be currently executed with writing or reading operations, and the log file should be retained at this time, so as to avoid the failure of the writing or reading operations of the log file caused by cleaning operations; when the log file is not in the executed state, a certain cleaning operation may be performed, and specifically, the method provided in this specification is to selectively clean the log file according to the size and the storage duration of the log file. The storage duration of the log file refers to a period of time from the generation time of the log file to the current timestamp. When a certain target service is currently in a non-running state, it can be considered that the analysis backtracking operation of the target service is finished through the corresponding log file, so that all the log files can be cleaned.
S160: and if the current state of the target service is a non-running state, cleaning all log files of the target service.
In a method for dynamically cleaning a log file provided in an embodiment of the present specification, a target service of a job to be cleaned is determined according to a configuration file, and then it is determined whether the target service is in an operating state and whether a log file of the target service is in an executed state, so as to select different cleaning policies for the log file according to different states of the target service and different states of the log file: when the target service is in a non-running state, cleaning all log files of the target service; when the target service is in a running state and a log file of the target service is in an executed state, the log file is reserved; when the target service is in a running state and the log file of the target service is not in an executed state, selectively cleaning at least part of the log file based on the size and the storage duration of the log file; the release of the storage space is realized, and the storage pressure of the storage space is greatly reduced; meanwhile, the mistaken deletion of the log file is avoided.
As shown in fig. 2, further, in step S130, acquiring the size and the storage duration of the target service log file to clean the log file according to the size and the storage duration of the log file may include:
s210: and judging whether the size of the log file is larger than a first threshold value or not.
For example, the first threshold may be set to 30G.
S220: and if the size of the log file is larger than the first threshold, judging whether the storage time length of the log file is larger than a preset first time length threshold.
For example, the first duration threshold may be set to 30 minutes.
S230: and if the storage time of the log file is longer than the first time threshold, cleaning the log file.
For example, if the size of a log file of a target service is 37G and the storage time thereof is 34 minutes, the log file is cleared. As shown in fig. 2, the method further comprises:
s240: if the size of the log file is smaller than or equal to the first threshold, judging whether the size of the log file is larger than a second threshold, wherein the second threshold is smaller than the first threshold.
For example, the second threshold may be set to 20G.
S250: if the size of the log file is larger than the second threshold, judging whether the storage time length of the log file is larger than a preset second time length threshold, wherein the second time length threshold is larger than the first time length threshold.
For example, the second duration threshold may be set to 24 hours.
S260: and if the storage time length of the log file is greater than the second time length threshold value, cleaning the log file.
For example, if the size of a log file of a target service is 24.12G and the storage time is 24 hours and 35 minutes, the same cleaning operation is performed. In combination with the foregoing examples, it can be seen that the dynamic cleaning method for logs provided by the embodiments of the present specification is not considered from the size of the log file or the storage duration of the log file alone, for example, cleaning is prioritized as the volume of the log file is larger, or cleaning is prioritized as the storage duration of the log file is longer; but the size of the log file is associated with the storage duration, so that whether the log file is cleaned or not is comprehensively judged. When the volume of the log file is larger, the time for saving the log file in the corresponding storage path is relatively shorter compared with the log file with smaller volume, because the log file with larger volume has longer storage time and more serious occupation of the limited storage space. Conversely, log files with smaller volumes may have longer storage times in the deposit space.
Further, as shown in fig. 2, the method further includes:
s270: if the size of the file is smaller than the second threshold, whether the storage duration of the log file is larger than a preset third duration threshold or not is judged, and the third duration threshold is larger than the second duration threshold.
The third duration threshold may be set to 7 days.
S280: and if the storage time of the log file is greater than the third time threshold, cleaning the log file.
S290: otherwise, continuing to keep the log file of the target service.
According to the dynamic cleaning method for the log files, the size and the storage time length of the log files are considered comprehensively, different cleaning strengths are set according to different sizes and different storage time lengths of the log files, so that the log files occupying a larger storage space are cleaned preferentially, the log files occupying a smaller storage space are cleaned later, and the effective release of the storage space is realized; and the cleaning operation of the log file is more elastic and flexible.
In other possible embodiments, as shown in fig. 3, the obtaining the size and the storage duration of the target service log file in step S130 to clean the log file according to the size and the storage duration of the log file may further include:
s310: and calculating to obtain a cleaning coefficient of the log file according to the current running state of the target service and the size and storage duration of the log file.
Specifically, in the embodiment of the present specification, the cleaning coefficient may be calculated by the following formula:
Figure BDA0003921075260000091
wherein R is the cleaning coefficient of each log file; * Multiplication in the four arithmetic operations; s is the current running state of the target service corresponding to each log file, when the target service is in the running state, the value of S is 1, and when the target service is in the non-running state, the value of S is 0; v is the size of each log file, h is a first threshold, and in this specification, the value of h may be 30; l is a second threshold value, and the value of l can take 20; ti is the generation time of each log file, and T is the current time node.
S320: and comparing the cleaning coefficient with a preset cleaning coefficient threshold value.
S330: and when the cleaning coefficient is less than or equal to the cleaning coefficient, cleaning the log file.
For example, the cleaning coefficient threshold may be set to 0, and when the cleaning coefficient of a certain log file is less than or equal to 0, the cleaning operation is immediately performed on the certain log file. Conversely, when the cleaning coefficient of a log file is greater than 0, the cleaning operation can be executed relatively late.
Of course, the priority of the cleaning operation can also be obtained according to the comparison of the cleaning coefficients of the log files: the smaller the cleaning coefficient is, the more preferential the cleaning is; the larger the cleaning coefficient is, the more important the log file is relatively, and the later the log file is cleaned relatively; when the cleaning factor is much greater than 1, then the cleaning may be considered as temporary.
In another possible embodiment, when the current state of the target service is a running state and the log file of the target service is not in an executed state, the method may further include:
obtaining the type of the target service log file, wherein the type of the log file at least comprises an ERROR log (ERROR), a reminding log (WARN), an information log (INFO) and a debugging log (DEBUG);
and clearing the log file according to the size, the storage time and the type of the log file.
An error log, which indicates that the log indicates that the target service has more serious errors which may affect the normal operation of the target service; reminder logs (also known as alarm logs) are typically used to indicate general, non-operational errors that exist for the target service; the information log is used for recording information of stages of target service testing, running and the like, such as calling time, access parameters and the like; and the debugging log is mainly used for running information in the target service development process. Different types of log files can be provided with different weights, and specifically, the respective weights of the error log, the reminding log, the information log and the debugging log are sequentially increased.
Thus, cleaning the log files according to the size, storage duration and type of the log files may be to calculate a cleaning coefficient of each log file by the following formula:
Figure BDA0003921075260000101
wherein α is a weight corresponding to the log file type.
For example, when the log file is an error log, α may take a value of 0.25; when the log file is a reminding log, the value of alpha can be 0.5; when the log file is an information log, the value of alpha can be 2; when the log file is a reminder log, the value of α can take 16.
Further, the priority order in the cleaning operation for each log file is determined based on the cleaning coefficient for each log file.
In other possible embodiments, the log file dynamic cleaning method may further include:
calculating the generation frequency of each type of log file of the target service in an observation period;
and clearing the log file according to the generation frequency of the log file.
Specifically, the generation frequency of the error log and the generation frequency of the reminding log can be calculated (the generation frequency of the error log and the generation frequency of the reminding log can be calculated respectively, or the generation frequencies of the error log and the reminding log can be calculated by combining the error log and the reminding log together), and then the log file of the target service is cleaned according to the generation frequencies of the error log and/or the reminding log.
For example, if a certain target service generates a large number of error logs and/or reminder logs in an observation period, that is, the generation frequency of the error logs and/or reminder logs is greater than or equal to a preset frequency threshold, it indicates that the target service has more frequent problems, and the possibility of subsequently performing fault analysis on the target service by using a log file generated by the target service is higher, so that the cleaning operation on the log file can be suspended. If most of the log files generated by a certain target service in the observation period are information logs and debugging logs, and error logs and reminding logs are generated less or not (that is, the generation frequency of the error logs and/or the reminding logs is less than a preset frequency threshold), it is indicated that the target service operates well in the observation period, and the probability of subsequently performing fault analysis on the target service by using the log files is low, and the log files of the target service can be deleted preferentially.
Further, at step S120: before determining whether the current state of the target service is the running state, the method may further include:
acquiring a storage path of the target service log file; in this embodiment of the present specification, the log file may be stored in a disk, and a storage path of the log file is the disk storing the log file.
And judging whether the log file of the target service reaches a condition for triggering cleaning according to the storage path.
Further, as shown in fig. 4, the determining, according to the storage path, whether the log file of the target service meets a condition for triggering cleaning may include:
s410: and acquiring the total storage space and the used storage space corresponding to the storage path.
Specifically, the information such as the total storage space, the used storage space and the like of the disk can be queried by using a special linux instruction.
S420: and when the ratio of the used storage space to the total storage space is greater than or equal to a preset occupancy rate, determining that the log file of the target service reaches a condition of triggering cleaning. Then the corresponding cleaning operation is carried out on the log file of the target service.
In some other possible embodiments, the method may further include:
acquiring the read-write speed of a magnetic disk;
comparing the read-write speed with a preset read-write speed threshold value, and comparing the ratio of the used storage space of the disk to the total storage space with a preset occupancy rate;
and if the read-write speed of the disk is less than a preset read-write speed threshold value and the ratio is greater than or equal to a preset occupancy rate, determining that the log file of the target service meets the condition of triggering cleaning.
When the read-write speed of the disk is smaller than a preset read-write speed threshold, the current operation state of the disk is not good; and when the ratio of the used storage space of the disk to the total storage space is greater than or equal to the preset occupancy rate, it indicates that the bad disk operation state is most likely caused by the high occupancy rate (the remaining storage space is less), and therefore, the cleaning operation for the target service log file in the disk is triggered.
It should be noted that log files of multiple services may be stored in the same storage path (disk), and some target services to be cleaned of the log files may exist in the multiple services, or some services that do not need to be cleaned of the log files may exist. Therefore, in the method for dynamically cleaning the log file provided in the embodiment of the present specification, a logic for determining whether the storage space of the disk needs to be released is executed first; then, the target service to be cleaned is determined according to the configuration file, and the log files of all the services stored in the storage path are not cleaned in a unified and batch mode, so that the effect of avoiding the error cleaning of the log files is achieved; and further executing refined cleaning operation on each log file of each target service according to the state of the target service and the state of the target service log file, so as to release the storage space of the disk.
As shown in fig. 5, a log file dynamic cleaning apparatus provided for an embodiment of this specification, the apparatus includes:
an obtaining module 51, configured to obtain a target service of a log file to be cleaned and a current running state of the target service;
a first judging module 52, configured to judge whether a current state of the target service is a running state;
a second determining module 53, configured to determine whether a log file of the target service is in an executed state when the current state of the target service is in an operating state;
a retention module 54, configured to retain the log file when the log file is in an executed state;
a first cleaning module 55, configured to, when the log file is not in the executed state, obtain the size and storage duration of the target service log file, so as to clean the log file according to the size and storage duration of the log file;
and a second cleaning module 56, configured to clean all log files of the target service when the current state of the target service is a non-running state.
The advantages achieved by the device provided by the embodiment of the specification are consistent with those achieved by the method, and are not described in detail herein.
As shown in fig. 6, for a computer device provided in this embodiment, the log file dynamic cleaning apparatus in this specification may be a computer device in this embodiment, and execute the method described herein. The computer device 602 may include one or more processors 604, such as one or more Central Processing Units (CPUs), each of which may implement one or more hardware threads. The computer device 602 may also include any memory 606 for storing any kind of information, such as code, settings, data, etc. For example, and without limitation, memory 606 may include any one or more of the following in combination: any type of RAM, any type of ROM, flash memory devices, hard disks, optical disks, etc. More generally, any memory may use any technology to store information. Further, any memory may provide volatile or non-volatile retention of information. Further, any memory may represent fixed or removable components of computer device 602. In one case, when the processor 604 executes the associated instructions, which are stored in any memory or combination of memories, the computer device 602 may perform any of the operations of the associated instructions. The computer device 602 also includes one or more drive mechanisms 608, such as a hard disk drive mechanism, an optical disk drive mechanism, etc., for interacting with any memory.
Computer device 602 may also include an input/output module 610 (I/O) for receiving various inputs (via input device 612) and for providing various outputs (via output device 614). One particular output mechanism may include a presentation device 616 and an associated Graphical User Interface (GUI) 618. In other embodiments, input/output module 610 (I/O), input device 612, and output device 614 may also be excluded, as just one computer device in a network. Computer device 602 may also include one or more network interfaces 620 for exchanging data with other devices via one or more communication links 622. One or more communication buses 624 couple the above-described components together.
Communication link 622 may be implemented in any manner, such as over a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. Communication link 622 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
Corresponding to the methods shown in fig. 1 to 4, the embodiments herein also provide a computer-readable storage medium having stored thereon a computer program, which, when executed by a processor, performs the steps of the above-described method.
Embodiments herein also provide computer readable instructions, wherein when executed by a processor, a program thereof causes the processor to perform the method as shown in fig. 1-4.
Embodiments herein also provide a computer program product comprising at least one instruction or at least one program, which is loaded and executed by a processor to implement the method as shown in fig. 1 to 4.
It should be understood that, in various embodiments herein, the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments herein.
It should also be understood that, in the embodiments herein, the term "and/or" is only one kind of association relation describing an associated object, meaning that three kinds of relations may exist. For example, a and/or B, may represent: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter associated objects are in an "or" relationship.
Those of ordinary skill in the art will appreciate that the various illustrative components and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the components and steps of the various examples have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present disclosure.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided herein, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the elements may be selected according to actual needs to achieve the objectives of the embodiments herein.
In addition, functional units in the embodiments herein may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present invention may be implemented in a form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, and various media capable of storing program codes.
The principles and embodiments of this document are explained herein using specific examples, which are presented only to aid in understanding the methods and their core concepts; meanwhile, for a person skilled in the art, according to the idea of the present disclosure, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present disclosure should not be construed as a limitation to the present disclosure.

Claims (13)

1. A log file dynamic cleaning method is characterized by comprising the following steps:
acquiring a target service of a log file to be cleaned and a current running state of the target service;
judging whether the current state of the target service is a running state or not;
if the current state of the target service is the running state, judging whether the log file of the target service is an executed state or not;
if yes, the log file is reserved;
if not, acquiring the size and the storage duration of the target service log file so as to clean the log file according to the size and the storage duration of the log file;
and if the current state of the target service is a non-running state, cleaning all log files of the target service.
2. The method of claim 1, wherein obtaining the size and storage duration of the target service log file to clean the log file according to the size and storage duration of the log file, further comprises:
judging whether the size of the log file is larger than a first threshold value or not;
if the size of the log file is larger than the first threshold, judging whether the storage time length of the log file is larger than a preset first time length threshold or not;
and if the storage time of the log file is longer than the first time threshold, cleaning the log file.
3. The method of claim 2, further comprising:
if the size of the log file is smaller than or equal to the first threshold, judging whether the size of the log file is larger than a second threshold, wherein the second threshold is smaller than the first threshold;
if the size of the log file is larger than the second threshold, judging whether the storage time length of the log file is larger than a preset second time length threshold, wherein the second time length threshold is larger than the first time length threshold;
and if the storage time length of the log file is greater than the second time length threshold value, cleaning the log file.
4. The method of claim 3, further comprising:
if the size of the file is smaller than the second threshold, judging whether the storage time length of the log file is larger than a preset third time length threshold, wherein the third time length threshold is larger than the second time length threshold;
and if the storage duration of the log file is greater than the third duration threshold, cleaning the log file.
5. The method of claim 1, wherein obtaining the size and storage duration of the target service log file to clean the log file according to the size and storage duration of the log file, further comprises:
calculating to obtain a cleaning coefficient of the log file according to the current running state of the target service and the size and storage duration of the log file;
comparing the cleaning coefficient with a preset cleaning coefficient threshold value;
and when the cleaning coefficient is less than or equal to the cleaning coefficient, cleaning the log file.
6. The method of claim 5, wherein the cleaning factor is calculated by the following formula:
Figure FDA0003921075250000021
wherein R is the cleaning coefficient of each log file; s is the current running state of the target service corresponding to each log file, when the target service is in a running state, the value of S is 1, and when the target service is in a non-running state, the value of S is 0; v is the size of each log file, h is a first threshold, and in this specification, the value of h may be 30; l is a second threshold value, and the value of l can take 20; ti is the generation time of each log file, and T is the current time node.
7. The method of claim 1, wherein when the current state of the target service is a running state and the log file of the target service is not in an executed state, the method further comprises:
acquiring the type of the target service log file, wherein the type of the log file at least comprises an error log, a reminding log, an information log and a debugging log;
and clearing the log file according to the size, the storage time and the type of the log file.
8. The method of claim 1, wherein prior to determining whether the current state of the target service is a running state, the method further comprises:
acquiring a storage path of the target service log file;
and judging whether the log file of the target service reaches a condition for triggering cleaning according to the storage path.
9. The method of claim 8, wherein the determining whether the log file of the target service meets a condition for triggering cleaning according to the storage path further comprises:
acquiring a total storage space and a used storage space corresponding to the storage path;
and when the ratio of the used storage space to the total storage space is greater than or equal to a preset occupancy rate, determining that the log file of the target service reaches a condition of triggering cleaning.
10. An apparatus for dynamically cleaning log files, the apparatus comprising:
the system comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring a target service of a log file to be cleaned and the current running state of the target service;
the first judgment module is used for judging whether the current state of the target service is an operation state or not;
the second judgment module is used for judging whether the log file of the target service is in an executed state or not when the current state of the target service is in an operating state;
the reservation module is used for reserving the log file when the log file is in an executed state;
the first cleaning module is used for acquiring the size and the storage duration of the target service log file when the log file is not in the executed state so as to clean the log file according to the size and the storage duration of the log file;
and the second cleaning module is used for cleaning all log files of the target service when the current state of the target service is a non-running state.
11. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1 to 9 when executing the computer program.
12. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, implements the method of any one of claims 1 to 9.
13. A computer program product comprising at least one instruction or at least one program which is loaded and executed by a processor to implement the method of any one of claims 1 to 9.
CN202211355694.1A 2022-11-01 2022-11-01 Log file dynamic cleaning method and device and computer equipment Pending CN115905110A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211355694.1A CN115905110A (en) 2022-11-01 2022-11-01 Log file dynamic cleaning method and device and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211355694.1A CN115905110A (en) 2022-11-01 2022-11-01 Log file dynamic cleaning method and device and computer equipment

Publications (1)

Publication Number Publication Date
CN115905110A true CN115905110A (en) 2023-04-04

Family

ID=86487503

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211355694.1A Pending CN115905110A (en) 2022-11-01 2022-11-01 Log file dynamic cleaning method and device and computer equipment

Country Status (1)

Country Link
CN (1) CN115905110A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737676A (en) * 2023-08-15 2023-09-12 中移(苏州)软件技术有限公司 File storage method, device, electronic equipment and readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737676A (en) * 2023-08-15 2023-09-12 中移(苏州)软件技术有限公司 File storage method, device, electronic equipment and readable storage medium

Similar Documents

Publication Publication Date Title
CN110245078B (en) Software pressure testing method and device, storage medium and server
US8056060B2 (en) Software testing method and system
US10698605B2 (en) Multipath storage device based on multi-dimensional health diagnosis
US20070203973A1 (en) Fuzzing Requests And Responses Using A Proxy
US20070168201A1 (en) Formula for automatic prioritization of the business impact based on a failure on a service in a loosely coupled application
CN110537170B (en) Method, system and computer readable storage device for analyzing large scale data processing jobs
US20080276129A1 (en) Software tracing
CN109407984B (en) Method, device and equipment for monitoring performance of storage system
CN115905110A (en) Log file dynamic cleaning method and device and computer equipment
CN113360270A (en) Data cleaning task processing method and device
US8601318B2 (en) Method, apparatus and computer program product for rule-based directed problem resolution for servers with scalable proactive monitoring
CN109542341B (en) Read-write IO monitoring method, device, terminal and computer readable storage medium
CN112052078A (en) Time-consuming determination method and device
CN110943887B (en) Probe scheduling method, device, equipment and storage medium
CN110659147B (en) Self-repairing method and system based on module self-checking behavior
EP4060435B1 (en) Method and system for infrastructure monitoring
CN110287115A (en) Generation method, device and the server of test report
EP3391295B1 (en) Autonomic method for managing a computing system
CN114356571A (en) Processing method and device
CN114741218A (en) Method, device, equipment, system and medium for extracting abnormal index of operating system
US9864668B2 (en) Apparatus, method, and system for event data processing
CN113626236A (en) Fault diagnosis method, device, equipment and medium for distributed file system
JP2001014189A (en) Instrument and method for measuring throughput
CN112068935A (en) Method, device and equipment for monitoring deployment of kubernets program
CN110750432B (en) IO performance analysis method and system of distributed storage system and related components

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination