// Sim mon server - query the simulators for counters and other data // Presents a web page on localhost:9999/mon var http = require('http'); var express = require('express'); var app = express(); var fieldSize=32; var dfcHeadings=[]; var dfcVal=[]; //I am alive app.get("/",function(req, res){ res.send("ok"); }) //Get parameter valuye from other server function getSimCtr(url, cb) { var data = ''; http.get(url, (resp) => { // A chunk of data has been recieved. resp.on('data', (chunk) => { data += chunk; }); // The whole response has been received. resp.on('end', () => { cb(data); }); }).on("error", (err) => { console.log("Error: " + err.message); cb("no response"); }); }; //Format a comma separated list of data to a html-safe string with fixed fieldsizes function formatDataRow(commaList) { var str = ""; var tmp=commaList.split(','); for(i=0;i0) { data = data+" "; len--; } str=str+data+"   "; } return str; } //Format a comma separated list of ids to a html-safe string with fixed fieldsizes function formatIdRow(commaList) { var str = ""; var tmp=commaList.split(','); for(i=0;i0) { data = data+" "; len--; } str=str+data+"   "; } return str; } //Format a list of ids to a html-safe string in compact format function formatIdRowCompact(commaList) { var str = ""; var tmp=commaList.split(','); for(i=0;i -1) { return; } else { dfc=dfc.replace(/\n/g, " "); dfc=dfc.replace(/\r/g, " "); var tmp=dfc.split(' '); var ctr=0 for(i=0;i0) { if (ctr%2==0) { dfcHeadings[ctr/2]=tmp[i]; } ctr=ctr+1; } } } } if (dfcHeadings.length > 0) { if (dfc.indexOf("no response") > -1) { dfcVal[idx]=[]; return; } else { dfc=dfc.replace(/\n/g, " "); dfc=dfc.replace(/\r/g, " "); var tmp=dfc.split(' '); var ctr=0 for(i=0;i0) { if (ctr%2==1) { dfcVal[idx][Math.trunc(ctr/2)]=""+tmp[i]; } ctr=ctr+1; } } } } } function padding(val, fieldSize, pad) { s=""+val; for(i=s.length;i" + "" + ""+ //5 sec auto refresh "DFC and simulator monitor"+ "" + "" + "

DFC apps

" + ""; // "dfc_app0: " + dfc0 + "
" + // "dfc_app1: " + dfc1 + "
" + // "dfc_app2: " + dfc2 + "
" + // "dfc_app3: " + dfc3 + "
" + // "dfc_app4: " + dfc4 + "
"; for(id=0;id<5;id++) { if (id==0) { str=str+padding("Instance",22,"."); str=str+" "+" "; } str=str+padding("dfc_app"+id,26, " "); str=str+" "+" "; } str=str+"
"; if (dfcHeadings.length > 0) { var hl=0; for(hl=0;hl 0) { val=""+padding(dfcVal[id][hl], 26, " "); } else { val=""+padding("-", 26, " "); } str=str+" "+" "+val; } str=str+"
"; } } str=str+"
"+ "

MR Simulator

" + ""+ "MR TC:........................................." + mr4 + "
" + "Configured filename prefixes:.................." + formatIdRowCompact(mr13) + "
" + "Status:........................................" + mr10 + "
" + "Execution time (mm.ss):........................" + mr6 + "
" + "Configured groups:............................." + formatIdRow(mr11) + "
" + "Configured change identifiers:................." + formatIdRow(mr12) + "
" + "Execution time from first poll (mm.ss):....... " + formatDataRow(mr8) + "
" + "Number of requests (polls):...................." + formatDataRow(mr1) + "
" + "Number of responses (polls):..................." + formatDataRow(mr2) + "
" + "Number of files in all responses:.............." + formatDataRow(mr9) + "
" + "Number of unique files in all responses:......." + formatDataRow(mr3) + "
" + "Number of events..............................." + formatDataRow(mr5) + "
" + "Number of unique PNFs.........................." + formatDataRow(mr7) + "
" + "
"+ "

DR Simulator

" + ""+ "DR TC:........................................." + dr8 + "
" + "Execution time (mm.ss):........................" + dr9 + "
" + "Configured feeds (feedId:filePrefix)..........." + formatIdRow(dr11) +"
" + "Number of queries:............................." + formatDataRow(dr1) + "
" + "Number of queries with bad file name prefix:..." + formatDataRow(dr12) + "
" + "Number of query responses, file published:....." + formatDataRow(dr2) + "
" + "Number of query responses, file not published:." + formatDataRow(dr3) + "
" + "Number of requests:............................" + formatDataRow(dr4) + "
" + "Number of requests with bad file name prefix:.." + formatDataRow(dr13) + "
" + "Number of responses with redirect:............." + formatDataRow(dr5) + "
" + "Number of responses without redirect:.........." + formatDataRow(dr6) + "
" + "Number of published files:....................." + formatDataRow(dr7) + "
" + "Number of double published files:.............." + formatDataRow(dr10) + "
" + "
"+ "

DR Redirect Simulator

" + "" + "DR REDIR TC:..................................." + drr3 + "
" + "Execution time (mm.ss):........................" + drr4 + "
" + "Publish speed (files/sec):....................." + drr9 + "
" + "Configured feeds (feedId:filePrefix)..........." + formatIdRow(drr7) +"
" + "Number of requests:............................" + formatDataRow(drr1) + "
" + "Number of requests with bad file name prefix:.." + formatDataRow(drr8) + "
" + "Number of responses:..........................." + formatDataRow(drr2) + "
" + "Downloaded volume (bytes):....................." + formatDataRow(drr6) + "
" + "Last publish (mm:ss):.........................." + formatDataRow(drr5) + "
" + "
"+ "" + ""; res.send(str); }) var httpServer = http.createServer(app); var httpPort=9999; httpServer.listen(httpPort); console.log("Simulator monitor listening (http) at "+httpPort); console.log("Open the web page on localhost:9999/mon to view the statistics page.")