Disclosure of Invention
The embodiment of the invention aims to provide a log query method, a log query device, electronic equipment and a storage medium, so as to achieve the beneficial effects of simplifying user operation, improving log query efficiency and saving time and energy. The specific technical scheme is as follows:
in a first aspect of the embodiments of the present invention, a log query method is first provided, where the method includes:
acquiring a first server identifier and a first application identifier input by a user;
determining a log query condition input by a user;
according to the log query condition, a log corresponding to the first server identifier and the first application identifier is queried from a server;
the server is used for collecting logs corresponding to the first application deployed on the first server.
In an optional embodiment, before performing the method, the method further comprises:
acquiring a second server identifier and a second application identifier;
sending a log acquisition request to a server, so that the server analyzes the second server identifier and the second application identifier carried in the log acquisition request, issues a log collector and a configuration file to a second server corresponding to the second server identifier, and starts the log collector;
the log collector is configured to collect a log of a second application corresponding to the second application identifier deployed on the second server according to the configuration file, and return the log to the server.
In an optional embodiment, the obtaining the second application identifier includes:
determining and displaying a second application identifier of a second application deployed on a second server corresponding to the second server identifier;
and acquiring the second application identifier selected by the user.
In an optional embodiment, the determining and presenting a second application identifier of a second application deployed on a second server corresponding to the second server identifier includes:
under the condition of receiving a query instruction, sending the second server identifier to a server, so that the server queries a second application deployed on a second server corresponding to the second server identifier, and returns a second application identifier of the second application deployed on the second server;
and receiving and displaying a second application identifier of a second application deployed on a second server corresponding to the second server identifier.
In an optional implementation manner, the querying, by the server, a second application deployed on a second server corresponding to the second server identifier includes:
and the server logs in a second server corresponding to the second server identifier through SSH, and inquires a second application deployed on the second server corresponding to the second server identifier.
In an optional implementation manner, before sending the log collection request to the server, the method further includes:
inquiring whether the server has logs corresponding to the second server identifier and the second application identifier;
and under the condition that the server does not have logs corresponding to the second server identifier and the second application identifier, executing a step of sending a log collection request to the server.
In an optional embodiment, the issuing a log collector and a configuration file to a second server corresponding to the second server identifier includes:
determining a configuration file corresponding to the second server identification and the second application identification;
and issuing a log collector and the configuration file to a second server corresponding to the second server identifier.
In a second aspect of the embodiments of the present invention, there is also provided a log query apparatus, including:
the identification acquisition module is used for acquiring a first server identification and a first application identification which are input by a user;
the condition determining module is used for determining log query conditions input by a user;
the log query module is used for querying logs corresponding to the first server identifier and the first application identifier from a server according to the log query condition;
the server is used for collecting logs corresponding to the first application deployed on the first server.
In a third aspect of the embodiments of the present invention, there is further provided an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
a processor, configured to implement the log query method according to any one of the first aspect when executing a program stored in a memory.
In a fourth aspect of the embodiments of the present invention, there is further provided a storage medium, where instructions are stored, and when the storage medium is run on a computer, the storage medium causes the computer to execute the log query method according to any one of the first aspect.
In a fifth aspect of embodiments of the present invention, there is also provided a computer program product containing instructions, which when run on a computer, cause the computer to perform the log querying method of any one of the above first aspects.
According to the technical scheme provided by the embodiment of the invention, the log query condition input by the user is determined by acquiring the first server identifier and the first application identifier input by the user, and the log corresponding to the first server identifier and the first application identifier is queried from the server side according to the log query condition. Therefore, the user can query the log only by inputting the server identifier and the corresponding application identifier, the user operation is simplified, the log query efficiency is improved, and the time and the energy are saved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
In the embodiment of the invention, in order to simplify user operation, improve log query efficiency and save time and energy, a log query condition input by a user is determined by acquiring a first server identifier and a first application identifier input by the user, and a log corresponding to the first server identifier and the first application identifier is queried from a server according to the log query condition.
Specifically, as shown in fig. 1, in the embodiment of the present invention, the client is connected to the server, the server is connected to the N servers, and the log query system may be composed of the client, the server and the N servers. The server and the N servers may be deployed in an intranet, and the server may specifically be an Elasticsearch server, and is configured to collect logs corresponding to applications deployed on the N servers, such as an operation log, a safety log, and a fault log.
Based on the log query system, as shown in fig. 2, an implementation flow diagram of a log query method provided by the embodiment of the present invention is applied to a client, and the method specifically includes the following steps:
s201, acquiring a first server identifier and a first application identifier input by a user;
when a user needs to query a log corresponding to an application deployed on a server, for example, an operation log, a security log, a fault log, and the like, the user may input a first server identifier and a first application identifier on a log query page in a log query system.
For the first server identifier, for example, the server IP address, the server name, the server ID, and the like may be used, and for the first application identifier, for example, the application name, the application ID, and the like may be used, which is not limited in this embodiment of the present invention.
For example, in the embodiment of the present invention, the server IP address and the application name are shown in a list form, the user can freely input the server IP address and the application name according to the actual requirement of the user, and the client obtains the first server IP address (172.168.1.1) and the first application name (application name 1) input by the user.
S202, determining a log query condition input by a user;
in the embodiment of the present invention, the user may input a log query condition according to actual requirements, for example, the user wants to query the last N logs of the application (where N may be 10, 100, 500, 2000 and any number input), and for example, the user wants to scroll the logs of the query application in real time.
When a user inputs a corresponding log query condition, the embodiment of the invention determines the log query condition input by the user, namely any log query condition.
S203, according to the log query condition, a log corresponding to the first server identifier and the first application identifier is queried from a server.
In the embodiment of the present invention, for the server, an index, for example, an Elasticsearch index named by the server identifier and the application identifier, is established according to the server identifier and the application identifier, and a log corresponding to the server identifier and the application identifier is stored in the Elasticsearch index, for example, as shown in table 1 below.
TABLE 1
For the query condition determined in the above step, in the embodiment of the present invention, according to the log query condition, the server queries the log corresponding to the first server identifier and the first application identifier, and may display the log corresponding to the first server identifier and the first application identifier. The server is used for collecting logs corresponding to the first application deployed on the first server.
Specifically, according to the log query condition, the embodiment of the present invention may query the log corresponding to the first server identifier and the first application identifier from the Elasticsearch index in the server, and may display the log corresponding to the first server identifier and the first application identifier.
For example, when a user inputs a query application with the last 10 logs, the embodiment of the present invention queries the last 10 logs corresponding to the first server identifier and the first application identifier from the server-side Elasticsearch index; when a user inputs a log of a real-time rolling query application, the embodiment of the invention queries the log corresponding to the first server identifier and the first application identifier from the server-side Elasticissearch index in real time.
Principle for real-time scrolling through logs for query applications: after a user inputs a server IP address and an application name, a client and a server establish socket connection, an Elasticissearch index corresponding to the server IP address and the application name is inquired from an Elasticissearch server, the last log in the Elasticissearch index is inquired, the serial number, namely the starting serial number (from), is obtained, a certain number of logs (size, such as 100 logs) are obtained each time, the logs in the Elasticissearch index are inquired according to the from + size, the logs are sent to the client through the socket connection and displayed, and the process is circulated until the user decides to stop inquiring and close the socket connection.
Through the above description of the technical solution provided by the embodiment of the present invention, the log query condition input by the user is determined by obtaining the first server identifier and the first application identifier input by the user, and the log corresponding to the first server identifier and the first application identifier is queried from the server according to the log query condition. Therefore, the user can query the log only by inputting the server identifier and the corresponding application identifier, the user operation is simplified, the log query efficiency is improved, and the time and the energy are saved.
Based on the log query system, as shown in fig. 3, an implementation flow diagram of a log collection method provided by the embodiment of the present invention is applied to a client, and the method specifically includes the following steps:
s301, acquiring a second server identifier and a second application identifier;
in the embodiment of the present invention, when a user needs to acquire a log corresponding to an application deployed on a certain server, a second server identifier and a second application identifier may be input on a log acquisition page of a log query system, where the second server identifier and the second application identifier uniquely specify an object of the log to be acquired.
The server identifier may be a server IP address, a server ID, a server name, and the like, which is not limited in this embodiment of the present invention. For example, the embodiment of the present invention obtains the IP address of the second server input by the user: 172.168.1.1, and a second application name: java application 1.
The embodiment of the invention obtains the second server identifier, determines and displays the second application identifier of the second application deployed on the second server corresponding to the second server identifier, and obtains the second application identifier input by the user, so that the second server identifier and the second application identifier can also be obtained.
For example, the user may input a second server IP address (172.168.1.1) on a log collection page of the log query system, and in the embodiment of the present invention, a second application identifier of a second application deployed on a second server corresponding to the second server IP address (172.168.1.1) may be determined and presented for selection, and the user may select one or more of the second application identifiers for log collection, so as to obtain the second application identifier selected by the user, that is, the log collection object selected by the user.
Specifically, under the condition that an inquiry instruction is received, the client sends the second server identifier to the server, so that the server inquires the second application deployed on the second server corresponding to the second server identifier and returns the second application identifier of the second application deployed on the second server, and the client receives and displays the second application identifier of the second application deployed on the second server corresponding to the second server identifier and can display the second application identifier in a list form.
In this way, the client may determine and display the second application identifier of the second application deployed on the second server corresponding to the second server identifier, and the application identifier may be an application name, an application ID, or the like. In addition, the server side can also return a log path of the second application, and the log path can be displayed in a list form in the embodiment of the invention.
For the second server identifier and the second application identifier, the second server identifier and the second application identifier may be used to establish an Elasticsearch index, and the globally unique identifier may determine the corresponding log. For the log path, the path may be the path of the log file to be queried.
For example, for the IP address (172.168.1.1), when the user clicks the query button, a query instruction is triggered, and the embodiment of the present invention may receive the query instruction triggered by the user, send the IP address to the server, so that the server may receive the IP address, query the second application deployed on the second server corresponding to the IP address, and return the application identifier of the second application and the log path of the second application to the client, and the client may receive and display the second application identifier of the second application deployed on the second server and the log path of the second application, as shown in table 2 below.
IP address
|
Application name
|
Log path
|
172.168.1.1
|
Application name 1
|
Log Path 1
|
172.168.1.1
|
Application name 2
|
Log Path 2
|
……
|
……
|
…… |
TABLE 2
The server may log in a second server corresponding to the second server identifier through an SSH (Secure Shell, Secure Shell protocol), and query a second application deployed on the second server corresponding to the second server identifier. The user name and the password used in the login process may be predetermined, which is not limited in the embodiment of the present invention.
S302, sending a log acquisition request to a server, so that the server analyzes the second server identifier and the second application identifier carried in the log acquisition request, issuing a log collector and a configuration file to a second server corresponding to the second server identifier, and starting the log collector;
in the embodiment of the present invention, after obtaining the second server identifier and the second application identifier, the client may send a log collection request to the server, where the log collection request carries the second server identifier and the second application identifier.
The server side can receive the log acquisition request, analyze a second server identifier and a second application identifier carried in the log acquisition request, issue a log collector and a configuration file to a second server corresponding to the second server identifier, and start the log collector.
The log collector is used for collecting logs of a second application corresponding to a second application identifier deployed on a second server according to the configuration file and returning the logs to the server.
For example, the log collector may be filehead software, and for the configuration file, for example, the configuration file may be a dynamically generated configuration file, yml, where the configuration file includes a second server identifier and a second application identifier for collecting a log, which is not limited in the embodiment of the present invention.
In this way, the server may determine the configuration file corresponding to the second server identifier and the second application identifier, and issue the log collector and the configuration file to the second server corresponding to the second server identifier.
For example, the configuration file may correspond to a second server identification and a second application identification, as shown in table 3 below.
TABLE 3
The server may determine the configuration file corresponding to 172.168.1.1 and Java application 1, and issue a journal logger and the configuration file to the second server.
In addition, before sending a log acquisition request to a server, inquiring whether the server has a log corresponding to the second server identifier and the second application identifier; sending a log acquisition request to the server under the condition that the log corresponding to the second server identifier and the second application identifier does not exist in the server; and under the condition that the server has the logs corresponding to the second server identifier and the second application identifier, the log collection of the second application deployed on the second server is represented, that is, the log query system does not need to be accessed again.
Furthermore, for a second application deployed on a second server that has performed log collection, the embodiment of the present invention may stop log collection, that is, remove access to the log query system, and therefore, may send a log collection stop request to the server, where the log collection stop request carries a second server identifier and a second application identifier, and the server receives the log collection stop request, analyzes the second server identifier and the second application identifier carried in the log collection stop request, stops running a log collector on the second server corresponding to the second server identifier, and deletes a configuration file corresponding to the second server identifier and the second application identifier.
Corresponding to the foregoing method embodiment, an embodiment of the present invention further provides a log query apparatus, as shown in fig. 4, where the apparatus may include: an identification acquisition module 410, a condition determination module 420, and a log query module 430.
An identifier obtaining module 410, configured to obtain a first server identifier and a first application identifier input by a user;
a condition determining module 420, configured to determine a log query condition input by a user;
a log query module 430, configured to query, from a server, a log corresponding to the first server identifier and the first application identifier according to the log query condition;
the server is used for collecting logs corresponding to the first application deployed on the first server.
In a specific implementation manner of the embodiment of the present invention, the apparatus further includes:
an obtaining module 440, configured to obtain a second server identifier and a second application identifier;
a request sending module 450, configured to send a log acquisition request to a server, so that the server analyzes the second server identifier and the second application identifier carried in the log acquisition request, issues a log collector and a configuration file to a second server corresponding to the second server identifier, and starts the log collector;
the log collector is configured to collect a log of a second application corresponding to the second application identifier deployed on the second server according to the configuration file, and return the log to the server.
In a specific implementation manner of the embodiment of the present invention, the obtaining module 440 includes:
the identifier determining submodule 441 is configured to determine and display a second application identifier of a second application deployed on a second server corresponding to the second server identifier;
the second obtaining sub-module 442 is configured to obtain the second application identifier selected by the user.
In a specific implementation manner of the embodiment of the present invention, the identifier determining submodule 441 is specifically configured to:
under the condition of receiving a query instruction, sending the second server identifier to a server, so that the server queries a second application deployed on a second server corresponding to the second server identifier, and returns a second application identifier of the second application deployed on the second server;
and receiving and displaying a second application identifier of a second application deployed on a second server corresponding to the second server identifier.
In a specific implementation manner of the embodiment of the present invention, the querying, by the server, a second application deployed on a second server corresponding to the second server identifier includes:
and the server logs in a second server corresponding to the second server identifier through SSH, and inquires a second application deployed on the second server corresponding to the second server identifier.
In a specific implementation manner of the embodiment of the present invention, the apparatus further includes:
the query module 460 is configured to query whether the server has a log corresponding to the second server identifier and the second application identifier;
and under the condition that the server does not have logs corresponding to the second server identifier and the second application identifier, executing a step of sending a log collection request to the server.
In a specific implementation manner of the embodiment of the present invention, the issuing a log collector and a configuration file to a second server corresponding to the second server identifier includes:
determining a configuration file corresponding to the second server identification and the second application identification;
and issuing a log collector and the configuration file to a second server corresponding to the second server identifier.
An embodiment of the present invention further provides an electronic device, as shown in fig. 5, including a processor 51, a communication interface 52, a memory 53 and a communication bus 54, where the processor 51, the communication interface 52, and the memory 53 complete mutual communication through the communication bus 54,
a memory 53 for storing a computer program;
the processor 51 is configured to implement the following steps when executing the program stored in the memory 53:
acquiring a first server identifier and a first application identifier input by a user; determining a log query condition input by a user; according to the log query condition, a log corresponding to the first server identifier and the first application identifier is queried from a server; the server is used for collecting logs corresponding to the first application deployed on the first server.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
In another embodiment of the present invention, there is also provided a storage medium having stored therein instructions, which when run on a computer, cause the computer to execute the log query method described in any one of the above embodiments.
In yet another embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the log query method of any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a storage medium or transmitted from one storage medium to another, for example, from one website, computer, server, or data center to another website, computer, server, or data center via wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The storage medium may be any available medium that can be accessed by a computer or a data storage device including one or more available media integrated servers, data centers, and the like. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, 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 identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.