Commit bc7a21f9 by amir

add Metrics view in html

parent a2f7bf4a
...@@ -39,5 +39,8 @@ ...@@ -39,5 +39,8 @@
4 Mitfanen :sleeping: 4 Mitfanen :sleeping:
### Metrics
To see the Metrics go to /_mon/_stat to get in json
to see in html go to /static/metrics.html
### ZMQRestService ### ZMQRestService
![alt text](ZMQRestService.png) ![alt text](ZMQRestService.png)
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
addTest(nsMicroservice_Iface::ITest *p_testClass) addTest(nsMicroservice_Iface::ITest *p_testClass)
*- Add true async in http rest service, that we can send response after handleRequest ends. +- Add true async in http rest service, that we can send response after handleRequest ends.
// exchange.dispatch(() -> { // exchange.dispatch(() -> {
// new Timer().schedule(new TimerTask() { // new Timer().schedule(new TimerTask() {
// public void run() { // public void run() {
...@@ -20,5 +20,6 @@ ...@@ -20,5 +20,6 @@
// } // }
// }, 5000); // }, 5000);
// }); // });
- ZMQ : All sockets must be handled from the same thread who created them.
so we can use Rx or my ipc or zmq ipc for event loops - add static page for monitor metrics that calls http://localhost:32000/_mon/_stat?viewType=list
\ No newline at end of file periodically via jquery and display the metrics in a table
\ No newline at end of file
...@@ -65,7 +65,7 @@ public class MicroserviceApp ...@@ -65,7 +65,7 @@ public class MicroserviceApp
Map<String, microservice.MicroserviceClient> msClientMap = null; Map<String, microservice.MicroserviceClient> msClientMap = null;
List<IRestServer> serverList = null; List<IRestServer> serverList = null;
Optional<MonitorHandler> optMonitorHandler = Optional.empty(); Optional<MonitorHandler> optMonitorHandler = Optional.empty();
/////////////// new design services /////////////////// /////////////// new design microservice ///////////////////
Reactor reactor; Reactor reactor;
public MicroserviceApp(String appName) public MicroserviceApp(String appName)
...@@ -525,7 +525,7 @@ public class MicroserviceApp ...@@ -525,7 +525,7 @@ public class MicroserviceApp
/******** SERVICES DESIGN **********************************************/ /******** SERVICES DESIGN **********************************************/
/*************************************************************************/ /*************************************************************************/
// //
/// the services array /// the microservice array
//private final List<Map<String,CommonServices.IService>> servicesArray = new ArrayList<>(Enums.EnumServiceType.values().length); //private final List<Map<String,CommonServices.IService>> servicesArray = new ArrayList<>(Enums.EnumServiceType.values().length);
private final Map<String,CommonServices.IService>[] servicesArray = new Map[Enums.EnumServiceType.values().length]; private final Map<String,CommonServices.IService>[] servicesArray = new Map[Enums.EnumServiceType.values().length];
...@@ -601,7 +601,7 @@ public class MicroserviceApp ...@@ -601,7 +601,7 @@ public class MicroserviceApp
reactor.init(logger); reactor.init(logger);
/** /**
* init services * init microservice
* iterating only over non empty elements * iterating only over non empty elements
*/ */
Arrays.stream(servicesArray) Arrays.stream(servicesArray)
......
...@@ -21,7 +21,7 @@ public class RestServerParams ...@@ -21,7 +21,7 @@ public class RestServerParams
public RestServerParams(int port, String host,int workerThreadsNum) public RestServerParams(int port, String host,int workerThreadsNum)
{ {
super(); super();
setParams(port, host, workerThreadsNum, "localhost", false, 0, 1883); setParams(port, host, workerThreadsNum, "localhost", true, 0, 1883);
} }
......
...@@ -27,7 +27,6 @@ import microservice.io.impl.IRequestRestImpl; ...@@ -27,7 +27,6 @@ import microservice.io.impl.IRequestRestImpl;
import microservice.io.impl.IResponseRestImpl; import microservice.io.impl.IResponseRestImpl;
import microservice.params.CommandParams; import microservice.params.CommandParams;
import microservice.params.RestServerParams; import microservice.params.RestServerParams;
import microservice.services.CommonServices;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import microservice.types.UserProfile; import microservice.types.UserProfile;
...@@ -316,9 +315,10 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -316,9 +315,10 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
apiDocMimeMappingsBuilder.addMapping("json", "text/json"); apiDocMimeMappingsBuilder.addMapping("json", "text/json");
apiDocMimeMappingsBuilder.addMapping("yaml", "text/x-yaml"); apiDocMimeMappingsBuilder.addMapping("yaml", "text/x-yaml");
apiDocMimeMappingsBuilder.addMapping("html", "text/html"); apiDocMimeMappingsBuilder.addMapping("html", "text/html");
pathHandler.addPrefixPath("/static", resource(new ClassPathResourceManager(getClass().getClassLoader(),"static")) pathHandler.addPrefixPath("/static", resource(new ClassPathResourceManager(getClass().getClassLoader(),getClass().getPackage()))//"static"))
.addWelcomeFiles("microservice/services/metrics.html")
.setMimeMappings(apiDocMimeMappingsBuilder.build()) .setMimeMappings(apiDocMimeMappingsBuilder.build())
.setDirectoryListingEnabled(true)); .setDirectoryListingEnabled(false));
} }
@Override @Override
......
...@@ -45,7 +45,7 @@ import static microservice.defs.Constants.EXIT_MSG_LEN; ...@@ -45,7 +45,7 @@ import static microservice.defs.Constants.EXIT_MSG_LEN;
* <img src="../../../../../../../doc/ZMQRestService.png" alt=""> * <img src="../../../../../../../doc/ZMQRestService.png" alt="">
* <p>Notes: <br> * <p>Notes: <br>
* - All ZMQ sockets must be handled from the thread that created them (zmq not thread safe)<br> * - All ZMQ sockets must be handled from the thread that created them (zmq not thread safe)<br>
* - Each Service has only one destination, for multiple destination create multiple zmq services * - Each Service has only one destination, for multiple destination create multiple zmq microservice
* </p> * </p>
* </p> * </p>
* <p> * <p>
......
...@@ -65,7 +65,7 @@ public class UserProfile extends DefaultClaims { ...@@ -65,7 +65,7 @@ public class UserProfile extends DefaultClaims {
public boolean isServiceAuthorized(String serviceName, CommonServices.EnumRestCommands enumRestCommands){ public boolean isServiceAuthorized(String serviceName, CommonServices.EnumRestCommands enumRestCommands){
boolean authorized = false; boolean authorized = false;
String serviceAuth = serviceAuthorizations.get(serviceName); String serviceAuth = serviceAuthorizations.get(serviceName);
if (serviceAuth == null) // check for all services authorizations if (serviceAuth == null) // check for all microservice authorizations
serviceAuth = serviceAuthorizations.get(ALL_SERVICES); serviceAuth = serviceAuthorizations.get(ALL_SERVICES);
if(serviceAuth != null) if(serviceAuth != null)
......
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>
<script>
// Builds the HTML Table out of myList.
function buildHtmlTable(data) {
var selector = '#meterTable';
var list = data.objectNode.meters;
var columns = addAllColumnHeaders(list, selector);
addRows(selector,columns,list);
selector = '#timerTable';
list = data.objectNode.timers;
columns = addAllColumnHeaders(list, selector);
addRows(selector,columns,list);
}
function addRows(selector,columns,myList){
for (var i = 0; i < myList.length; i++) {
var row$ = $('<tr/>');
for (var colIndex = 0; colIndex < columns.length; colIndex++) {
var cellValue = myList[i][columns[colIndex]];
if (cellValue == null) cellValue = "";
row$.append($('<td/>').html(cellValue));
}
$(selector).append(row$);
}
}
// Adds a header row to the table and returns the set of columns.
// Need to do union of keys from all records as some records may not contain
// all records.
function addAllColumnHeaders(myList, selector) {
var columnSet = [];
var headerTr$ = $('<tr/>');
for (var i = 0; i < myList.length; i++) {
var rowHash = myList[i];
for (var key in rowHash) {
if ($.inArray(key, columnSet) == -1) {
columnSet.push(key);
headerTr$.append($('<th/>').html(key));
}
}
}
$(selector).append(headerTr$);
return columnSet;
}
$(document).ready(function(){
$.get("http://localhost:32000/_mon/_stat?viewType=list", function(data, status){
buildHtmlTable(data);
});
});
</script>
</head>
<body>
<table id="meterTable" border="1">
</table>
<table id="timerTable" border="1">
</table>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment