Method and device for detecting service state of nacos management and realizing service batch restart

Through packet capture analysis and python crawling technology, Nacos interface request is simulated, combined with paramiko package, the automatic login and restart of service nodes is solved, and the efficiency of manual restart of microservice applications is achieved in the event of failure is achieved, and the efficient service batch restart function is realized.

CN119537090APending Publication Date: 2025-02-28CHINA UNITECHS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311085299.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-28
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In traditional operation and maintenance work, microservice applications are deployed in virtual machines. When a service failure occurs, it is necessary to manually find the server where the service is located through Nacos and restart one by one. It is time-consuming and manual intensive, and there is a lack of an efficient solution for one-click restart.

Method used

By capturing packets, analyzing the interface request of the Nacos Registration Center, using python crawler simulation interface request to obtain service node information, and implement service status monitoring. Provide command line dialogue to allow users to enter services and nodes that need to be restarted, use the paramiko package to log in to the server one by one, and obtain ports and process numbers through Nacos to achieve service restart.

Benefits of technology

It realizes the function of restarting all services with one click, efficiently solves the problem of batch restarting services, and significantly improves operation and maintenance work efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119537090A_ABST
    Figure CN119537090A_ABST
Patent Text Reader

Abstract

The invention provides a method and device for detecting the service state of nacos management and achieving batch restart of services, and the method comprises the steps: obtaining an interface address during nacos login and data sent when the address is requested through a crawler capture package analysis result, and simulating and requesting the interface to carry out nacos login through a post method of requests; after login succeeds, all service name information registered in the nacos is obtained through crawler package capture analysis; querying registration information of the service in the nacos through a service name input by a user, and obtaining a service state of the service registered to each node in the nacos; the service of the IP address needing to be restarted is obtained through information input by a user, a server is logged in according to the address, and the service is restarted after the process where the service is located is inquired through a port. In this way, the port automatically completes the operations of logging in the server, finding the program process and restarting the service only by inputting the service address needing to be restarted, so that the time of operation and maintenance personnel is saved, and the working efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention generally relate to the field of computer software technology, and more particularly to a method and device for detecting the service status of nacos management and implementing batch restart of services. Background Art

[0002] In traditional operation and maintenance work, microservice applications are deployed in virtual machines. Under this architecture, there are often 20 to 30 virtual machines, or dozens or hundreds of them. Microservice applications range from dozens to hundreds. When deploying applications in cluster mode, multiple nodes of the program are scattered on different servers. It is easy to lose records when using Excel to record, and it is not convenient to update in time. At this time, there is a nacos registration center (nacos is an existing third-party middleware program used to record microservice addresses, ports, status and other information). With the nacos registration center, nacos can be used to record the server addresses of all microservices. However, when there is a fault in the microservice program and a batch restart is required, it is necessary to use nacos to find the server where the microservice is located, and then log in to the server one by one, find the directory where the service is located, and enter the command to restart the service. This operation takes a lot of time and manpower, so a method is needed to restart all services with one click. Summary of the invention

[0003] To solve the above problems, the present invention analyzes the login of the nacos registration center, the acquisition of all service information, the interface request address, interface data, and return data of the registration information of a single service through packet capture, and uses a python crawler to simulate interface requests and obtain the node information of the service, thereby completing the status monitoring of each node; provides a command line for user dialogue, and the user decides the service and service node that need to be restarted, and then uses python's paramiko third-party package to log in to the server where the service to be restarted is located one by one, and then uses the service port found out from nacos to find the process number of the service, and completes the restart according to the process number. The function of restarting all services with one click is realized, the problem of batch restarting services is efficiently solved, and work efficiency is improved.

[0004] According to an embodiment of the present invention, a method and device for detecting the service status managed by nacos and implementing batch restart of services are provided.

[0005] In a first aspect of the present invention, a method for detecting the service status of nacos management and implementing batch restart of services is provided. The method comprises:

[0006] S01: Use the crawler to capture the packet analysis results to obtain the interface address when nacos logs in and the data sent when requesting the address. Use Python's third-party dependency package requests to write a program to simulate calling the interface, construct the headers array, url address and post array when requesting the http interface, and use the post method of requests to simulate requesting the interface for nacos login;

[0007] S02: After simulating a successful nacos login, obtain all service name information registered in nacos through crawler packet capture analysis;

[0008] S03: Provide a command line dialogue, query the registration information of the service in nacos through the service name entered by the user, and obtain the service status of each node registered in nacos by the service;

[0009] S04: Provide a command line dialogue, obtain the service of the IP address that needs to be restarted through the information input by the user, log in to the server according to the address, and restart the service after querying the process where the service is located through the port.

[0010] Furthermore, the specific steps of S03 are:

[0011] S031: Provide a command line dialogue and ask the user to enter the service name that needs to be restarted;

[0012] S032: Query the registration information of the service in nacos according to the input service name, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis. The data returned by the interface is in json format;

[0013] S033: Assign the data returned by the interface to the variable listData, access the data under the list node through listData and read the list node data in a loop to obtain the address information, port information, service status and health status of each node registered by the service in nacos;

[0014] S034: The address information, port information, service status and health status of each node registered with the service in nacos are formatted and output for presentation.

[0015] Furthermore, the command line dialogue described in S04 has three input modes: if one service node needs to be restarted, enter the IP:Port; if multiple service nodes need to be restarted, enter multiple IP:Port separated by commas; if all service nodes need to be restarted, enter all.

[0016] Furthermore, after obtaining the service of the IP address that needs to be restarted as described in S04, it is determined whether the node information input by the user contains "all". If so, the address of each service node is directly logged in in a loop; if not, the information separated by English commas is split and an array of node information is obtained, and finally the array is looped to log in to the address of each service node.

[0017] Furthermore, the specific steps of restarting the service described in S04 are:

[0018] S041: After logging in to the server through ssh using paramiko, execute the command to query the process number of the port occupied to find the process number of the service entered by the user;

[0019] S042: Execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services. Compare the process number obtained in S041 with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number.

[0020] S043: Execute the "supervisorctl restart service name" command to restart the service.

[0021] In a second aspect of the present invention, a device for detecting the service status of nacos management and implementing batch restart of services is provided. The device comprises:

[0022] Login module: used to obtain the interface address of nacos login and the data sent when requesting the address through the crawler packet analysis results, use python's third-party dependency package requests to write a program to simulate the interface call, construct the headers array, url address and post array when requesting the http interface, and simulate the request for the interface to log in to nacos through the post method of requests;

[0023] Acquisition module: used to simulate the successful login of nacos and obtain all service name information registered in nacos through crawler packet analysis;

[0024] Query module: used to provide command line dialogue, query the registration information of the service in nacos through the service name entered by the user, and obtain the service status of each node registered in nacos;

[0025] Restart module: used to provide command line dialogue, obtain the service of the IP address that needs to be restarted through the information entered by the user, log in to the server according to the address, and restart the service after querying the process where the service is located through the port.

[0026] Furthermore, the query module includes:

[0027] Input module: used to provide command line dialogue, asking users to enter the service name that needs to be restarted;

[0028] Data return module: used to query the registration information of the service in nacos according to the input service name, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis. The data returned by the interface is in json format;

[0029] Status acquisition module: used to assign the data returned by the interface to the variable listData, access the data under the list node through listData and read the list node data in a loop to obtain the address information, port information, service status and health status of each node registered by the service in nacos;

[0030] Status presentation module: used to format and output the address information, port information, service status and health status of each node registered with the service in nacos.

[0031] Furthermore, there are three input methods for the command line dialogue described in the restart module: if you need to restart a service node, enter the IP:Port; if you need to restart multiple service nodes, enter multiple IP:Port separated by English commas; if you need to restart all service nodes, enter all.

[0032] Furthermore, after obtaining the service of the IP address that needs to be restarted in the restart module, it is determined whether the node information input by the user contains "all". If it does, the address of each service node is directly logged in in a loop; if it does not contain "all", the information separated by English commas is split and an array of node information is obtained, and finally the array is looped to log in to the address of each service node.

[0033] Furthermore, the restart module includes:

[0034] Process ID acquisition module: used to log in to the server through SSH through paramiko, and then execute the process ID command to query the process ID of the port occupied to find the process ID of the service entered by the user;

[0035] Service name acquisition module: used to execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services. The process number obtained by the process number acquisition module is compared with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number.

[0036] Restart execution module: used to execute the "supervisorctl restart service name" command to restart the service.

[0037] The meanings of the above mentioned English abbreviations:

[0038] Python: an object-oriented interpreted computer programming language

[0039] nacos: Dynamic Naming and Configuration Service, an open source distributed service discovery and configuration management platform that provides service registration, discovery, configuration and metadata management functions requests: a Python http client library

[0040] http:Hypertext Transfer Protocol, Hypertext Transfer Protocol

[0041] headers: http request headers

[0042] url: uniform resource locator, uniform resource locator system

[0043] post: http request method IP: Internet Protocol, Internet Protocol

[0044] json: JavaScript Object Notation, a lightweight data exchange format

[0045] listData: variables defined in the program

[0046] Port: Port

[0047] paramiko: a third-party library for Python

[0048] ssh: Secure Shell, Secure Shell Protocol

[0049] The present invention captures packets to analyze the interface request address, interface data, and return data of the login of the nacos registration center, the acquisition of all service information, and the registration information of a single service, and uses a python crawler to simulate interface requests and obtain the node information of the service, thereby completing the status monitoring of each node; provides a command line for user dialogue, and the user decides the service and service node to be restarted, and then uses the paramiko third-party package of python to log in to the servers where the services to be restarted are located one by one, and then uses the service port found out from nacos to find the process number of the service, and finds the service name according to the process number to complete the restart, thereby realizing the function of restarting all services with one key, effectively solving the problem of restarting services in batches, and improving work efficiency.

[0050] It should be understood that the contents described in the summary of the invention are not intended to limit the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The above and other features, advantages and aspects of the embodiments of the present invention will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings.

[0052] Figure 1 A flow chart of a method for detecting the service status of nacos management and implementing batch restart of services according to an embodiment of the present invention is shown;

[0053] Figure 2 A block diagram of a device for detecting the service status managed by nacos and implementing batch restart of services according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments 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.

[0055] According to the implementation mode of the present invention, a method and device for detecting the service status managed by nacos and realizing batch restart of services are proposed. By capturing packets and analyzing the login of the nacos registration center, obtaining all service information, and obtaining the interface request address, interface data, and return data of the registration information of a single service, the interface request is simulated by a python crawler method to obtain the node information of the service, thereby completing the status monitoring of each node; a command line for user dialogue is provided, and the user decides the services and service nodes that need to be restarted, and then uses the paramiko third-party package of python to log in to the servers where the services that need to be restarted are located one by one, and then uses the service port found from nacos to find the process number of the service, and completes the restart according to the process number. The function of restarting all services with one click is realized, which effectively solves the problem of batch restarting services and improves work efficiency.

[0056] The principle and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.

[0057] Figure 1 The present invention is a flow chart of a method for detecting the service status of nacos management and implementing batch restart of services according to an embodiment of the present invention. The method comprises:

[0058] S01: Use the crawler to capture the packet analysis results to obtain the interface address when nacos logs in and the data sent when requesting the address. Use Python's third-party dependency package requests to write a program to simulate calling the interface, construct the headers array, url address and post array when requesting the http interface, and use the post method of requests to simulate requesting the interface for nacos login;

[0059] S02: After simulating a successful nacos login, obtain all service name information registered in nacos through crawler packet capture analysis;

[0060] S03: Provide a command line dialogue, query the registration information of the service in nacos through the service name entered by the user, and obtain the service status of each node registered in nacos by the service;

[0061] S04: Provide a command line dialogue, obtain the service of the IP address that needs to be restarted through the information input by the user, log in to the server according to the address, and restart the service after querying the process where the service is located through the port.

[0062] It should be noted that, although the operations of the method of the present invention are described in a specific order in the above embodiments and the accompanying drawings, this does not require or imply that the operations must be performed in the specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0063] In order to explain more clearly the method for detecting the service status managed by nacos and realizing batch restart of services, three specific embodiments are described below. However, it is worth noting that the embodiments are only for better illustrating the present invention and do not constitute improper limitation of the present invention.

[0064] The following three specific examples further illustrate the method of detecting the service status of nacos management and implementing batch restart of services:

[0065] Embodiment 1:

[0066] There are 3 microservices. The nacos registration center records the server addresses of all microservices, as shown in Table 1:

[0067] Table 1

[0068] Microservice Name The address of the server check-service 192.168.20.20、192.168.20.21、192.168.20.22 alarm-service 192.168.20.30、192.168.20.31、192.168.20.32 email-service 192.168.20.40、192.168.20.41、192.168.20.42

[0069] The results of the crawler packet capture analysis are used to obtain the interface address of nacos login and the data sent when requesting the address. The third-party dependency package requests of python is used to write a program to simulate the interface call. According to the packet capture analysis, the interface address during login is: http: / / 192.168.20.8:8848 / nacos / v1 / auth / users / login.

[0070] According to the packet capture results, the headers array, URL address and post array of the http interface request are constructed, and the post method of requests is used to simulate the request for the interface to log in to nacos.

[0071] After simulating a successful nacos login, all service name information registered in nacos is obtained through crawler packet analysis.

[0072] According to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / services?hasIpCount=true&withInstances=false&pageNo=1&pageSize=100&serviceNameParam=&groupNameParam=&accessToken=%s&namespaceId=. The data returned by the interface is in a json format. We assign this part of the data to the variable serviceData.

[0073]

[0074]

[0075] We assign this part of data to the serviceData variable, and get the data under the serviceList node through serviceData["serviceList"]. Then we read the serviceList node data in a loop, read the value of the name node, and finally format the output to present the service name information of all services registered in nacos. The service list is shown in Table 2:

[0076] Table 2

[0077] Serial number Service Name 1 check-service 2 alarm-service 3 email-service

[0078] A command line dialog is provided, asking the user to enter the name of the service that needs to be restarted. The user enters: check-service.

[0079] According to the input service name, query the registration information of the service in nacos, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis; according to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / instances?&accessToken=%s&serviceName=check-service&clusterName=DEFAULT&groupName=DEFAULT_GROUP&pageSize=100&pageNo=1&namespaceId=, the data returned by the interface is also in json format, here we assign this part of the data to the variable listData, after simplification, the data sample is as follows:

[0080]

[0081]

[0082] We assign the data to the listData variable, then we can access the data under the list node through listData["list"]. Often a service is deployed in a cluster and there will be multiple nodes. So the packet capture result shows that there are multiple data under the list node. So we read the list node data in a loop to get the values ​​of the ip, port, healthy, and enabled nodes, and thus get the address information, port information, service status, and health status information of each node registered in nacos by the service. We also implement the detection of the service status and finally format the output for presentation, as shown in Table 3, where True represents healthy or normal, False represents unhealthy or abnormal, and the service is unavailable.

[0083] Table 3

[0084] IP port healthy enabled 192.168.20.20 8888 True True 192.168.20.21 8888 True True 192.168.20.22 8888 True False

[0085] Provides a command line dialogue to obtain the service of the IP address that needs to be restarted through the information entered by the user. Three input methods are provided here. When only one service node needs to be restarted, enter it in the format of IP:Port. When multiple nodes need to be entered, separate them with English commas. If all nodes need to be restarted, just enter all.

[0086] User input: 192.168.20.20:8888.

[0087] After obtaining the service that the user needs to restart, the code determines whether the node information entered by the user contains "all". If "all" is not included, the specified single service node or multiple nodes are restarted. The input information is separated by English commas: serviceList.split(",",). This line of code will be separated by English commas to obtain an array of node information: ["192.168.20.20:8888"], and finally the array is looped to the address of the login node 192.168.20.20. After ssh login to the server through paramiko, execute the netstat-anp|grep 8888|head-1|awk'{print$7}'|cut-d' / '-f 1 command to find the process number of the service entered by the user: 3777, and then execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services, as shown in Table 4:

[0088] Table 4

[0089] Microservice Name Process number check-service 3777 alarm-service 3778 email-service 3779

[0090] Compare the obtained process number with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number: check-service. Run the "supervisorctl restart check-service" command to restart the service.

[0091] Embodiment 2:

[0092] There are 3 microservices. The nacos registration center records the server addresses of all microservices, as shown in Table 5:

[0093] Table 5

[0094] Microservice Name The address of the server check-service 192.168.20.20、192.168.20.21、192.168.20.22 alarm-service 192.168.20.30、192.168.20.31、192.168.20.32 email-service 192.168.20.40、192.168.20.41、192.168.20.42

[0095] The results of the crawler packet capture analysis are used to obtain the interface address of nacos login and the data sent when requesting the address. The third-party dependency package requests of python is used to write a program to simulate the interface call. According to the packet capture analysis, the interface address during login is: http: / / 192.168.20.8:8848 / nacos / v1 / auth / users / login.

[0096] According to the packet capture results, the headers array, URL address and post array of the http interface request are constructed, and the post method of requests is used to simulate the request for the interface to log in to nacos.

[0097] After simulating a successful nacos login, all service name information registered in nacos is obtained through crawler packet analysis.

[0098] According to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / services?hasIpCount=true&withInstances=false&pageNo=1&pageSize=100&serviceNameParam=&groupNameParam=&accessToken=%s&namespaceId=. The data returned by the interface is in a json format. We assign this part of the data to the variable serviceData.

[0099]

[0100]

[0101] We assign this part of data to the serviceData variable, and get the data under the serviceList node through serviceData["serviceList"]. Then we read the serviceList node data in a loop, read the value of the name node, and finally format the output to present the service name information of all services registered in nacos. The service list is shown in Table 6:

[0102] Table 6

[0103] Serial number Service Name 1 check-service 2 alarm-service 3 email-service

[0104] A command line dialog is provided, asking the user to enter the name of the service that needs to be restarted. The user enters: check-service.

[0105] According to the input service name, query the registration information of the service in nacos, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis; according to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / instances?&accessToken=%s&serviceName=check-service&clusterName=DEFAULT&groupName=DEFAULT_GROUP&pageSize=100&pageNo=1&namespaceId=, the data returned by the interface is also in a json format, here we assign this part of the data to the variable listData, because the data fields are too many and inconvenient to present, after simplification, the data sample is as follows:

[0106]

[0107]

[0108] We assign the data to the listData variable, then we can access the data under the list node through listData["list"]. Often a service is deployed in a cluster and there will be multiple nodes. So the packet capture result shows that there are multiple data under the list node. So we read the list node data in a loop to get the values ​​of the ip, port, healthy, and enabled nodes, and thus get the address information, port information, service status, and health status information of each node registered in nacos by the service. We also implement the detection of the service status and finally format the output for presentation, as shown in Table 7, where True represents healthy or normal, False represents unhealthy or abnormal, and the service is unavailable.

[0109] Table 7

[0110] IP port healthy enabled 192.168.20.20 8888 False True 192.168.20.21 8888 True True 192.168.20.22 8888 True False

[0111] Provides a command line dialogue to obtain the service of the IP address that needs to be restarted through the information entered by the user. Three input methods are provided here. When only one service node needs to be restarted, enter it in the format of IP:Port. When multiple nodes need to be entered, separate them with English commas. If all nodes need to be restarted, just enter all.

[0112] User input: 192.168.20.20:8888,192.168.20.22:8888.

[0113] After obtaining the service that the user needs to restart, the code determines whether the node information entered by the user contains "all". If there is no "all", the specified single service node or multiple nodes are restarted. The input information is separated by English commas: serviceList.split(",). This line of code will be separated by English commas to obtain an array of node information: ["192.168.20.20:8888", "192.168.20.22:8888"], and finally the array is looped to loop through the addresses of the login nodes 192.168.20.20 and 192.168.20.22. For each node, paramiko is used to implement ssh login to the server, and then the netstat-anp|grep8888|head-1|awk'{print$7}'|cut-d' / '-f 1 command is executed to find the process number of the service entered by the user: 3777, and then the "supervisorctl status" command to view the service names and corresponding process numbers of all services, as shown in Table 8:

[0114] Table 8

[0115] Microservice Name Process number check-service 3777 alarm-service 3778 email-service 3779

[0116] Compare the obtained process number with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number: check-service. Run the "supervisorctl restart check-service" command to restart the service.

[0117] Embodiment 3:

[0118] There are 3 microservices. The nacos registration center records the server addresses of all microservices, as shown in Table 9:

[0119] Table 9

[0120] Microservice Name The address of the server check-service 192.168.20.20、192.168.20.21、192.168.20.22 alarm-service 192.168.20.30、192.168.20.31、192.168.20.32 email-service 192.168.20.40、192.168.20.41、192.168.20.42

[0121] The results of the crawler packet capture analysis are used to obtain the interface address of nacos login and the data sent when requesting the address. The third-party dependency package requests of python is used to write a program to simulate the interface call. According to the packet capture analysis, the interface address during login is: http: / / 192.168.20.8:8848 / nacos / v1 / auth / users / login.

[0122] According to the packet capture results, the headers array, URL address and post array of the http interface request are constructed, and the post method of requests is used to simulate the request for the interface to log in to nacos.

[0123] After simulating a successful nacos login, all service name information registered in nacos is obtained through crawler packet analysis.

[0124] According to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / services?hasIpCount=true&withInstances=false&pageNo=1&pageSize=100&serviceNameParam=&groupNameParam=&accessToken=%s&namespaceId=. The data returned by the interface is in a json format. We assign this part of the data to the variable serviceData.

[0125]

[0126]

[0127] We assign this part of data to the serviceData variable, and get the data under the serviceList node through serviceData["serviceList"]. Then we read the serviceList node data in a loop, read the value of the name node, and finally format the output to present the service name information of all services registered in nacos. The service list is shown in Table 10:

[0128] Table 10

[0129] Serial number Service Name 1 check-service 2 alarm-service 3 email-service

[0130] A command line dialog is provided, asking the user to enter the name of the service that needs to be restarted. The user enters: check-service.

[0131] According to the input service name, query the registration information of the service in nacos, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis; according to the packet capture analysis results, the interface address is: http: / / 192.168.20.8:8848 / nacos / v1 / ns / catalog / instances?&accessToken=%s&serviceName=check-service&clusterName=DEFAULT&groupName=DEFAULT_GROUP&pageSize=100&pageNo=1&namespaceId=, the data returned by the interface is also in json format, here we assign this part of the data to the variable listData, after simplification, the data sample is as follows:

[0132]

[0133]

[0134] We assign the data to the listData variable, then we can access the data under the list node through listData["list"]. Often a service is deployed in a cluster and there will be multiple nodes. So the packet capture result shows that there are multiple data under the list node. So we read the list node data in a loop to get the values ​​of the ip, port, healthy, and enabled nodes, and thus get the address information, port information, service status, and health status information of each node registered in nacos by the service. We also implement the detection of the service status and finally format the output for presentation, as shown in Table 11, where True represents healthy or normal, False represents unhealthy or abnormal, and the service is unavailable.

[0135] Table 11

[0136] IP port healthy enabled 192.168.20.20 8888 False False 192.168.20.21 8888 False True 192.168.20.22 8888 True False

[0137] Provides a command line dialogue to obtain the service of the IP address that needs to be restarted through the information entered by the user. Three input methods are provided here. When only one service node needs to be restarted, enter it in the format of IP:Port. When multiple nodes need to be entered, separate them with English commas. If all nodes need to be restarted, just enter all.

[0138] User input: all.

[0139] After obtaining the service that the user needs to restart, the code determines whether the node information entered by the user contains "all". If so, it is determined to restart all services. The code directly loops through the addresses of the login nodes 192.168.20.20, 192.168.20.21, and 192.168.20.22. Each node implements ssh login to the server through paramiko, and then executes the netstat-anp|grep 8888|head-1|awk'{print$7}'|cut-d' / '-f 1 command to find the process number of the service entered by the user: 3777, and then executes the "supervisorctl status" command to view the service names and corresponding process numbers of all services, as shown in Table 12:

[0140] Table 12

[0141]

[0142]

[0143] Compare the obtained process number with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number: check-service. Run the "supervisorctl restart check-service" command to restart the service.

[0144] Based on the same inventive concept, the present invention also proposes a device for detecting the service status of nacos management and implementing batch restart of services. The implementation of the device can refer to the implementation of the above method, and the repeated parts will not be repeated. Figure 2 As shown, the device 100 includes:

[0145] Login module 101: used to obtain the interface address of nacos login and the data sent when requesting the address through the crawler packet analysis results, use Python's third-party dependency package requests to write a program to simulate calling the interface, construct the headers array, url address and post array when requesting the http interface, and simulate the request for the interface to log in to nacos through the post method of requests;

[0146] Acquisition module 102: used to obtain all service name information registered in nacos through crawler packet analysis after simulating successful nacos login;

[0147] Query module 103: used to provide a command line dialogue, query the registration information of the service in nacos through the service name input by the user, and obtain the service status of each node registered in nacos by the service;

[0148] Restart module 104: used to provide a command line dialogue, obtain the service of the IP address that needs to be restarted through the information input by the user, log in to the server according to the address and restart the service after querying the process where the service is located through the port.

[0149] The query module 103 includes:

[0150] Input module 1031: used to provide a command line dialogue, asking the user to input the service name that needs to be restarted;

[0151] Data return module 1032: used to query the registration information of the service in nacos according to the input service name, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis. The data returned by the interface is in json format;

[0152] Status acquisition module 1033: used to assign the data returned by the interface to the variable listData, access the data under the list node through listData and read the list node data in a loop to obtain the address information, port information, service status and health status of each node registered by the service in nacos;

[0153] Status presentation module 1034: used to format and output the address information, port information, service status and health status of each node registered with the service in nacos.

[0154] The restart module 104 includes:

[0155] Process ID acquisition module 1041: used to execute the process ID command of querying the occupied port to find the process ID of the service input by the user after logging into the server through SSH through paramiko;

[0156] The service name acquisition module 1042 is used to execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services, and compare the process number obtained by the process number acquisition module with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number;

[0157] The restart execution module 1043 is used to execute the "supervisorctl restart service name" command to restart the service.

[0158] The device proposed by the present invention detects the service status of nacos management and realizes batch restart of services. By capturing packets and analyzing the interface request address, interface data and return data of the login of the nacos registration center, the acquisition of all service information and the registration information of a single service, the interface request is simulated by a python crawler method to obtain the node information of the service, thereby completing the status monitoring of each node; a command line for user dialogue is provided, and the user determines the services and service nodes that need to be restarted, and then the paramiko third-party package of python is used to log in to the servers where the services that need to be restarted are located one by one, and then the service port found out from nacos is used to find the process number of the service, and the service name is found according to the process number to complete the restart, thereby realizing the function of restarting all services with one key, effectively solving the problem of batch restarting services, and improving work efficiency.

[0159] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements contained in the spirit and scope of the attached claims.

[0160] Regarding the limitation of the protection scope of the present invention, those skilled in the art should understand that, based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative work are still within the protection scope of the present invention.

Claims

1. A method for detecting the service status managed by nacos and implementing batch restart of services, characterized in that: The method includes: S01: Use the crawler to capture the packet analysis results to obtain the interface address when nacos logs in and the data sent when requesting the address. Use Python's third-party dependency package requests to write a program to simulate calling the interface, construct the headers array, url address and post array when requesting the http interface, and use the post method of requests to simulate requesting the interface for nacos login; S02: After simulating a successful nacos login, obtain all service name information registered in nacos through crawler packet capture analysis; S03: Provide a command line dialogue, query the registration information of the service in nacos through the service name entered by the user, and obtain the service status of each node registered in nacos by the service; S04: Provide a command line dialogue, obtain the service of the IP address that needs to be restarted through the information input by the user, log in to the server according to the address, and restart the service after querying the process where the service is located through the port.

2. The method for detecting the service status of nacos management and realizing batch restart of services according to claim 1 is characterized in that: The specific steps of S03 are: S031: Provide a command line dialogue and ask the user to enter the service name that needs to be restarted; S032: Query the registration information of the service in nacos according to the input service name, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis. The data returned by the interface is in json format; S033: Assign the data returned by the interface to the variable listData, access the data under the list node through listData and read the list node data in a loop to obtain the address information, port information, service status and health status of each node registered by the service in nacos; S034: The address information, port information, service status and health status of each node registered with the service in nacos are formatted and output for presentation.

3. The method for detecting the service status of nacos management and realizing batch restart of services according to claim 1 is characterized in that: There are three input methods for the command line dialogue described in S04: if you need to restart a service node, enter the IP:Port; if you need to restart multiple service nodes, enter multiple IP:Port separated by English commas; if you need to restart all service nodes, enter all.

4. The method for detecting the service status of nacos management and realizing batch restart of services according to claim 3 is characterized in that: After obtaining the service of the IP address that needs to be restarted as described in S04, determine whether the node information input by the user contains "all". If so, directly loop and log in to the address of each service node; if not, split the information separated by English commas and obtain an array of node information, and finally loop the array to log in to the address of each service node.

5. The method for detecting the service status of nacos management and realizing batch restart of services according to claim 1 is characterized in that: The specific steps for restarting the service described in S04 are: S041: After logging in to the server through ssh using paramiko, execute the command to query the process number of the port occupied to find the process number of the service entered by the user; S042: Execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services. Compare the process number obtained in S041 with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number. S043: Execute the "supervisorctl restart service name" command to restart the service.

6. A device for detecting the service status managed by nacos and implementing batch restart of services, characterized in that: The device includes: Login module: used to obtain the interface address of nacos login and the data sent when requesting the address through the crawler packet analysis results, use python's third-party dependency package requests to write a program to simulate the interface call, construct the headers array, url address and post array when requesting the http interface, and simulate the request for the interface to log in to nacos through the post method of requests; Acquisition module: used to simulate the successful login of nacos and obtain all service name information registered in nacos through crawler packet analysis; Query module: used to provide command line dialogue, query the registration information of the service in nacos through the service name entered by the user, and obtain the service status of each node registered in nacos; Restart module: used to provide command line dialogue, obtain the service of the IP address that needs to be restarted through the information entered by the user, log in to the server according to the address, and restart the service after querying the process where the service is located through the port.

7. The device for detecting the service status of nacos management and realizing batch restart of services according to claim 6, characterized in that: The query module includes: Input module: used to provide command line dialogue, asking users to enter the service name that needs to be restarted; Data return module: used to query the registration information of the service in nacos according to the input service name, and obtain the interface address, headers array, url address, post array and data returned by the interface address when obtaining a single service through packet capture analysis. The data returned by the interface is in json format; Status acquisition module: used to assign the data returned by the interface to the variable listData, access the data under the list node through listData and read the list node data in a loop to obtain the address information, port information, service status and health status of each node registered by the service in nacos; Status presentation module: used to format and output the address information, port information, service status and health status of each node registered with the service in nacos.

8. The device for detecting the service status of nacos management and realizing batch restart of services according to claim 6, characterized in that: There are three input methods for the command line dialogue described in the restart module: if you need to restart a service node, enter the IP:Port; if you need to restart multiple service nodes, enter multiple IP:Port separated by English commas; if you need to restart all service nodes, enter all.

9. The device for detecting the service status of nacos management and realizing batch restart of services according to claim 8, characterized in that: After obtaining the service of the IP address that needs to be restarted as described in the restart module, determine whether the node information entered by the user contains "all". If it does, directly loop and log in to the address of each service node; if it does not contain "all", split the information separated by English commas and obtain an array of node information, and finally loop the array to log in to the address of each service node.

10. The device for detecting the service status of nacos management and realizing batch restart of services according to claim 6, characterized in that: The restart module comprises: Process ID acquisition module: used to log in to the server through SSH through paramiko, and then execute the process ID command to query the process ID of the port occupied to find the process ID of the service entered by the user; Service name acquisition module: used to execute the "supervisorctl status" command to view the service names and corresponding process numbers of all services. The process number obtained by the process number acquisition module is compared with the service process number returned by "supervisorctl status" to obtain the service name corresponding to the process number. Restart execution module: used to execute the "supervisorctlrestart service name" command to restart the service.