Browse Source

添加 心跳监测 链路追踪

miaolijing 2 years ago
parent
commit
06e0374689
3 changed files with 98 additions and 4 deletions
  1. 49 0
      pom.xml
  2. 43 0
      src/main/resources/heartbeat-app.sh
  3. 6 4
      src/main/resources/log4j.properties

+ 49 - 0
pom.xml

@@ -216,5 +216,54 @@
             <version>3.4.1</version>
         </dependency>
 
+        <!-- 链路追踪 -->
+        <dependency>
+            <groupId>org.apache.skywalking</groupId>
+            <artifactId>apm-toolkit-log4j-1.x</artifactId>
+            <version>8.3.0</version>
+        </dependency>
+
     </dependencies>
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+            <!--拷贝资源文件 copy-resources-->
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-resources</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <resources>
+                                <resource>
+                                    <directory>src/main/resources/</directory>
+                                    <includes>
+                                        <include>**/*.xml</include>
+                                        <include>**/*.yml</include>
+                                        <include>**/icon/**</include>
+                                        <include>**/init/**</include>
+                                        <include>**/mapper/**</include>
+                                        <include>**/*.properties</include>
+                                        <include>**/version.txt</include>
+                                        <include>**/heartbeat-app.sh</include>
+                                    </includes>
+                                </resource>
+                            </resources>
+                            <outputDirectory>${project.build.directory}/config</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>

+ 43 - 0
src/main/resources/heartbeat-app.sh

@@ -0,0 +1,43 @@
+#/bin/sh
+
+post_json() {
+  response=`curl "${address}${url}" -X $request --connect-timeout 15 -m 20 --header 'Content-Type: application/json' -d "${data}" -o /dev/null -s -w %{http_code}`
+
+  if [ $response != '200' ];then
+    exit 3
+  fi
+}
+
+
+post_jsonstring() {
+    response=`curl "${address}${url}" -X $request --connect-timeout 15 -m 20 --header 'Content-Type: application/x-www-form-urlencoded' -d "jsonSting=${data}" -o /dev/null -s -w %{http_code}`
+
+    if [ $response != '200' ];then
+      exit 3
+    fi
+}
+
+if [ -n "$SERVER_PORT" ];then
+  port="$SERVER_PORT"
+elif [ -n "$PORT_DOCKER" ];then
+  port="$PORT_DOCKER"
+fi
+
+address="http://127.0.0.1:${port}"
+request='POST'
+type='json'
+url="/monitorIndicatorRecords/test"
+data='{}'
+
+
+# address="http://127.0.0.1:${port}"
+# request='POST'
+# type='jsonstring'
+# url="/Spring/MVC/entrance/unifier/getPersonByUserNameService"
+# data='{"user_id":"","pd":"","person_id":"","groupCode":"BR","puser":{"userId":"","loginDevice":"PC","pd":""},"loginName":"PERSAGYADMIN","loginDevice":"PC","isAdminLogin":true}'
+
+if [ "$type" = "json" ];then
+  post_json
+elif [ "$type" = "jsonstring" ];then
+  post_jsonstring
+fi

+ 6 - 4
src/main/resources/log4j.properties

@@ -9,16 +9,16 @@ log4j.logger.com.persagy.apm=DEBUG
 
 #输出到控制台
 log4j.appender.systemOut=org.apache.log4j.ConsoleAppender
-log4j.appender.systemOut.layout=org.apache.log4j.PatternLayout
-log4j.appender.systemOut.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %m%n
+log4j.appender.systemOut.layout=org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout
+log4j.appender.systemOut.layout.ConversionPattern =[energy-eq-run-diagnose] %d{yyyy-MM-dd HH\:mm\:ss} %TID %p ${PID} [%thread] %c %m%n
 log4j.appender.systemOut.Threshold=DEBUG
 log4j.appender.systemOut.ImmediateFlush=TRUE
 log4j.appender.systemOut.Target=System.out
 
 #info日志按DatePattern输出到文件 
 log4j.appender.logInfo=org.apache.log4j.RollingFileAppender
-log4j.appender.logInfo.layout=org.apache.log4j.PatternLayout
-log4j.appender.logInfo.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %m%n
+log4j.appender.logInfo.layout=org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout
+log4j.appender.logInfo.layout.ConversionPattern=[energy-eq-run-diagnose] %d{yyyy-MM-dd HH\:mm\:ss} %TID %p ${PID} [%thread] %c %m%n
 log4j.appender.logInfo.Threshold=DEBUG
 log4j.appender.logInfo.ImmediateFlush=TRUE
 log4j.appender.logInfo.File = ../logs/energy-eq-run-diagnose/log.log
@@ -26,3 +26,5 @@ log4j.appender.logInfo.File = ../logs/energy-eq-run-diagnose/log.log
 log4j.appender.logInfo.Encoding=UTF-8
 log4j.appender.logInfo.MaxFileSize=20MB
 log4j.appender.logInfo.MaxBackupIndex=10
+
+