Browse Source

修改合并bug

haoyanbing 8 năm trước cách đây
mục cha
commit
f50737ee6c

+ 18 - 0
config/applicationContext.xml

@@ -22,6 +22,7 @@
 				<ref bean="applicationSetting5" />
 				<ref bean="applicationSetting6" />
 				<ref bean="applicationSetting7" />
+				<ref bean="applicationSetting8" />
 			</list>
 		</property>
 	</bean>
@@ -38,6 +39,8 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:81/monitor"></property>
+		<property name="token" value="123456"></property>
 	</bean>
 	
 	<bean id="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
@@ -45,6 +48,8 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:82/activiti/explorer/monitor"></property>
+		<property name="token" value="123456"></property>
 	</bean>
 	
 	<bean id="applicationSetting4" class="com.leanwo.management.model.ApplicationSetting">
@@ -52,6 +57,8 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:83/monitor"></property>
+		<property name="token" value="123456"></property>
 	</bean>
 	
 	<bean id="applicationSetting5" class="com.leanwo.management.model.ApplicationSetting">
@@ -59,6 +66,8 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:80/monitor"></property>
+		<property name="token" value="123456"></property>
 	</bean>
 	
 	<bean id="applicationSetting6" class="com.leanwo.management.model.ApplicationSetting">
@@ -75,5 +84,14 @@
 		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
 	
+	<bean id="applicationSetting8" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="文件服务程序"></property>
+		<property name="installPath" value=""></property>
+		<property name="startBatFile" value=""></property>
+		<property name="stopBatFile" value=""></property>
+		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
+		<property name="token" value="123456"></property>
+	</bean>
+	
 	<bean id="springUtil" class="org.leanwo.management.util.SpringUtil" />
 </beans>

+ 37 - 0
src/main/java/com/leanwo/management/ServerManagmentJFrame.java

@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,6 +41,14 @@ import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.leanwo.management.util.SpringUtil;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
 
 import com.leanwo.management.model.ApplicationSetting;
 import com.leanwo.management.model.ApplicationSettingCache;
@@ -324,6 +333,34 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 						}
 					}
 				}
+				
+				// 监控各个服务程序是否正在运行
+				String url = setting.getMonitorUrl();
+				String token = setting.getToken();
+				if(url == null || "".equals(url) || token == null || "".equals(token)){
+					continue;
+				}
+				RestTemplate restTemplate = new RestTemplate();		
+				restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
+				HttpHeaders headers = new HttpHeaders();
+				headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+				headers.add("account", "2");
+				headers.add("token", token);
+				HttpEntity entity = new HttpEntity(headers);
+				try{			
+					ResponseEntity<Long> response = restTemplate.exchange(url, HttpMethod.GET, entity, Long.class);
+					((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
+					((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
+					Long result = response.getBody();
+					long mills = new Date().getTime() - result;
+					if(statusLabel != null){
+						statusLabel.setText("运行中(" + mills + "ms)");
+					}
+				}catch(Exception ex){
+					if(statusLabel != null){
+						statusLabel.setText("已停止");
+					}
+				}
 			}
 		}
 	}