spring-boot-admin源码分析及单机监控spring-boot-monitor的实现(三)

扫码关注公众号:Java 技术驿站

发送:vip
将链接复制到本浏览器,永久解锁本站全部文章

【公众号:Java 技术驿站】 【加作者微信交流技术,拉技术群】
免费领取10G资料包与项目实战视频资料
# # # SpringBootMonitor # ## [spring-boot-admin源码分析及单机监控spring-boot-monitor的实现(一)][spring-boot-admin_spring-boot-monitor] ## ## [spring-boot-admin源码分析及单机监控spring-boot-monitor的实现(二)][spring-boot-admin_spring-boot-monitor 1] ## [**spring-boot-admin源码分析及单机监控spring-boot-monitor的实现(三)**][spring-boot-admin_spring-boot-monitor 2] ## 1.spring-boot-monitor设计 ## > # # > > > > > 设计我们自己的springbootmonitor,就不能用springbootadmin的那套东西,需要自己画页面。 > > > 新建登陆页面login.html。 > > > > >``` > sbim monitor
> ``` > > > > 使用jquery与后台进行交互。 > > > > 2.spring-boot-monitor后台设计 ``` package com.cff.boot.monitor.web; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpRequest; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.cff.boot.monitor.config.MonitorProperties; import com.cff.boot.monitor.model.AppInfo; import com.cff.boot.monitor.model.SbimUser; import com.cff.boot.monitor.store.SimpleAppInfoStore; @WebController @RequestMapping("/sbim/api") @ResponseBody public class RestApiController { private final MonitorProperties monitorProperties; private final SimpleAppInfoStore simpleAppInfoStore; private String contextPath = "/"; public RestApiController(MonitorProperties monitorProperties, SimpleAppInfoStore simpleAppInfoStore) { this.monitorProperties = monitorProperties; this.simpleAppInfoStore = simpleAppInfoStore; contextPath = monitorProperties.getContextPath(); } @RequestMapping(value= "/login", method=RequestMethod.POST) public String login(@RequestParam String loginUsername, @RequestParam String loginPassword, HttpServletRequest req) { SbimUser sbimUser = new SbimUser(); sbimUser.setLoginUsername(loginUsername); sbimUser.setLoginPassword(loginPassword); if (monitorProperties.getUsername().equals(sbimUser.getLoginUsername()) && monitorProperties.getPassword().equals(sbimUser.getLoginPassword())){ req.getSession().setAttribute("sbimUser", sbimUser); return "success"; } else { return "failed"; } } @RequestMapping(value= "/appInfo", method=RequestMethod.POST) public List appInfo(HttpServletRequest req) { SbimUser sbimUser = (SbimUser) req.getSession().getAttribute("sbimUser"); if(sbimUser == null){ return null; } List lists = simpleAppInfoStore.getAll(); return lists; } @RequestMapping(value= "/appRemove", method=RequestMethod.POST) public List appRemove(HttpServletRequest req) { SbimUser sbimUser = (SbimUser) req.getSession().getAttribute("sbimUser"); if(sbimUser == null){ return null; } String appName = req.getParameter("appName"); simpleAppInfoStore.remove(appName); List lists = simpleAppInfoStore.getAll(); return lists; } } ``` 后台提供登陆接口,可以将登陆信息直接放入session,这样做的目的是可以不用使用springsecurity控制登陆。自己实现简单的登陆。 > # # > > > > # # 3.SimpleAppInfoStore应用信息存储 > # # > > > > 虽然是单机监控,我们还是要存储应用信息,方便与前台进行交互。 # # ``` package com.cff.boot.monitor.store; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import com.cff.boot.monitor.model.AppInfo; public class SimpleAppInfoStore { private final ConcurrentMap map = new ConcurrentHashMap<>(); public SimpleAppInfoStore() { } public void addApp(AppInfo appInfo){ map.put(appInfo.getAppId(), appInfo); } public void remove(String appId){ map.remove(appId); } public List getAll(){ List lists = new ArrayList(map.values()); return lists; } public AppInfo getApp(String appId){ return map.get(appId); } } ``` 类似于springbootadmin,我们都使用ConcurrentMap去存储应用信息,虽然并不必要。 这样,一个简单的监控登陆+首页已经ok了。剩下的就是不断添加前台页面和后台逻辑的问题了。 [spring-boot-admin_spring-boot-monitor]: http://blog.csdn.net/feiyangtianyao/article/details/78184153 [spring-boot-admin_spring-boot-monitor 1]: http://blog.csdn.net/feiyangtianyao/article/details/78184789 [spring-boot-admin_spring-boot-monitor 2]: http://blog.csdn.net/feiyangtianyao/article/details/78185617 ------- 来源:[http://ddrv.cn](http://ddrv.cn)
赞(0) 打赏
版权归原创作者所有,任何形式的转载请联系博主:daming_90:Java 技术驿站 » spring-boot-admin源码分析及单机监控spring-boot-monitor的实现(三)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏