Server information acquisition method, device, electronic device and storage medium
By executing the target program on the server and calling the jar toolkit to call the Sigar dynamic library according to the operating system type, the problems of complex server information collection and resource monitoring operations and difficult data integration in the existing technology are solved, and simple and efficient information collection and unified operating system support are achieved.
Patent Information
- Application Number
- CN202110208317.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-24
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2041-02-24
AI Technical Summary
The prior art has problems such as complex operation and difficulty in data integration in server information collection and resource monitoring, especially in the fact that it cannot be easily integrated into Java programs.
By executing the target program, the jar toolkit is called, which is used to call the corresponding Sigar dynamic library according to the operating system type, and then collect server information.
It realizes simple and efficient server information collection and resource monitoring, and can uniformly collect server information from different operating systems, simplifying the operation process.
Smart Images

Figure CN112835767B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a server information acquisition method, device, electronic device and storage medium. Background Art
[0002] Currently, there are two main methods for collecting information and monitoring resources on servers: one method is to use Linux Shell commands, and the other method is to call dynamic libraries in the program.
[0003] Both methods have certain disadvantages. Although the first method is easy to operate, it can only perform simple collection and cannot integrate and process complex data. It cannot be directly integrated into Java programs for use. Although the second method can be integrated into Java programs for use, it requires configuration files to distinguish different system categories and call different dynamic libraries, which is more complicated to operate. Summary of the invention
[0004] In view of the problems existing in the prior art, the present invention provides a method, device, electronic device and storage medium for acquiring server information.
[0005] The present invention provides a method for obtaining server information, comprising:
[0006] Execute the target program and call the jar toolkit, wherein the jar toolkit is used to call the corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information;
[0007] Execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information.
[0008] According to a server information acquisition method provided by the present invention, the executing target program and calling the jar toolkit include:
[0009] Execute the target program, obtain the calling address of the jar tool package according to the jar instruction in the target program; and call the jar tool package according to the calling address.
[0010] According to a server information acquisition method provided by the present invention, the jar toolkit is executed to acquire the corresponding Sigar dynamic library, and the acquired Sigar dynamic library is executed to collect server information, including:
[0011] Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type;
[0012] The Sigar dynamic library is executed to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains collection items of server information.
[0013] According to a server information acquisition method provided by the present invention, the jar toolkit is obtained by using Java language coding.
[0014] The present invention also provides a server information acquisition device, comprising:
[0015] A calling module is used to execute a target program and call a jar toolkit, wherein the jar toolkit is used to call a corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information;
[0016] The acquisition module is used to execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information.
[0017] The present invention also provides a server information acquisition device, wherein the calling module is specifically used for:
[0018] Execute the target program, obtain the calling address of the jar tool package according to the jar instruction in the target program; and call the jar tool package according to the calling address.
[0019] The present invention also provides a server information acquisition device, wherein the acquisition module is specifically used for:
[0020] Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type;
[0021] The Sigar dynamic library is executed to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains collection items of server information.
[0022] The present invention also provides a server information acquisition device, wherein the jar toolkit is obtained by using Java language coding.
[0023] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-mentioned server information acquisition methods are implemented.
[0024] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned server information acquisition methods are implemented.
[0025] The server information acquisition method, device, electronic device and storage medium provided by the present invention call the jar toolkit by executing a program, determine the Sigar dynamic library used for the server operating system, collect server information based on the Sigar dynamic library, and achieve the purpose of simple and efficient information collection and resource monitoring of the server, and can achieve the purpose of uniformly collecting server information for different operating systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 It is a flow chart of the method for obtaining server information provided by the present invention;
[0028] Figure 2 It is a structural schematic diagram of the server information acquisition device provided by the present invention;
[0029] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] To this end, the following Figure 1-Figure 3 The present invention describes a method, device, electronic device and storage medium for acquiring server information.
[0032] Figure 1 The flowchart of the method for obtaining server information provided by the present invention is shown, which is applied to the server side and includes the following steps:
[0033] 11. Execute the target program and call the jar toolkit, where the jar toolkit is used to call the corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information;
[0034] 12. Execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information.
[0035] Regarding step 11-step 12, it should be noted that in the present invention, a startup program for collecting server information, i.e. the target program mentioned, is configured on the server. The server plans to collect server information. The server will start the target program under the instruction of the user's operation. After the target program is started, the jar toolkit will be called. The jar toolkit is used to call the corresponding Sigar dynamic library according to the operating system type. For different operating systems, for example, sigar-amd64-winnt.dll or sigar-x86-winnt.dll and libsigar-amd64-linux.so or libsigar-x86-linux.so dynamic libraries are provided for Windows and Linux operating systems respectively. The Sigar dynamic library is a tool for collecting system and processing information. It can collect computer host information such as operating system, CPU, memory, process, file system, network, etc., which will not be introduced in detail here.
[0036] The server executes the jar toolkit to obtain the corresponding Sigar dynamic library, that is, executing the jar toolkit can call the corresponding Sigar dynamic library according to the operating system of the current server. Then the obtained Sigar dynamic library is executed to collect server information.
[0037] The server information acquisition method provided by the present invention determines the Sigar dynamic library used for the server operating system by calling the jar toolkit through an execution program, collects server information based on the Sigar dynamic library, and realizes the purpose of simply and efficiently collecting information and monitoring resources on the server, and can realize the purpose of uniformly collecting server information for different operating systems.
[0038] In the further description of the above method, the processing of executing the target program and calling the jar tool package is mainly explained, as follows:
[0039] Execute the target program, obtain the calling address of the jar tool package according to the jar instruction in the target program, and call the jar tool package according to the calling address.
[0040] In this regard, it should be noted that in the present invention, a jar instruction will be written in the target program. During the execution of the target program, the jar instruction in the program will be executed. Based on the jar instruction, the calling address of the jar toolkit can be determined, and then the jar toolkit can be called based on the calling address.
[0041] In the present invention, the jar toolkit is obtained by using Java language coding. Accordingly, the jar instruction is also obtained by using Java language coding. When the jar instruction is executed, the step of determining the jar toolkit can be started accordingly, so as to quickly call the jar toolkit.
[0042] In the further description of the above method, the main explanation is about the process of executing the jar toolkit to obtain the corresponding Sigar dynamic library, and executing the obtained Sigar dynamic library to collect server information, which is as follows:
[0043] Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type;
[0044] The Sigar dynamic library is executed to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains collection items of server information.
[0045] In this regard, it should be noted that in the present invention, the jar toolkit contains a full-text search directory file for collecting and monitoring computer host information such as operating system, CPU, memory, process, file system, network, etc. The full-text search target file contains collection items of server information. The collection items such as CPU information, memory information, process information, network interface information, network routing and connection table information, etc. are not listed here one by one.
[0046] In the present invention, after executing the jar toolkit, the operating system type used by the server is first collected, and then the corresponding Sigar dynamic library is called according to the operating system type. For example, if the operating system type is Linux operating system (x86), the libsigar-x86-linux.so dynamic library is called.
[0047] Then, based on the collection items in the full-text search catalog file in the jar toolkit, the Sigar dynamic library is executed to collect the corresponding server information.
[0048] A further method of the present invention, by writing a full-text search catalog file on a jar toolkit, can provide preset collection items when executing the Sigar dynamic library to collect server information, thereby facilitating accurate collection of server information.
[0049] The server information acquisition device provided by the present invention is described below. The server information acquisition device described below and the server information acquisition method described above can be referenced to each other.
[0050] Figure 2 The schematic diagram of the structure of the server information acquisition device provided by the present invention is shown in FIG. Figure 2The device comprises a calling module 21 and a collecting module 22, wherein:
[0051] A calling module 21 is used to execute a target program and call a jar toolkit, wherein the jar toolkit is used to call a corresponding Sigar dynamic library according to an operating system type, and the target program is a startup program for collecting server information;
[0052] The acquisition module 22 is used to execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information.
[0053] In the further description of the above device, the calling module is specifically used for:
[0054] Execute the target program, obtain the calling address of the jar tool package according to the jar instruction in the target program; and call the jar tool package according to the calling address.
[0055] In the further description of the above device, the acquisition module is specifically used for:
[0056] Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type;
[0057] The Sigar dynamic library is executed to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains collection items of server information.
[0058] In the further description of the above device, the jar toolkit is obtained by using Java language coding.
[0059] Since the principle of the device described in the embodiment of the present invention is the same as that of the method described in the above embodiment, a more detailed explanation will not be repeated here.
[0060] It should be noted that, in the embodiment of the present invention, the relevant functional modules can be implemented by a hardware processor.
[0061] The server information acquisition device provided by the present invention determines the Sigar dynamic library used for the server operating system by calling the jar toolkit through an execution program, collects server information based on the Sigar dynamic library, and realizes the purpose of simply and efficiently collecting information and monitoring resources on the server, and can realize the purpose of uniformly collecting server information for different operating systems.
[0062] Figure 3 A schematic diagram of the physical structure of an electronic device is shown. Figure 3As shown, the electronic device may include: a processor 31, a communication interface 32, a memory 33 and a communication bus 34, wherein the processor 31, the communication interface 32 and the memory 33 communicate with each other through the communication bus 34. The processor 31 may call the logic instructions in the memory 33 to execute the server information acquisition method, the method comprising: executing the target program, calling the jar toolkit, wherein the jar toolkit is used to call the corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information; executing the jar toolkit to obtain the corresponding Sigar dynamic library, and executing the obtained Sigar dynamic library to collect server information.
[0063] In addition, the logic instructions in the above-mentioned memory 33 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0064] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the server information acquisition method provided by the above methods, and the method includes: executing a target program and calling a jar toolkit, wherein the jar toolkit is used to call a corresponding Sigar dynamic library according to an operating system type, and the target program is a startup program for collecting server information; executing the jar toolkit to obtain a corresponding Sigar dynamic library, and executing the obtained Sigar dynamic library to collect server information.
[0065] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the above-mentioned server information acquisition methods, the method comprising: executing a target program and calling a jar toolkit, wherein the jar toolkit is used to call a corresponding Sigar dynamic library according to an operating system type, and the target program is a startup program for collecting server information; executing the jar toolkit to obtain a corresponding Sigar dynamic library, and executing the obtained Sigar dynamic library to collect server information.
[0066] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0067] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for obtaining server information, characterized in that: include: Execute the target program and call the jar toolkit, wherein the jar toolkit is used to call the corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information; Execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information; The target program is executed, and the jar toolkit is called, including: Execute the target program, and obtain the calling address of the jar tool package according to the jar instruction in the target program; call the jar tool package according to the calling address; The executing of the jar toolkit to obtain the corresponding Sigar dynamic library, and executing the obtained Sigar dynamic library to collect server information, includes: Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type; Execute the Sigar dynamic library to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains a collection item of server information; The jar toolkit is obtained by coding in Java language.
2. A server information acquisition device, characterized in that: include: A calling module is used to execute a target program and call a jar toolkit, wherein the jar toolkit is used to call a corresponding Sigar dynamic library according to the operating system type, and the target program is a startup program for collecting server information; A collection module, used to execute the jar toolkit to obtain the corresponding Sigar dynamic library, and execute the obtained Sigar dynamic library to collect server information; The calling module is specifically used for: Execute the target program, and obtain the calling address of the jar tool package according to the jar instruction in the target program; call the jar tool package according to the calling address; The acquisition module is specifically used for: Execute the jar toolkit to collect the operating system type used by the server, and call the corresponding Sigar dynamic library according to the operating system type; Execute the Sigar dynamic library to collect server information based on the full-text search directory file in the jar toolkit, wherein the full-text search directory file contains a collection item of server information; The jar toolkit is obtained by coding in Java language.
3. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the server information acquisition method according to claim 1 are implemented.
4. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the server information acquisition method as claimed in claim 1 are implemented.