|
@@ -0,0 +1,67 @@
|
|
|
+package cn.com.qmth.examcloud.web.mongodb;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.net.Inet4Address;
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.boot.ApplicationArguments;
|
|
|
+import org.springframework.boot.ApplicationRunner;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
+import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
+
|
|
|
+/**
|
|
|
+ * mongodb 侦察器
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年11月29日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Order(99)
|
|
|
+public class MongodbDetector implements ApplicationRunner {
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+ String appName = PropertyHolder.getString("spring.application.name");
|
|
|
+
|
|
|
+ String ip = null;
|
|
|
+ try {
|
|
|
+ InetAddress localHost = Inet4Address.getLocalHost();
|
|
|
+ ip = localHost.getHostAddress();
|
|
|
+ } catch (Exception e) {
|
|
|
+ // ingnore
|
|
|
+ }
|
|
|
+
|
|
|
+ Class<?> mongoTemplateClass = null;
|
|
|
+ try {
|
|
|
+ mongoTemplateClass = Class
|
|
|
+ .forName("org.springframework.data.mongodb.core.MongoTemplate");
|
|
|
+ Object mongoTemplateObject = SpringContextHolder.getBean(mongoTemplateClass);
|
|
|
+
|
|
|
+ Map<String, String> data = Maps.newHashMap();
|
|
|
+ data.put("startupTime", DateUtil.chinaNow());
|
|
|
+ data.put("appName", appName);
|
|
|
+ data.put("ip", ip);
|
|
|
+
|
|
|
+ Method insertMethod = mongoTemplateClass.getMethod("insert", Object.class,
|
|
|
+ String.class);
|
|
|
+ insertMethod.invoke(mongoTemplateObject, data, "startup");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // ingnore
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) throws Exception {
|
|
|
+ start();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|