1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.apps;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.lang.management.ManagementFactory;
17
18 import org.springframework.beans.factory.annotation.Value;
19 import org.springframework.stereotype.Controller;
20 import org.springframework.web.bind.annotation.GetMapping;
21 import org.springframework.web.servlet.ModelAndView;
22 import org.springframework.web.servlet.mvc.ParameterizableViewController;
23
24
25
26
27 @Controller
28 public class AjaxUptimeController extends ParameterizableViewController {
29
30 @GetMapping(path = "/uptime.ajax")
31 @Override
32 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
33 throws Exception {
34 return super.handleRequest(request, response);
35 }
36
37 @Override
38 protected ModelAndView handleRequestInternal(HttpServletRequest request,
39 HttpServletResponse response) throws Exception {
40 long uptimeStartValue = ManagementFactory.getRuntimeMXBean().getStartTime();
41 long uptime = System.currentTimeMillis() - uptimeStartValue;
42 long uptimeDays = uptime / (1000 * 60 * 60 * 24);
43
44 uptime = uptime % (1000 * 60 * 60 * 24);
45 long uptimeHours = uptime / (1000 * 60 * 60);
46
47 uptime = uptime % (1000 * 60 * 60);
48 long uptimeMins = uptime / (1000 * 60);
49
50 request.setAttribute("uptime_days", uptimeDays);
51 request.setAttribute("uptime_hours", uptimeHours);
52 request.setAttribute("uptime_mins", uptimeMins);
53
54 return new ModelAndView(getViewName());
55 }
56
57 @Value("ajax/uptime")
58 @Override
59 public void setViewName(String viewName) {
60 super.setViewName(viewName);
61 }
62
63 }