Spark-based task state monitoring method and device, electronic equipment and medium
By building a status monitoring project and defining a task status listener on the Spark client, the problem of Spark task status monitoring occupying resources is solved, achieving more efficient resource utilization and real-time status monitoring.
Patent Information
- Application Number
- CN202410716834.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-24
AI Technical Summary
In the process of monitoring the execution status of Spark tasks, the upstream system needs to parse the console log, resulting in expensive IO operations, seriously occupying resources, and high costs.
Build a Spark status monitoring project, and define a Spark task status listener by writing a configuration file to obtain task status information and send it to the message middleware, so that the downstream business system can consume it and reduce the upstream system resource usage.
By configuring the Spark listener and integrating it into the Spark client, the user's business system is decoupled, reducing the complexity of Spark task status information, reducing resource occupation, and improving real-time performance and accuracy.
Smart Images

Figure CN118689668A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, electronic device and medium for monitoring task status based on Spark. Background Art
[0002] Apache Spark is a fast, general-purpose, memory-based distributed computing system. It is designed to process large-scale data sets, especially for iterative algorithms and interactive data mining. Spark provides a variety of APIs, including Scala, Java, Python, and R, so that users can use different languages for data analysis. In big data analysis, Apache Spark is widely used in various scenarios, such as enterprise data analysis, search engine optimization, and real-time data processing. It can not only process large-scale data sets, but also support interactive analysis and complex algorithms. Therefore, Spark has become one of the important tools in the field of big data. It is very important to monitor the execution status of tasks during the execution of Spark tasks. For example, if the status of failed tasks is captured, early warning and intervention can be carried out in time; if the status of successful tasks is captured, subsequent task execution can be triggered.
[0003] In the related art, when submitting a Spark task, the console log output by the Spark client is obtained, and the console log is parsed to obtain the execution status of the current Spark task. However, when submitting a Spark task to the upstream system, parsing the log operation requires expensive IO operations, which will seriously occupy the resources of the upstream system and is costly. Therefore, in the process of monitoring the execution status of the Spark task, how to reduce the resource occupation of the upstream system is an urgent problem to be solved. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a Spark-based task status monitoring method, device, electronic device and medium.
[0005] In order to achieve the above objectives, the embodiments of the present disclosure provide the following technical solutions:
[0006] In a first aspect, an embodiment of the present disclosure provides a task status monitoring method based on Spark, which is applied to a Spark client, and the method includes:
[0007] Build a spark status monitoring project and configure the dependency information of the spark status monitoring project and the dependency information of the message middleware;
[0008] Based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, a spark task status listener is defined by writing a configuration file; the spark task status listener includes: a plurality of attributes to be monitored, and a method for obtaining the plurality of attributes to be monitored;
[0009] When executing a spark task submitted by an upstream business system, obtaining task status information of the spark task through the task status listener;
[0010] The task status information is sent to the message middleware, so that the downstream business system consumes the task status information in the message middleware.
[0011] As an optional implementation of the embodiment of the present disclosure, the spark task status listener is defined by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, including:
[0012] In the configuration file, write a spark task status monitoring class, and define multiple attributes to be monitored in the spark task status monitoring class;
[0013] In the spark task status monitoring class, rewrite the task start method, task end method, application start method and application end method of the parent class;
[0014] In the configuration file, a task status information class is added; the task status information class is a java class; the task status information class includes: a spark application identification attribute, a spark application name attribute, a spark task execution status attribute, a spark task start time attribute, and a spark task end time attribute;
[0015] A method for obtaining the multiple attributes to be monitored is defined in the spark task status monitoring class.
[0016] As an optional implementation of the embodiment of the present disclosure, when executing the spark task submitted by the upstream business system, after obtaining the task status information of the spark task through the task status listener, it also includes:
[0017] Add the message middleware connection message and the spark task status topic pushed by the task status information to the configuration file, and configure the spark task status listener according to the task status information; the message middleware connection information includes: the ip address information and port information of the message middleware;
[0018] Encapsulating the task status information into the task status information class;
[0019] Obtain the connection information of the middleware, and send the task status information to the spark task status topic of the message middleware;
[0020] The spark status monitoring project is packaged based on a packaging tool to obtain a jar package;
[0021] Install the jar package into the jars directory of the spark client.
[0022] As an optional implementation of the embodiment of the present disclosure, when executing the spark task submitted by the upstream business system, obtaining the task status information of the spark task through the task status listener includes:
[0023] In response to the spark task submitted by the upstream business system, the application startup method is captured through the task status listener to obtain the task parameters submitted by the spark task;
[0024] Capturing the task start method through the task status listener to obtain the task status information of the spark task;
[0025] Capturing the task end method through the task status listener to determine whether the task status information has changed;
[0026] If the task status information has not changed, the application end method is captured through the task status listener to obtain the task execution end time of the spark task.
[0027] As an optional implementation of the embodiment of the present disclosure, the determining whether the task status information is changed further includes:
[0028] If the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and the method for obtaining the multiple attributes to be monitored is called to push the task status information.
[0029] As an optional implementation of the embodiment of the present disclosure, the adding of the connection message of the message middleware and the spark task status topic in the configuration file, and configuring the spark task status listener according to the task status information, includes:
[0030] Configure the connection information of the message middleware;
[0031] Configure the key-value pair serialization mode of the message middleware as string serialization;
[0032] Configure the message middleware to carry the message topic of the spark task status information;
[0033] According to the task status information, configure the spark task status listener.
[0034] As an optional implementation of the embodiment of the present disclosure, the multiple attributes to be monitored include: spark application identification, spark application name, spark task execution status, spark task start time, and spark task end time.
[0035] In a second aspect, the embodiment of the present disclosure provides a task status monitoring device based on Spark, including:
[0036] A configuration module is used to build a spark status monitoring project and configure dependency information of the spark status monitoring project and dependency information of the message middleware;
[0037] A writing module, used to define a spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware; the spark task status listener includes: a plurality of attributes to be monitored, and a method for obtaining the plurality of attributes to be monitored;
[0038] A monitoring module, used for obtaining the task status information of the spark task through the task status monitor when executing the spark task submitted by the upstream business system;
[0039] The sending module is used to send the task status information to the message middleware so that the downstream business system consumes the task status information in the message middleware.
[0040] As an optional implementation of the embodiment of the present disclosure, the writing module is specifically used for:
[0041] In the configuration file, write a spark task status monitoring class, and define multiple attributes to be monitored in the spark task status monitoring class;
[0042] In the spark task status monitoring class, rewrite the task start method, task end method, application start method and application end method of the parent class;
[0043] In the configuration file, a task status information class is added; the task status information class is a java class; the task status information class includes: a spark application identification attribute, a spark application name attribute, a spark task execution status attribute, a spark task start time attribute, and a spark task end time attribute;
[0044] A method for obtaining the multiple attributes to be monitored is defined in the spark task status monitoring class.
[0045] As an optional implementation of the embodiment of the present disclosure, the device further includes:
[0046] A new module is added, which is used to add the connection message of the message middleware and the spark task status topic pushed by the task status information in the configuration file, and configure the spark task status listener according to the task status information; the connection information of the message middleware includes: the IP address information and port information of the message middleware;
[0047] An encapsulation module, used for encapsulating the task status information into the task status information class;
[0048] An acquisition module is used to obtain the connection information of the middleware and send the task status information to the spark task status topic of the message middleware;
[0049] A packaging module is used to package the spark status monitoring project based on a packaging tool to obtain a jar package;
[0050] The installation module is used to install the jar package into the jars directory of the spark client.
[0051] As an optional implementation of the embodiment of the present disclosure, the monitoring module includes:
[0052] A response unit, configured to respond to the spark task submitted by the upstream business system, capture the application startup method through the task status listener, and obtain the task parameters submitted by the spark task;
[0053] An acquiring unit, configured to capture the task start method through the task status listener and acquire task status information of the spark task;
[0054] A determination unit, configured to capture the task end method through the task status listener and determine whether the task status information has changed;
[0055] The changing unit is used to capture the application end method through the task status listener to obtain the task execution end time of the spark task if the task status information has not changed.
[0056] As an optional implementation of the embodiment of the present disclosure, the determining unit is further specifically configured to:
[0057] If the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and the method for obtaining the multiple attributes to be monitored is called to push the task status information.
[0058] As an optional implementation of the embodiment of the present disclosure, the newly added module is specifically used for:
[0059] Configure the connection information of the message middleware;
[0060] Configure the key-value pair serialization mode of the message middleware as string serialization;
[0061] Configure the message middleware to carry the message topic of the spark task status information;
[0062] According to the task status information, configure the spark task status listener.
[0063] As an optional implementation of the embodiment of the present disclosure, the multiple attributes to be monitored include: spark application identification, spark application name, spark task execution status, spark task start time, and spark task end time.
[0064] In a third aspect, an embodiment of the present disclosure provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the spark-based task status monitoring method described in the first aspect or any implementation of the first aspect is implemented.
[0065] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the spark-based task status monitoring method described in the first aspect or any implementation of the first aspect is implemented.
[0066] The present invention discloses a method for monitoring task status based on spark, constructs a spark status monitoring project, configures dependency information of the spark status monitoring project and dependency information of the message middleware, defines a spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, wherein the spark task status listener includes: multiple attributes to be monitored, and a method for obtaining multiple attributes to be monitored, and when executing a spark task submitted by an upstream business system, obtains the task status information of the spark task through the task status listener, and sends the task status information to the message middleware, so that the downstream business system consumes the task status information in the message middleware. The task execution status is obtained by configuring the spark listener, that is, the task status listener is integrated into the spark client in the form of a plug-in, decoupled from the user business system, and reduces the complexity of the user business system using the spark task status information. The user business system does not need to parse the spark task submission log, thereby reducing the resource occupation of the upstream system in the process of monitoring the spark task execution status. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0068] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0069] Figure 1 The figure is a flowchart of a method for monitoring task status based on Spark in one embodiment;
[0070] Figure 2 The following is a schematic diagram of an application scenario of a task status monitoring method based on Spark in one embodiment;
[0071] Figure 3 It is a structural schematic diagram of a task status monitoring device based on Spark in one embodiment;
[0072] Figure 4 It is a schematic diagram of the structure of the electronic device described in the embodiment of the present disclosure. DETAILED DESCRIPTION
[0073] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0074] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0075] Relational terms such as “first” and “second” in the description and claims of the present disclosure are merely used to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0076] In the embodiments of the present disclosure, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present disclosure should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way. In addition, in the description of the embodiments of the present disclosure, unless otherwise specified, the meaning of "multiple" refers to two or more.
[0077] Glossary:
[0078] Maven is an open source project management tool based on the concept of Project Object Model (POM) and developed in pure Java. It is mainly used to manage Java projects, perform dependency management (JAR package dependency management) and project construction (project compilation, packaging, testing, and deployment). In addition, it can also be developed in modules to improve development efficiency.
[0079] pom.xml is the core configuration file of Maven project, which is the abbreviation of Project Object Model. POM defines all the properties of the project, including the project name, version, dependencies, build configuration, etc. With pom.xml, you can easily manage the build and dependencies of the project.
[0080] In traditional WEB projects, the jar packages that the project depends on must be copied into the project, which makes the project very large. In Maven projects, jar packages are not directly imported into the project, but the coordinates of the required jar packages are added in the pom.xml file, which effectively avoids the direct introduction of jar packages. When the jar package is needed, just search the pom.xml file, and then use the coordinates in the pom.xml file to find these jar packages in a warehouse dedicated to "storing jar packages" (maven warehouse) according to the coordinates, and then run these jar packages.
[0081] Spark provides a variety of APIs, including Scala, Java, Python, and R, allowing users to use different languages for data analysis. In big data analysis, Apache Spark is widely used in various scenarios, such as enterprise data analysis, search engine optimization, and real-time data processing. It can not only process large-scale data sets, but also support interactive analysis and complex algorithms. Therefore, Spark has become one of the important tools in the field of big data. It is very important to monitor the execution status of tasks during the execution of Spark tasks. For example, if the status of failed tasks is captured, early warning and intervention can be carried out in time; if the status of successful tasks is captured, subsequent task execution can be triggered.
[0082] In the related art, when submitting a Spark task, the console log output by the Spark client is obtained, and the console log is parsed to obtain the execution status of the current Spark task, or the task execution status is obtained by periodic polling. However, the above method has the following defects: in the task submission logic of the upstream system, it is necessary to couple the corresponding log parsing logic to parse the task execution status, which increases the complexity of the upstream system. When there is an accident (such as power failure and restart) in the process of submitting a task in the upstream system, the execution status of the task cannot be re-obtained in real time, and the stability and real-time performance are poor. When the upstream system submits a spark task, the log parsing operation requires expensive IO operations, which will seriously occupy the resources of the upstream system and the cost is high. Spark task execution is completely separated from task status monitoring. When developers directly submit tasks on the spark client through the server background, they can bypass the log parsing logic redefined by the upstream business system. For example, when submitting a spark task through the system level (such as a web page or a mobile phone), the log can be obtained by using the existing technology, that is, the execution status of the current spark task is obtained by parsing the log. The log processing logic in the existing technology is in the user business system. However, if the system (such as a web page or a mobile phone) is bypassed and the spark task is submitted directly on the server using the command line, there is a lack of log processing logic, and the log cannot be obtained, and further the log cannot be parsed.
[0083] To solve the above problems, the present invention provides a task status monitoring method based on spark, constructs a spark status monitoring project, and configures the dependency information of the spark status monitoring project and the dependency information of the message middleware. Based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, a spark task status listener is defined by writing a configuration file, wherein the spark task status listener includes: multiple attributes to be monitored, and a method for obtaining multiple attributes to be monitored. When executing a spark task submitted by an upstream business system, the task status information of the spark task is obtained through the task status listener, and the task status information is sent to the message middleware, so that the downstream business system consumes the task status information in the message middleware. The task execution status is obtained by configuring the spark listener, that is, the task status listener is integrated into the spark client in the form of a plug-in, decoupled from the user business system, and the complexity of the user business system using the spark task status information is reduced. The user business system does not need to parse the spark task submission log, so that in the process of monitoring the spark task execution status, the resource occupation of the upstream system can be reduced. That is, in the embodiment of the present disclosure, the information of the Spark client configuring the listener can be obtained from the Spark client regardless of whether the server or the user business system obtains the execution status information.
[0084] In one embodiment, Figure 1 As shown, a method for monitoring task status based on Spark is provided, comprising the following steps:
[0085] S11. Build a spark status monitoring project, and configure dependency information of the spark status monitoring project and dependency information of the message middleware.
[0086] Specifically, create a Maven project spark-status-listener, and introduce spark-related Maven dependencies and kafka-related Maven dependencies. Related pom dependencies include but are not limited to: introducing the spark-sql module to execute sparksql tasks, introducing the spark-yarn module to communicate with the big data computing resource manager, introducing the spark-core module to execute spark underlying logic, introducing the spark-streaming module to execute spark streaming computing, introducing hadoop-related dependencies to facilitate the use of big data resources, and introducing json dependencies to parse object data.
[0087] S12: Based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, define the spark task status listener by writing a configuration file.
[0088] The spark task status listener includes: multiple attributes to be monitored and methods for obtaining the multiple attributes to be monitored. The multiple attributes to be monitored include: spark application identifier, spark application name, spark task execution status, spark task start time, and spark task end time.
[0089] Specifically, the spark application identifier can be represented by APPID, which is used to record the application ID during the execution of the Spark task; the spark application name can be represented by Appname, which is used to record the specified task name when the Spark task is submitted; the spark task execution status can be represented by Status, which is used to record the status during the execution of the Spark task (the spark task execution status includes but is not limited to: task execution failure, task execution success, running, undefined, and canceled); the spark task start time can be represented by startTime, which is used to record the timestamp when the Spark task starts; the spark task end time can be represented by endTime, which is used to record the timestamp when the Spark task ends.
[0090] In some embodiments, the above step S12 (defining the spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware) can be implemented as follows:
[0091] A. In the configuration file, write a spark task status monitoring class, and define multiple attributes to be monitored in the spark task status monitoring class.
[0092] Specifically, in the Maven project spark-status-listener created above, write the SparkTaskStatusListener class and inherit the SparkListener class of the Spark framework. In the SparkTaskStatusListener class, define the attribute appId of the string type to record the application ID of the corresponding Spark task execution process; define the attribute appName of the string type to record the task name specified when the Spark task is submitted; define the attribute status of the string type to record the status of the Spark task execution process; define the attribute startTime of the constant integer type to record the timestamp when the Spark task starts; define the attribute endTime of the constant integer type to record the timestamp when the Spark task ends.
[0093] B. In the spark task status monitoring class, rewrite the task start method, task end method, application start method and application end method of the parent class.
[0094] Specifically, in the defined SparkTaskStatusListener class, override the onTaskStart method of the parent class, override the onTaskEnd method of the parent class, override the onApplicationStart method of the parent class, and override the onApplicationEnd method of the parent class.
[0095] C. In the configuration file, a new task status information class is added.
[0096] The task status information class is a Java class, and includes: a spark application identification attribute, a spark application name attribute, a spark task execution status attribute, a spark task start time attribute, and a spark task end time attribute.
[0097] Specifically, in the constructed spark status monitoring project, since the spark task status listener is defined by writing a configuration file, the java class TaskStatusInfo (task status information class) is defined in the configuration file to encapsulate information parameters such as the status during the execution of the Spark task. The java class TaskStatusInfo defines a string type attribute appId to record the application ID during the execution of the corresponding Spark task; defines a string type attribute appName to record the task name specified when the Spark task is submitted; defines a string type attribute status to record the status during the execution of the Spark task; defines a constant integer type attribute startTime to record the timestamp when the Spark task is started; defines a constant integer type attribute endTime to record the timestamp when the Spark task ends.
[0098] D. Define a method for obtaining the multiple attributes to be monitored in the spark task status monitoring class.
[0099] Specifically, a method for obtaining the plurality of attributes to be monitored is defined in the spark task status monitoring class. In this method, the input parameter is the java class TaskStatusInfo object defined in the above task status information class.
[0100] Among them, the method for obtaining the multiple attributes to be monitored includes the following steps: obtaining the corresponding middleware configuration information and the spark task status topic pushed by the task status information from the dependency information of the spark status monitoring project; initializing the middleware client according to the middleware configuration information; and pushing the spark task status information to the spark task status topic through the middleware client.
[0101] Exemplarily, in this method (the method for obtaining the multiple attributes to be monitored), first, the corresponding Kafka configuration information and the topic corresponding to the push status message are obtained from the Spark task configuration, and then the Kafka client is initialized according to the obtained Kafka configuration, and finally the Spark task status message is pushed to the corresponding Kafka topic through the Kafka client.
[0102] S13. When executing the spark task submitted by the upstream business system, the task status information of the spark task is obtained through the task status listener.
[0103] In some embodiments, the above step S13 (obtaining the task status information of the spark task through the task status listener when executing the spark task submitted by the upstream business system) can be implemented as follows:
[0104] a. In response to the spark task submitted by the upstream business system, the application startup method is captured through the task status listener to obtain the task parameters submitted by the spark task.
[0105] Specifically, in response to the spark task submitted by the upstream business system, the application startup method is captured through the task status listener. In the application startup method, the spark application identifier, spark application name, and spark task startup time defined in the spark task status listening class are assigned through the input parameters of the task status information class.
[0106] b. Capture the task start method through the task status listener to obtain the task status information of the spark task.
[0107] c. Capturing the task end method through the task status listener to determine whether the task status information has changed.
[0108] Specifically, in the task start method and the task end method, the task status information when the task starts executing and the task status information when the task ends executing are obtained respectively through the input parameter of the task status information class.
[0109] d. If the task status information has not changed, the application end method is captured by the task status listener to obtain the task execution end time of the spark task.
[0110] Specifically, if the task status information has not changed, the application end method is captured through the task status listener. In the application end method, the spark task end time is assigned through the input parameter of the task status information class.
[0111] Furthermore, in some embodiments, the above step c (determining whether the task status information has changed) can also be implemented in the following manner:
[0112] If the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and the method for obtaining the multiple attributes to be monitored is called to push the task status information.
[0113] Specifically, when the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and a method for obtaining the multiple attributes to be monitored is called to push the task status information.
[0114] In some embodiments, after executing the above step S13 (obtaining the task status information of the spark task through the task status listener when executing the spark task submitted by the upstream business system), the following steps may also be performed:
[0115] (1) Add the connection message of the message middleware and the spark task status topic pushed by the task status information in the configuration file, and configure the spark task status listener according to the task status information.
[0116] The connection information of the message middleware includes: the IP address information and port information of the message middleware.
[0117] Optionally, the above step (1) can be implemented in the following way:
[0118] Configure the connection information of the message middleware;
[0119] Configure the key-value pair serialization mode of the message middleware as string serialization;
[0120] Configure the message middleware to carry the message topic of the spark task status information;
[0121] According to the task status information, configure the spark task status listener.
[0122] Specifically, add kafka-related connection information and the topic for pushing task status messages in the spark-default.conf configuration file of the spark client, that is, configure the connection information of the message middleware kafka, and the connection information includes the ip address information and port information of the message middleware. Since data transmission is transmitted in a serialized manner, it is also necessary to configure the kafka message key serialization method as string serialization, and configure the kafka message value serialization method as string serialization. In addition, it is necessary to configure the kafka message topic to carry the spark task status data, and configure the SparkTaskStatusListener listener defined in the above step S12 according to the spark task status data.
[0123] (2) Encapsulate the task status information into the task status information class.
[0124] (3) Obtain the connection information of the middleware, and send the task status information to the spark task status topic of the message middleware.
[0125] (4) Packaging the spark status monitoring project based on a packaging tool to obtain a jar package.
[0126] (5) Install the jar package into the jars directory of the spark client.
[0127] Specifically, after encapsulating the parsed task status data into the java class TaskStatusInfo object defined in the above step, obtain the configured kafka connection information, and send the task status data TaskStatusInfo to the spark_task_status topic of the message queue kafka. Use Maven to package the project spark-status-listener created in the above step S11 into a jar package and install it in the jars directory of the spark client.
[0128] S14: Send the task status information to the message middleware, so that the downstream business system consumes the task status information in the message middleware.
[0129] Specifically, the downstream system monitors the task status data stored in the spark_task_status topic in the message middleware kafka and can perform relevant analysis and monitoring processing.
[0130] In some embodiments, the flow of task status data can refer to Figure 2 As shown, the user submits a spark computing task to the Spark engine. The Spark engine obtains the task status information according to the solution described in Section 3 above, and sends the parsed task status data to the message middleware Kafka. The downstream business system consumes the task status data in Kafka to complete task status monitoring.
[0131] This method can be applied to the task status information collection in the process of executing computing tasks based on the spark engine. By collecting the status data of the spark task execution process in real time, early warning monitoring of the task status can be achieved.
[0132] Compared with the method of parsing task submission logs by the upstream system or the method of periodic polling, the method provided by the embodiment of the present disclosure obtains the task execution status by configuring the spark listener, which is more accurate and more real-time.
[0133] The task status listener is integrated into the spark client as a plug-in, decoupled from the user's business system, and reduces the complexity of the user's business system using spark tasks. The user's business system does not need to parse the spark task submission log or periodically poll for status updates.
[0134] The task status listener is integrated into the spark task execution process, ensuring the consistency of task execution and status data, and unifying the collection entry of task status information on the spark client.
[0135] The upgrade of the spark task status monitoring plug-in in the embodiment of the present disclosure does not affect the use of the business system. It can directly replace the listener plug-in in the spark client jars directory, and the upstream business system is unaware of it.
[0136] The present invention discloses a method for monitoring task status based on spark, constructs a spark status monitoring project, configures dependency information of the spark status monitoring project and dependency information of the message middleware, defines a spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, wherein the spark task status listener includes: multiple attributes to be monitored, and a method for obtaining multiple attributes to be monitored, and when executing a spark task submitted by an upstream business system, obtains the task status information of the spark task through the task status listener, and sends the task status information to the message middleware, so that the downstream business system consumes the task status information in the message middleware. The task execution status is obtained by configuring the spark listener, that is, the task status listener is integrated into the spark client in the form of a plug-in, decoupled from the user business system, and reduces the complexity of the user business system using the spark task status information. The user business system does not need to parse the spark task submission log, thereby reducing the resource occupation of the upstream system in the process of monitoring the spark task execution status.
[0137] In one embodiment, Figure 3 As shown, a task status monitoring device 300 based on Spark is provided, comprising:
[0138] Configuration module 310, used to build a spark status monitoring project and configure dependency information of the spark status monitoring project and dependency information of the message middleware;
[0139] A writing module 320 is used to define a spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware; the spark task status listener includes: a plurality of attributes to be monitored, and a method for obtaining the plurality of attributes to be monitored;
[0140] The monitoring module 330 is used to obtain the task status information of the spark task through the task status monitor when executing the spark task submitted by the upstream business system;
[0141] The sending module 340 is used to send the task status information to the message middleware, so that the downstream business system consumes the task status information in the message middleware.
[0142] As an optional implementation of the embodiment of the present disclosure, the writing module is specifically used for:
[0143] In the configuration file, write a spark task status monitoring class, and define multiple attributes to be monitored in the spark task status monitoring class;
[0144] In the spark task status monitoring class, rewrite the task start method, task end method, application start method and application end method of the parent class;
[0145] In the configuration file, a task status information class is added; the task status information class is a java class; the task status information class includes: a spark application identification attribute, a spark application name attribute, a spark task execution status attribute, a spark task start time attribute, and a spark task end time attribute;
[0146] A method for obtaining the multiple attributes to be monitored is defined in the spark task status monitoring class.
[0147] As an optional implementation of the embodiment of the present disclosure, the device further includes:
[0148] A new module is added, which is used to add the connection message of the message middleware and the spark task status topic pushed by the task status information in the configuration file, and configure the spark task status listener according to the task status information; the connection information of the message middleware includes: the IP address information and port information of the message middleware;
[0149] An encapsulation module, used for encapsulating the task status information into the task status information class;
[0150] An acquisition module is used to obtain the connection information of the middleware and send the task status information to the spark task status topic of the message middleware;
[0151] A packaging module is used to package the spark status monitoring project based on a packaging tool to obtain a jar package;
[0152] The installation module is used to install the jar package into the jars directory of the spark client.
[0153] As an optional implementation of the embodiment of the present disclosure, the monitoring module includes:
[0154] A response unit, configured to respond to the spark task submitted by the upstream business system, capture the application startup method through the task status listener, and obtain the task parameters submitted by the spark task;
[0155] An acquiring unit, configured to capture the task start method through the task status listener and acquire task status information of the spark task;
[0156] A determination unit, configured to capture the task end method through the task status listener and determine whether the task status information has changed;
[0157] The changing unit is used to capture the application end method through the task status listener to obtain the task execution end time of the spark task if the task status information has not changed.
[0158] As an optional implementation of the embodiment of the present disclosure, the determining unit is further specifically configured to:
[0159] If the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and the method for obtaining the multiple attributes to be monitored is called to push the task status information.
[0160] As an optional implementation of the embodiment of the present disclosure, the newly added module is specifically used for:
[0161] Configure the connection information of the message middleware;
[0162] Configure the key-value pair serialization mode of the message middleware as string serialization;
[0163] Configure the message middleware to carry the message topic of the spark task status information;
[0164] According to the task status information, configure the spark task status listener.
[0165] As an optional implementation of the embodiment of the present disclosure, the multiple attributes to be monitored include: spark application identification, spark application name, spark task execution status, spark task start time, and spark task end time.
[0166] The spark-based task status monitoring device provided by the embodiment of the present disclosure is applied to construct a spark status monitoring project, and configure the dependency information of the spark status monitoring project and the dependency information of the message middleware. Based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, a spark task status listener is defined by writing a configuration file, wherein the spark task status listener includes: multiple attributes to be monitored, and a method for obtaining multiple attributes to be monitored. When executing the spark task submitted by the upstream business system, the task status information of the spark task is obtained through the task status listener, and the task status information is sent to the message middleware, so that the downstream business system consumes the task status information in the message middleware. The task execution status is obtained by configuring the spark listener, that is, the task status listener is integrated into the spark client in the form of a plug-in, decoupled from the user business system, and the complexity of the user business system using the spark task status information is reduced. The user business system does not need to parse the spark task submission log, so that in the process of monitoring the spark task execution status, the resource occupation of the upstream system can be reduced.
[0167] For the specific definition of the task status monitoring device based on Spark, please refer to the definition of the task status monitoring method based on Spark above, which will not be repeated here. Each module in the above-mentioned task status monitoring device based on Spark can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor of the electronic device in the form of hardware, or can be stored in the processor of the electronic device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0168] The present disclosure also provides an electronic device, Figure 4 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 4As shown, the electronic device provided in this embodiment includes: a memory 41 and a processor 42, the memory 41 is used to store a computer program; the processor 42 is used to execute the steps performed by any embodiment of the task state monitoring method based on Spark provided by the above method embodiment when calling the computer program. The electronic device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the computer program is executed by the processor, a task state monitoring method based on Spark is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the housing of the computer device, or an external keyboard, touchpad or mouse.
[0169] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present disclosure, and does not constitute a limitation on the computer device to which the scheme of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0170] In one embodiment, the task status monitoring device based on Spark provided by the present disclosure can be implemented in the form of a computer, and the computer program can be used in Figure 4 The memory of the electronic device may store various program modules constituting the task status monitoring device based on Spark of the electronic device, for example, Figure 3 The configuration module 310, the writing module 320, the monitoring module 330, and the sending module 340 shown in the figure. The computer program composed of each program module enables the processor to execute the steps of the task status monitoring method based on spark of the electronic device of each embodiment of the present disclosure described in this specification.
[0171] The embodiment of the present disclosure also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the spark-based task status monitoring method provided by the above method embodiment is implemented.
[0172] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.
[0173] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0174] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0175] Computer readable media include permanent and non-permanent, removable and non-removable storage media. Storage media can be implemented by any method or technology to store information, and the information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0176] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0177] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be 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 present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A task status monitoring method based on Spark, characterized in that: Applicable to the Spark client, including: Build a spark status monitoring project and configure the dependency information of the spark status monitoring project and the dependency information of the message middleware; Based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, a spark task status listener is defined by writing a configuration file; the spark task status listener includes: a plurality of attributes to be monitored, and a method for obtaining the plurality of attributes to be monitored; When executing a spark task submitted by an upstream business system, obtaining task status information of the spark task through the task status listener; The task status information is sent to the message middleware, so that the downstream business system consumes the task status information in the message middleware.
2. The method according to claim 1, characterized in that The spark task status listener is defined by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware, including: In the configuration file, write a spark task status monitoring class, and define multiple attributes to be monitored in the spark task status monitoring class; In the spark task status monitoring class, rewrite the task start method, task end method, application start method and application end method of the parent class; In the configuration file, a task status information class is added; the task status information class is a java class; the task status information class includes: a spark application identification attribute, a spark application name attribute, a spark task execution status attribute, a spark task start time attribute, and a spark task end time attribute; A method for obtaining the multiple attributes to be monitored is defined in the spark task status monitoring class.
3. The method according to claim 2, characterized in that When executing the spark task submitted by the upstream business system, after obtaining the task status information of the spark task through the task status listener, the method further includes: Add the message middleware connection message and the spark task status topic pushed by the task status information to the configuration file, and configure the spark task status listener according to the task status information; the message middleware connection information includes: the ip address information and port information of the message middleware; Encapsulating the task status information into the task status information class; Obtain the connection information of the middleware, and send the task status information to the spark task status topic of the message middleware; The spark status monitoring project is packaged based on a packaging tool to obtain a jar package; Install the jar package into the jars directory of the spark client.
4. The method according to claim 2, characterized in that: When executing the spark task submitted by the upstream business system, obtaining the task status information of the spark task through the task status listener includes: In response to the spark task submitted by the upstream business system, the application startup method is captured through the task status listener to obtain the task parameters submitted by the spark task; Capturing the task start method through the task status listener to obtain the task status information of the spark task; Capturing the task end method through the task status listener to determine whether the task status information has changed; If the task status information has not changed, the application end method is captured through the task status listener to obtain the task execution end time of the spark task.
5. The method according to claim 4, characterized in that The determining whether the task status information has changed further includes: If the task status information changes, the spark task execution status defined in the spark task status monitoring class is updated, and the method for obtaining the multiple attributes to be monitored is called to push the task status information.
6. The method according to claim 3, characterized in that The adding of the connection message of the message middleware and the spark task status topic in the configuration file, and configuring the spark task status listener according to the task status information, includes: Configure the connection information of the message middleware; Configure the key-value pair serialization mode of the message middleware as string serialization; Configure the message middleware to carry the message topic of the spark task status information; Configure the spark task status listener according to the task status information.
7. The method according to claim 1, characterized in that The multiple attributes to be monitored include: spark application identifier, spark application name, spark task execution status, spark task start time, and spark task end time.
8. A task status monitoring device based on Spark, characterized in that: The device comprises: A configuration module is used to build a spark status monitoring project and configure dependency information of the spark status monitoring project and dependency information of the message middleware; A writing module, used to define a spark task status listener by writing a configuration file based on the dependency information of the spark status monitoring project and the dependency information of the message middleware; the spark task status listener includes: a plurality of attributes to be monitored, and a method for obtaining the plurality of attributes to be monitored; A monitoring module, used for obtaining the task status information of the spark task through the task status monitor when executing the spark task submitted by the upstream business system; The sending module is used to send the task status information to the message middleware so that the downstream business system consumes the task status information in the message middleware.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the spark-based task status monitoring method described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the spark-based task status monitoring method according to any one of claims 1 to 7 is implemented.
