A health check method and device for a server
By checking process and historical baseline information on the Apache server and performing a comprehensive health check in conjunction with configuration files, the problem of poor universality of existing Apache server check methods is solved, achieving more comprehensive health status monitoring and avoiding false alarms.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-27
- Publication Date
- 2026-04-14
AI Technical Summary
Existing Apache server health check methods are limited in scope and lack versatility, failing to comprehensively identify deeper problems and risks.
By checking whether the Apache process exists on the server and historical baseline information, reading the Apache configuration file, and performing a comprehensive health check based on the configuration information, including checks on metrics such as Apache service status, access success rate, concurrency utilization, thread busy rate, and listener queue depth.
It achieves universality and reliability of Apache server health checks, avoids false alarms, and can perform comprehensive and complete checks to ensure the health status monitoring of servers.
Smart Images

Figure CN116107831B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer network technology, and in particular to a method and apparatus for checking the health of a server. Background Technology
[0002] Apache, as a web server, is widely used due to its modularity, simplicity, fast operation, and stable performance, making it one of the most popular open-source software products today. To ensure the healthy and stable operation of the Apache server, routine maintenance is required to check its operational status. Currently, there are two main methods for health checks on Apache:
[0003] The first method is to check the number of Apache processes running and the service listening port to determine if the Apache service is working properly.
[0004] The second method is to enable the Apache status module and view server statistics through a browser, including the number of server requests, runtime, thread status, etc., to determine the health status of Apache.
[0005] However, the two existing Apache health check methods mentioned above are limited in scope, lack comprehensiveness, and have poor versatility, making them unable to effectively identify deeper problems and risks. Summary of the Invention
[0006] In view of this, embodiments of the present invention provide a health check method and apparatus for servers to solve the problems of poor universality, limited check methods, and incomplete check content in existing health checks for Apache servers.
[0007] To address the above problems, embodiments of the present invention provide the following technical solutions:
[0008] The first aspect of this invention discloses a health check method for a server, the method comprising:
[0009] Check if the Apache process exists on the server to be checked;
[0010] If not, check whether historical baseline information within a set time period exists in the server to be checked;
[0011] If so, determine that the server to be checked is an abnormal Apache server, and output the abnormal result of the Apache server health check;
[0012] If it exists, the server to be checked is determined to be an Apache server;
[0013] Read the Apache configuration file of the Apache server;
[0014] The health check indicators of the Apache server are checked based on the configuration information in the Apache configuration file, and the corresponding check results are output.
[0015] Optionally, checking whether historical baseline information within a preset time period exists in the server to be checked includes:
[0016] Check whether there is a historical file in the server to be tested that records the historical baseline information of Apache, and whether the number of Apache http processes recorded in the historical file is greater than 0 within a preset time.
[0017] If the historical file does not exist, it is determined that the server to be tested is not an Apache server, and the check is exited;
[0018] If the historical file exists and the number of recorded Apache HTTP processes is greater than 0, the server to be checked is determined to be an abnormal Apache server.
[0019] Optionally, the health check indicators of the Apache server are checked based on the configuration information in the Apache configuration file, and the corresponding check results are output, including:
[0020] Determine the health check metrics to be checked for the Apache server, including one or any combination of Apache service status, Apache access success rate, Apache concurrency utilization, Apache thread busy rate, and Apache listener queue depth.
[0021] Obtain the information corresponding to the health check indicators, check the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and output the check results;
[0022] If there are multiple health check indicators, the check results for each health check indicator will be output.
[0023] Optionally, if the health check indicators include the Apache service status, the step of obtaining the information corresponding to the health check indicators, checking the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and outputting the check results includes:
[0024] Read the access logs for the first preset time period from the access logs;
[0025] The URL with the highest number of successful accesses recorded in the access log is identified.
[0026] Parse the Apache configuration file to obtain the Apache service listening address;
[0027] By concatenating the URL address and the Apache service listening address, an accessible URL address is obtained.
[0028] Perform a simulated access to the accessible URL address and determine whether the simulated HTTP return code matches the expected status code;
[0029] If the results match, output a check result indicating that the Apache server service status is normal.
[0030] If inconsistent, transmit the check results of the Apache server service status abnormality.
[0031] Optionally, if the health check metric includes Apache access success rate, the step involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check results, including:
[0032] Check if an access log file exists in the Apache default log path;
[0033] If it exists, read the HTTP return code of the corresponding Apache access request within the second preset time period in the access log;
[0034] If it does not exist, parse the Apache configuration file to obtain the new log path, and read the HTTP return code of the corresponding Apache access request within the second preset time period in the access log file based on the new log path;
[0035] The total number of HTTP return codes is counted as the access count, and the number of HTTP return codes greater than the preset return code is counted as the abnormal access record count.
[0036] The Apache access success rate is obtained by dividing the number of abnormal access records by the number of accesses, and then output.
[0037] Optionally, if the health check metric includes Apache concurrent usage, the step of obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check result includes:
[0038] Based on the Apache listening port configured in the Apache configuration file, obtain the current number of network connections of the Apache server;
[0039] Retrieve the maximum number of network connections configured in the Apache configuration file;
[0040] The Apache concurrency utilization rate is obtained by dividing the current number of network connections of the Apache server by the maximum number of network connections, and then output.
[0041] Optionally, if the health check metric includes Apache thread busy rate, the step involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check result, including:
[0042] Obtain the total number of HTTP processes / threads configured in the Apache configuration file;
[0043] Obtain the number of running HTTP processes / threads on the Apache server;
[0044] Calculate the ratio of the number of HTTP processes in the running state to the total number of HTTP processes / threads to obtain the Apache thread busy rate, and output it.
[0045] Optionally, if the health check metric includes the Apache listener queue depth, the step involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check result, including:
[0046] Based on the Apache listening port configured in the Apache configuration file, obtain the current full connection queue depth of the Apache server;
[0047] Determine whether the current fully connected queue depth is greater than a preset depth;
[0048] If the value is greater than 1, output the results of the Apache server error check.
[0049] If the result is not greater than the specified value, output the normal check result of the Apache server.
[0050] Optionally, after determining that the server to be inspected is an Apache server, the method further includes:
[0051] A baseline information file is created on the Apache server based on the Apache process.
[0052] The number of HTTP processes of the Apache server is recorded as historical baseline information in the baseline information file, and a time-to-live (TTL) is set for the number of HTTP processes; wherein the TTL is equal to the set time.
[0053] A second aspect of this invention discloses a health check device for a server, the device comprising:
[0054] The process check module is used to check whether an Apache process exists on the server to be checked. If it does not exist, the historical check module is executed; if it exists, the server to be checked is determined to be an Apache server, and the health check module is executed.
[0055] The historical check module is used to check whether there is historical baseline information in the server to be checked within a set time. If so, the server to be checked is determined to be an abnormal Apache server, and the output module is used to output the abnormal Apache server health check result.
[0056] The health check module is used to read the Apache configuration file of the Apache server; check the health check indicators of the Apache server based on the configuration information in the Apache configuration file; and output the corresponding check results using the output module.
[0057] The output module is used to output the inspection results.
[0058] Based on the above embodiments of the present invention, a server health check method and apparatus are provided. The method checks whether an Apache process exists on the server to be checked; if not, it checks whether historical baseline information within a set time period exists on the server to be checked; if so, it determines that the server to be checked is an abnormal Apache server and outputs an abnormal Apache server health check result; if it exists, it determines that the server to be checked is an Apache server; it reads the Apache configuration file of the Apache server; it checks the health check indicators of the Apache server based on the configuration information in the Apache configuration file and outputs the corresponding check results. In this embodiment of the invention, it is not necessary to pre-distinguish whether the server is a server deploying Apache. By temporarily storing historical Apache running information, it is possible to effectively distinguish between non-Apache servers and situations where Apache server service processes are not present, possessing good versatility and adaptability. During subsequent Apache-related checks, checks are performed based on comprehensive health check indicators, making the Apache health check content more complete and comprehensive, ensuring the reliability and sensitivity of the Apache health check. Therefore, the server health check method disclosed in this embodiment of the invention not only has strong versatility but also achieves the purpose of avoiding false alarms and effectively performing comprehensive checks. Attached Figure Description
[0059] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0060] Figure 1 This is a flowchart illustrating a server health check method disclosed in an embodiment of the present invention;
[0061] Figure 2 This is a schematic diagram of the structure of a server health check device disclosed in an embodiment of the present invention. Detailed Implementation
[0062] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0063] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0064] like Figure 1 The diagram shown is a flowchart illustrating a server health check method according to an embodiment of the present invention. This server health check method can be executed based on a pre-built script and mainly includes the following steps:
[0065] S101: Check if the Apache process exists on the server to be checked; if it does not exist, proceed to S102; if it exists, proceed to S104.
[0066] When executing S101, the server type of the service to be checked is not distinguished, and the check is performed indiscriminately on all servers to be checked. If an Apache process exists on the server currently being checked, then the server is determined to be an Apache server, and the check continues. If an Apache process does not exist on the server currently being checked, either it is indeed not an Apache server, or it has an anomaly, therefore S102 needs to be executed to continue the check.
[0067] S102: Check if there is historical baseline information within a set time period in the server to be checked; if yes, proceed to S103; otherwise, exit.
[0068] In S102, the historical baseline information is a file that records the number of processes most recently checked by Apache. Specifically,
[0069] In this embodiment of the invention, after each check, if an Apache process exists, the base number is recorded in the file. If no Apache process is found, the file is checked to see if it records the number of Apache processes within a set time period. That is, the file is checked to see if there is a record of an Apache process being started within the set time period.
[0070] For example, if the number of Apache processes is greater than 0 and the file was updated within the last 3 days, it means that there are related processes on this server within the last 3 days.
[0071] During the execution of S102, the system determines whether the server under inspection is an Apache server by checking whether there is historical baseline information within a set time period (whether there is a record of starting the Apache process within the set time period).
[0072] If historical baseline information exists within a set time period, the server to be checked is identified as an Apache server. However, since there is currently no Apache process, this situation may be due to the abnormal exit of the Apache process. Therefore, it can be confirmed that the service status of the server to be checked is abnormal, and step S103 is executed.
[0073] If no historical baseline information is available within the specified time period, it is determined that the server to be checked is not an Apache server. The absence of an Apache process is normal, so the subsequent Apache check can be exited.
[0074] In one embodiment of the present invention, the specific process of checking whether historical baseline information within a preset time period exists in the server to be checked is as follows:
[0075] First, check if there are historical files on the server to be tested that record Apache historical baseline information, and if the number of Apache HTTP processes recorded in the historical files is greater than 0 within a preset time period.
[0076] The preset time can be set according to the needs or requirements of the technicians. It is usually set to 3 days, but it can also be set to 2 days, 5 days or a week.
[0077] If no historical files are found, the server being tested is determined to be not an Apache server, and the test is exited.
[0078] If historical files exist and the number of recorded Apache HTTP processes is greater than 0, it is determined that the server under test started an Apache process within a preset time period, confirming that the server under test is an abnormal Apache server.
[0079] In one embodiment of the present invention, the process of checking whether historical baseline information within a preset time period exists in the server to be checked based on the program execution in the preset script is as follows:
[0080] local v_hist_file=$(find / tmp / -name“.apache.check.history”–mtime-3|head–n 1)
[0081] if[[-f${v_hist_file}&&$(cat${v_hist_file}–gt“0”)]]
[0082] then
[0083] The echo message "Error message: This server started the Apache server within the last week, but the Apache process does not exist in this check" indicates an error.
[0084] else
[0085] The echo message "Check successful: No Apache process exists on this server, no further Apache checks are required" indicates that the server is not performing any checks.
[0086] fi
[0087] S103: Determine that the server to be checked is an abnormal Apache server, and output the abnormal result of the Apache server health check.
[0088] S104: The server to be inspected is determined to be an Apache server.
[0089] In one embodiment of the present invention, after executing S104 to determine that the server to be inspected is an Apache server, the method further includes:
[0090] Create a baseline information file on the Apache server based on the Apache process.
[0091] The number of HTTP processes of the Apache server is recorded as historical baseline information in the baseline information file, and a time-to-live (TTL) is set for the number of HTTP processes; wherein the TTL is equal to the set time.
[0092] The baseline information file is created in the / tmp directory. This baseline information file is a temporary file that records the number of Apache httpd processes. It is updated when the time-to-live of the baseline information file is reached.
[0093] The survival time here is usually the same as the preset time and the set time mentioned above.
[0094] This baseline information file can be used as historical baseline information for subsequent inspections.
[0095] In one embodiment of the present invention, the temporary file can be created using the following specific command:
[0096] local v_num=$(ps–ef|grep–w “httpd”|grep–v “grep”|wc–l)
[0097] if[[${v_num}–gt“0”]]
[0098] then
[0099] echo "${v_num}> / tmp / .apache.check.history
[0100] fi
[0101] When the server health check is performed again (within a preset time), if the server is involved, regardless of whether the Apache process exists on the server, the number of Apache httpd processes recorded in this file can be used to determine that the server is an Apache server.
[0102] S105: Read the Apache configuration file of the Apache server.
[0103] In the specific implementation of S105, the Apache configuration file of the Apache server is read, and configuration information such as the Apache working mode, listening port, and MaxClints (the number of requests that the server can connect to simultaneously, i.e., the maximum number of connections) is collected from it.
[0104] Apache has three working modes: Prefork, worker, and event.
[0105] The Apache working mode can be obtained from the Apache configuration file in the following ways:
[0106] local v_exe=$(ps-ef|grep-w"httpd"|grep-v"grep"|grep-w"${v_pid}"|head-n 1|awk'{print$8}')
[0107] if[[-f${v_exe}&&! -z$(echo${v_exe}|grep-w"httpd")]]
[0108] then
[0109] local v_workmode=$(${v_exe}-V 2> / dev / null|grep"Server MPM:"|awk-F":"'{print$2}'|awk'{print$1}')
[0110] fi
[0111] The listening port configured for the Apache server can be obtained from the Apache configuration file by extracting the Listen field.
[0112] V_APC_CONF=" / etc / httpd / conf / httpd.conf"
[0113] local v_listen_port=$(cat-A${V_APC_CONF}|grep Listen|awk'{print$2}')
[0114] The maximum number of connections configured for the Apache server can be obtained from the Apache configuration file in the following ways:
[0115] V_APC_CONF=" / etc / httpd / conf / httpd.conf"
[0116] local v_max_clients=$(grep-Eiw"MaxClients|MaxRequestWorkers"${V_APC_CONF}|awk'{print$2}'|head-n1)
[0117] S106: Based on the configuration information in the Apache configuration file, check the health check indicators of the Apache server and output the corresponding check results.
[0118] In S106, the health check metrics for this Apache server are shown in Table 1 below.
[0119] Table 1:
[0120]
[0121] In the specific implementation of S106, the health check indicators to be checked include one or any combination of Apache service status, Apache access success rate, Apache concurrency usage, Apache thread busy rate, and Apache listener queue depth.
[0122] In one embodiment of the present invention, the health check indicators of the Apache server are checked based on the configuration information in the Apache configuration file, and the corresponding check results are output. The specific execution process includes:
[0123] First, determine the health check indicators to be checked for the Apache server, that is, determine the health check indicators to be checked.
[0124] Secondly, the information corresponding to the health check indicators is obtained, and the information corresponding to the health check indicators is checked based on the configuration information in the parsed Apache configuration file, and the check results are output.
[0125] If there are multiple health check indicators, the check results for each health check indicator will be output.
[0126] The process of examining each health check indicator is illustrated through the following example.
[0127] If the health check metric includes Apache access success rate, then obtain the information corresponding to the Apache access success rate, check the information corresponding to the Apache access success rate based on the configuration information in the parsed Apache configuration file, and output the check result.
[0128] In one embodiment of the present invention, the specific implementation process includes:
[0129] S201: Check if an access log file exists in the Apache default log path; if it exists, proceed to S202; if it does not exist, proceed to S203.
[0130] In the specific implementation of S201, the system checks if access.log exists in the Apache default log path. If it does, the system assumes that the access log file exists.
[0131] It should be noted that access.log defines the record for each Apache access request and the HTTP return code.
[0132] S202: Read the HTTP return codes of the corresponding Apache access requests within the second preset time period in the access log.
[0133] In S202, the second preset time period is usually a recent period of time, which can be set by a technician. Preferably, it can be within 1 day, or within 3 days or 5 days.
[0134] S203: Parse the Apache configuration file to obtain the new log path, and read the HTTP return codes of the corresponding Apache access requests within the second preset time period in the access log file based on the new log path.
[0135] In S203, the redefined log path is obtained by parsing the Apache configuration file and used as the new log path.
[0136] S204: Count the total number of HTTP return codes, recorded as the access count, and count the number of HTTP return codes greater than the preset return code, recorded as the abnormal access record count.
[0137] In S204, access.log defines each Apache access request record and its HTTP return code. A return code >= 500 indicates a server error, and such errors are considered failed transactions.
[0138] S205: Divide the number of abnormal access records by the number of accesses to obtain the Apache access success rate and output it.
[0139] In the specific implementation of S205, the access success rate is calculated by dividing the number of abnormal accesses by the total number of accesses.
[0140] For example, if the most recent 500 access records are extracted from access.log, and 200 records with return codes greater than 500 are found, then the access success rate is: (200 / 500)*100% = 40%.
[0141] If the health check indicators to be checked include the Apache service status, then obtain the information corresponding to the Apache service status, check the information corresponding to the Apache service status based on the configuration information in the parsed Apache configuration file, and output the check results.
[0142] In one embodiment of the present invention, the specific process is as follows:
[0143] S301: Read the access logs for the first preset time period from the access logs.
[0144] In S301, the first preset time period is usually a recent period of time, which can be set by a technician. Preferably, it can be within 1 day, or within 3 days or 5 days.
[0145] S302: Count the URL address with the highest number of successful accesses recorded in the access log.
[0146] S303: Parse the Apache configuration file to obtain the Apache service listening address.
[0147] S304: Concatenate the URL address and the Apache service listening address to obtain an accessible URL address.
[0148] S305: Perform a simulated access to the accessible URL address and determine whether the simulated HTTP return code matches the expected status code; if they match, proceed to S306; if they do not match, proceed to S307.
[0149] S306: Outputs the check results indicating that the Apache server service status is normal.
[0150] S307: Transmit the results of an Apache server service status check for abnormalities.
[0151] If the health check metric includes Apache concurrent usage, then obtain the information corresponding to the Apache concurrent usage, check the information corresponding to the Apache concurrent usage based on the configuration information in the parsed Apache configuration file, and output the check result.
[0152] In one embodiment of the present invention, the specific execution process is as follows:
[0153] S401: Based on the Apache listening port configured in the Apache configuration file, obtain the current number of network connections of the Apache server.
[0154] In the specific implementation of S401, the Apache listening port (v_listen_port) is obtained through the configuration file, and the number of network connections established to the Apache server is obtained through the following command.
[0155] local v_conn_num=$(ss-ant|grep-vE"LISTEN|State"|grep"ESTAB"|awk'{print$4}'|grep-E":(${v_listen_port})"|wc-l)
[0156] S402: Get the maximum number of network connections configured in the Apache configuration file.
[0157] In the specific implementation of S401, the maximum number of network connections configured by Apache (v_max_clients) is obtained through the configuration file.
[0158] S403: Divide the current number of network connections of the Apache server by the maximum number of network connections to obtain the Apache concurrency utilization rate and output it.
[0159] In the actual implementation of S403, the Apache concurrency utilization is calculated using the following command:
[0160] local v_conn_ratio=$(echo "${v_conn_num}*100 / ${v_max_clients}"|bc)
[0161] If the health check indicators include Apache thread busy rate, then obtain the information corresponding to the Apache thread busy rate, check the information corresponding to the Apache thread busy rate based on the configuration information in the parsed Apache configuration file, and output the check results.
[0162] It should be noted that the Apache thread busy rate is calculated based on the number of processes in profork mode, and based on the number of threads in work mode.
[0163] In one embodiment of the present invention, the specific execution process is as follows:
[0164] S501: Get the total number of HTTP processes / threads configured in the Apache configuration file.
[0165] S502: Obtain the number of HTTP processes / threads that are running on the Apache server.
[0166] S503: Calculate the ratio of the number of HTTP processes in the running state to the total number of HTTP processes / threads to obtain the Apache thread busy rate, and output it.
[0167] In one embodiment of the present invention, the specific execution process is as follows: obtain the number of started Apache processes / threads and the number of processes / threads in the running state, calculate the proportion of running processes / threads in the total number of processes / threads, and obtain the Apache thread busy rate.
[0168] If the health check indicator includes the Apache listener queue depth, then the information corresponding to the Apache listener queue depth is obtained, and the information corresponding to the Apache listener queue depth is checked based on the configuration information in the parsed Apache configuration file. The check results are then output, including:
[0169] S601: Based on the Apache listening port configured in the Apache configuration file, obtain the current full connection queue depth of the Apache server.
[0170] In S601, the Apache listener queue depth can be obtained using the netstat / ss command.
[0171] S602: Determine whether the current fully connected queue depth is greater than a preset depth; if it is greater, execute S603; if it is not greater, execute S604.
[0172] S603: Outputs the results of Apache server error checks.
[0173] S604: Outputs the results of a normal Apache server check.
[0174] In the server health check method disclosed in this invention, the currently running processes and recent historical records of the server under inspection are checked indiscriminately. Based on this, it is first determined whether the server under inspection needs to perform Apache-related checks, without prior differentiation as to whether the server is a server with Apache deployed. By temporarily storing Apache historical running information, it is possible to effectively distinguish between non-Apache servers and situations where Apache server service processes are not present, exhibiting good versatility and adaptability. During subsequent Apache-related checks, checks are performed based on comprehensive health check indicators, making the Apache health check content more thorough and complete, ensuring the reliability and sensitivity of the Apache health check. Therefore, the server health check method disclosed in this invention not only has strong versatility but also achieves the goal of avoiding false alarms and effectively performing comprehensive checks.
[0175] Based on the server health check method disclosed in the above embodiments of the present invention, the present invention also discloses a server health check device, such as... Figure 2 As shown, the health check device includes a process check module 21, a history check module 22, a health check module 23, and an output module 24.
[0176] The process check module 21 is used to check whether there is an Apache process on the server to be checked. If it does not exist, the history check module 22 is executed; if it exists, the server to be checked is determined to be an Apache server, and the health check module 23 is executed.
[0177] In one embodiment of the present invention, the health check device further includes a temporary file creation module; after the process check module 21 determines that the server to be checked is an Apache server, the temporary file creation module creates a baseline information file on the Apache server based on the Apache process; records the number of HTTP processes of the Apache server as historical baseline information in the baseline information file, and sets a lifespan for the number of HTTP processes; wherein the lifespan is equal to the set time.
[0178] The historical check module 22 is used to check whether there is historical baseline information in the server to be checked within a set time. If so, the server to be checked is determined to be an abnormal Apache server, and the output module 24 is used to output the abnormal result of the Apache server health check.
[0179] The history check module 22 is specifically used to check whether there is a historical file recording Apache historical baseline information in the server to be checked, and whether the number of Apache HTTP processes recorded in the historical file is greater than 0 within a preset time. If there is no historical file, it is determined that the server to be checked is not an Apache server and the check is exited. If there is a historical file and the number of Apache HTTP processes recorded is greater than 0, it is determined that the server to be checked is an abnormal Apache server.
[0180] The health check module 23 is used to read the Apache configuration file of the Apache server; check the health check indicators of the Apache server based on the configuration information in the Apache configuration file; and output the corresponding check results using the output module 24.
[0181] Output module 24 is used to output the inspection results.
[0182] The health check module 23 is specifically used to determine the health check indicators of the Apache server to be checked. The health check indicators include one or any combination of Apache service status, Apache access success rate, Apache concurrency utilization, Apache thread busy rate, and Apache listener queue depth. It obtains the information corresponding to the health check indicators, checks the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and outputs the check results. If there are multiple health check indicators, the check results of each health check indicator are output.
[0183] In one embodiment of the present invention, if the health check indicators include the Apache service status, the health check module 23 is specifically used for:
[0184] The system reads access logs from the access logs within a first preset time period; it then identifies the URL with the highest number of successful accesses recorded in the access logs; it parses the Apache configuration file to obtain the Apache service listening address; it concatenates the URL address and the Apache service listening address to obtain an accessible URL address; it performs a simulated access to the accessible URL address and determines whether the simulated HTTP return code matches the expected status code; if they match, it outputs a check result indicating that the Apache server service status is normal; otherwise, it transmits a check result indicating that the Apache server service status is abnormal.
[0185] In one embodiment of the present invention, if the health check indicators include Apache access success rate, the health check module 23 is specifically used for:
[0186] The system checks if an access log file exists in the Apache default log path. If it exists, it reads the HTTP return codes of the corresponding Apache access requests within a second preset time period from the access log. If it does not exist, it parses the Apache configuration file to obtain a new log path and reads the HTTP return codes of the corresponding Apache access requests within the second preset time period from the access log file based on the new log path. The system counts the total number of HTTP return codes, which is recorded as the access count, and counts the number of HTTP return codes greater than a preset return code, which is recorded as the abnormal access record count. The system divides the abnormal access record count by the access count to obtain the Apache access success rate, and outputs it.
[0187] In one embodiment of the present invention, if the health check indicators include Apache concurrent usage, the health check module 23 is specifically used for:
[0188] Based on the Apache listening port configured in the Apache configuration file, obtain the current number of network connections of the Apache server; obtain the maximum number of network connections configured in the Apache configuration file; divide the current number of network connections of the Apache server by the maximum number of network connections to obtain the Apache concurrency utilization rate, and output it.
[0189] In one embodiment of the present invention, if the health check indicators include Apache thread busy rate, the health check module 23 is specifically used for:
[0190] Obtain the total number of HTTP processes / threads configured in the Apache configuration file; obtain the number of HTTP processes / threads that are running on the Apache server; calculate the ratio of the number of running HTTP processes / threads to the total number of HTTP processes / threads to obtain the Apache thread busy rate, and output it.
[0191] In one embodiment of the present invention, if the health check metric includes the Apache listener queue depth, the health check module 23 is specifically used for:
[0192] Based on the Apache listening port configured in the Apache configuration file, obtain the current full connection queue depth of the Apache server; determine whether the current full connection queue depth is greater than a preset depth; if it is greater, output the Apache server error check result; if it is not greater, output the Apache server normal check result.
[0193] The specific execution process and principle of each module in the health check device of the server disclosed in the embodiments of the present invention can be found in the corresponding content of the health check method disclosed in the above embodiments of the present invention.
[0194] In the server health check apparatus disclosed in this embodiment of the invention, there is no need to pre-distinguish whether the server is a server with Apache deployed. By temporarily storing historical Apache running information, it can effectively distinguish between non-Apache servers and situations where Apache server service processes are not present, exhibiting excellent versatility and adaptability. During subsequent Apache-related checks, checks are performed based on comprehensive health check indicators, making the Apache health check content more thorough and complete, ensuring the reliability and sensitivity of the Apache health check. Therefore, the server health check method disclosed in this embodiment of the invention not only has strong versatility but also achieves the goal of avoiding false alarms and effectively performing comprehensive checks.
[0195] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0196] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0197] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for checking the health of a server, characterized in that, The method includes: Check if the Apache process exists on the server to be checked; If not, check whether historical baseline information within a set time period exists in the server to be checked; If so, determine that the server to be checked is an abnormal Apache server, and output the abnormal result of the Apache server health check; If it exists, the server to be checked is determined to be an Apache server; Read the Apache configuration file of the Apache server; The health check indicators of the Apache server are checked based on the configuration information in the Apache configuration file, and the corresponding check results are output. The process of checking whether historical baseline information within a set time period exists in the server to be checked includes: Check whether there is a historical file in the server to be checked that records the historical baseline information of Apache, and whether the number of Apache http processes recorded in the historical file is greater than 0 within a set time period; If the historical file does not exist, it is determined that the server to be checked is not an Apache server, and the check is exited; If the historical file exists and the number of recorded Apache HTTP processes is greater than 0, the server to be checked is determined to be an abnormal Apache server. The health check indicators of the Apache server are checked based on the configuration information in the Apache configuration file, and the corresponding check results are output, including: Determine the health check metrics for the Apache server to be checked, including one or any combination of Apache service status, Apache access success rate, Apache concurrency utilization, Apache thread busy rate, and Apache listener queue depth. Obtain the information corresponding to the health check indicators, check the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and output the check results; If there are multiple health check indicators, the check results for each health check indicator will be output.
2. The method according to claim 1, characterized in that, If the health check indicators include the Apache service status, the process involves obtaining the information corresponding to the health check indicators, checking the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and outputting the check results, including: Read the access logs for the first preset time period from the access logs; The URL with the highest number of successful accesses recorded in the access log is identified. Parse the Apache configuration file to obtain the Apache service listening address; By concatenating the URL address and the Apache service listening address, an accessible URL address is obtained. Perform a simulated access to the accessible URL address and determine whether the simulated HTTP return code matches the expected status code; If the results match, output a check result indicating that the Apache server service status is normal. If inconsistent, transmit the check results of the Apache server service status abnormality.
3. The method according to claim 1, characterized in that, If the health check metric includes Apache access success rate, the process involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check results, including: Check if an access log file exists in the Apache default log path; If it exists, read the HTTP return code of the corresponding Apache access request within the second preset time period in the access log; If it does not exist, parse the Apache configuration file to obtain the new log path, and read the HTTP return code of the corresponding Apache access request within the second preset time period in the access log file based on the new log path; The total number of HTTP return codes is counted as the access count, and the number of HTTP return codes greater than the preset return code is counted as the abnormal access record count. The Apache access success rate is obtained by dividing the number of abnormal access records by the number of accesses, and then output.
4. The method according to claim 1, characterized in that, If the health check metric includes Apache concurrent usage, the process involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check results, including: Based on the Apache listening port configured in the Apache configuration file, obtain the current number of network connections of the Apache server; Retrieve the maximum number of network connections configured in the Apache configuration file; The Apache concurrency utilization rate is obtained by dividing the current number of network connections of the Apache server by the maximum number of network connections, and then output.
5. The method according to claim 1, characterized in that, If the health check metric includes Apache thread busy rate, the process involves obtaining the information corresponding to the health check metric, checking the information corresponding to the health check metric based on the configuration information in the parsed Apache configuration file, and outputting the check results, including: Obtain the total number of HTTP processes / threads configured in the Apache configuration file; Obtain the number of running HTTP processes / threads on the Apache server; Calculate the ratio of the number of HTTP processes / threads in the running state to the total number of HTTP processes / threads to obtain the Apache thread busy rate, and output it.
6. The method according to claim 1, characterized in that, If the health check metric includes the Apache listener queue depth, the process involves obtaining the information corresponding to the health check metric, checking the information based on the configuration information in the parsed Apache configuration file, and outputting the check results, including: Based on the Apache listening port configured in the Apache configuration file, obtain the current full connection queue depth of the Apache server; Determine whether the current fully connected queue depth is greater than a preset depth; If the value is greater than 1, output the results of the Apache server error check. If the result is not greater than the specified value, output the normal check result of the Apache server.
7. The method according to any one of claims 1 to 6, characterized in that, After determining that the server to be inspected is an Apache server, the process also includes: A baseline information file is created on the Apache server based on the Apache process. The number of HTTP processes of the Apache server is recorded as historical baseline information in the baseline information file, and a time-to-live (TTL) is set for the number of HTTP processes; wherein the TTL is equal to the set time.
8. A health check device for a server, characterized in that, The device includes: The process check module is used to check whether an Apache process exists on the server to be checked. If it does not exist, the historical check module is executed; if it exists, the server to be checked is determined to be an Apache server, and the health check module is executed. The historical check module is used to check whether there is historical baseline information in the server to be checked within a set time. If so, the server to be checked is determined to be an abnormal Apache server, and the output module is used to output the abnormal Apache server health check result. The health check module is used to read the Apache configuration file of the Apache server; check the health check indicators of the Apache server based on the configuration information in the Apache configuration file; and output the corresponding check results using the output module. The output module is used to output the inspection results; Specifically, the history check module is used to check whether there is a historical file recording Apache historical baseline information in the server to be checked, and whether the number of Apache HTTP processes recorded in the historical file is greater than 0 within a set time. If there is no historical file, it is determined that the server to be checked is not an Apache server and the check is terminated. If there is a historical file and the number of Apache HTTP processes recorded is greater than 0, it is determined that the server to be checked is an abnormal Apache server. The health check module is specifically used to determine the health check indicators of the Apache server to be checked. The health check indicators include one or any combination of Apache service status, Apache access success rate, Apache concurrency utilization, Apache thread busy rate, and Apache listener queue depth. It obtains the information corresponding to the health check indicators, checks the information corresponding to the health check indicators based on the configuration information in the parsed Apache configuration file, and outputs the check results. If there are multiple health check indicators, it outputs the check results for each health check indicator.
Citation Information
Patent Citations
Server health degree analysis method and device, storage medium and electronic equipment
CN109800139A
Magnetic field baseline self-maintenance method and device, computer equipment and storage medium
CN111653104A