add: eureka-ui 添加 startup 相关信息

This commit is contained in:
ywjno 2018-01-16 18:13:46 +08:00
parent 77a4e9f98d
commit f43038d754
3 changed files with 198 additions and 83 deletions

View File

@ -34,6 +34,7 @@ import com.netflix.eureka.EurekaServerContext;
import com.netflix.eureka.EurekaServerContextHolder;
import com.netflix.eureka.cluster.PeerEurekaNode;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl;
import com.netflix.eureka.resources.StatusResource;
import com.netflix.eureka.util.StatusInfo;
@ -76,6 +77,19 @@ public class EurekaServletStarter extends HttpServlet implements WebServletFace
+ "/");
populateBase(result);
if (pathInfo.endsWith("/status.json")) {
status(result);
lastn(result);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().println(Json.toJson(result, JsonFormat.tidy()));
} else {
response.setStatus(404);
}
}
private void status(NutMap result) {
populateApps(result);
StatusInfo statusInfo;
@ -89,14 +103,27 @@ public class EurekaServletStarter extends HttpServlet implements WebServletFace
result.put("statusInfo", statusInfo);
populateInstanceInfo(result, statusInfo);
filterReplicas(result, statusInfo);
if (pathInfo.endsWith("/status.json")) {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().println(Json.toJson(result, JsonFormat.tidy()));
} else {
response.setStatus(404);
}
private void lastn(NutMap result) {
PeerAwareInstanceRegistryImpl registry = (PeerAwareInstanceRegistryImpl) getRegistry();
List<NutMap> lastNCanceled = registry.getLastNCanceledInstances()
.stream()
.map(entry -> NutMap.NEW()
.setv("id", entry.second())
.setv("date",
new Date(entry.first())))
.collect(Collectors.toList());
result.put("lastNCanceled", lastNCanceled);
List<NutMap> lastNRegistered = registry.getLastNRegisteredInstances()
.stream()
.map(entry -> NutMap.NEW()
.setv("id", entry.second())
.setv("date",
new Date(entry.first())))
.collect(Collectors.toList());
result.put("lastNRegistered", lastNRegistered);
}
private PeerAwareInstanceRegistry getRegistry() {
@ -109,7 +136,6 @@ public class EurekaServletStarter extends HttpServlet implements WebServletFace
private void populateBase(NutMap result) {
result.put("time", new Date());
result.put("basePath", "/eureka");
populateHeader(result);
populateNavbar(result);
}

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,21 @@
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
function activeStatus() {
$('li.status').addClass("active");
$('li.lastn').removeClass("active");
$('#status').show();
$('#lastn').hide();
}
function activeLastn() {
$('li.status').removeClass("active");
$('li.lastn').addClass("active");
$('#status').hide();
$('#lastn').show();
}
</script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
@ -27,7 +42,12 @@
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a :href="home">Home</a></li>
<li class="active status">
<a href="javascript:void(0);" onclick="activeStatus()">Home</a>
</li>
<li class="lastn">
<a href="javascript:void(0);" onclick="activeLastn()">Last 1000 since startup</a>
</li>
</ul>
</div>
</div>
@ -113,6 +133,7 @@
</li>
</ul>
<div id="status">
<h1>Instances currently registered with Eureka</h1>
<table id='instances' class="table table-striped table-hover">
<thead>
@ -190,14 +211,75 @@
</tbody>
</table>
</div>
<div id="lastn" style="display: none">
<hr>
<div id="xd-jobs" class="tab-pane active col-md-12">
<ul class="nav nav-tabs" role="tablist" id="myTab">
<li class="active"><a data-toggle="tab" href="#cancelled">Last 1000 cancelled leases</a>
</li>
<li><a data-toggle="tab" href="#registered">Last 1000 newly registered leases</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="cancelled">
<table id='lastNCanceled' class="table table-striped table-hover">
<thead>
<tr>
<th>Timestamp</th>
<th>Lease</th>
</tr>
</thead>
<tbody>
<template v-for="entry in lastNCanceled">
<tr>
<td>{{ entry.date }}</td>
<td>{{ entry.id }}</td>
</tr>
</template>
<template v-if="lastNCanceled.length == 0">
<tr>
<td colspan="2">No results available</td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="tab-pane" id="registered">
<table id='lastNRegistered' class="table table-striped table-hover">
<thead>
<tr>
<th>Timestamp</th>
<th>Lease</th>
</tr>
</thead>
<tbody>
<template v-for="entry in lastNRegistered">
<tr>
<td>{{ entry.date }}</td>
<td>{{ entry.id }}</td>
</tr>
</template>
<template v-if="lastNRegistered.length == 0">
<tr>
<td colspan="2">No results available</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(function () {
$.getJSON('./js/status.json', function (data) {
new Vue({
el: 'nav',
data: {home: data.basePath + '/status'}
data: {home: data.basePath + 'status.html'}
});
new Vue({
el: '#content',