X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fsimulator-group%2Fsim-monitor.js;h=f993410fc510c454ce3c4550accd5bb3cdae39b3;hb=d2aeca8843fe3ffca2e73dec5b64daeef0dda938;hp=da71a9e343dff7fac754f580419886e1b445f922;hpb=7a7a13a47eeebf9a61fa84d14af59b1cbe1598bc;p=nonrtric.git diff --git a/test/simulator-group/sim-monitor.js b/test/simulator-group/sim-monitor.js index da71a9e3..f993410f 100644 --- a/test/simulator-group/sim-monitor.js +++ b/test/simulator-group/sim-monitor.js @@ -17,50 +17,60 @@ # */ -// Sim mon server - query the agent and the simulators for counters and other data +// Sim mon server - query the a1pms and the simulators for counters and other data // Presents a web page on localhost:9999/mon var LOCALHOST="http://127.0.0.1:" var MRSTUB_PORT="3905" -var AGENT_PORT="8081" +var A1PMS_PORT="8081" var CR_PORT="8090" +var ICS_PORT="8083" +var PRODSTUB_PORT="8092" +var RC_PORT="8680" + var http = require('http'); var express = require('express'); +const { POINT_CONVERSION_HYBRID } = require('constants') var app = express(); var fieldSize=32; - +var flagstore={} //I am alive app.get("/",function(req, res){ res.send("ok"); }) -//Get parameter valuue from other server +//Get parameter value from other server function getSimCtr(url, index, 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', () => { - var code=resp.statusCode - if (code > 199 && code < 300) { - cb(data, index); - } else { - cb("not found", index); - } - }); - }).on("error", (err) => { - console.log("Error: " + err.message); - cb("no response", index); - }); -}; + try { + 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', () => { + var code=resp.statusCode + if (code > 199 && code < 300) { + cb(data, index); + } else { + cb("not found", index); + } + }); + + }).on("error", (err) => { + console.log("Error: " + err.message); + cb("no response", index); + }); + } catch(err) { + cb("no response", index); + } +} //Format a comma separated list of data to a html-safe string with fixed fieldsizes @@ -112,22 +122,51 @@ function formatIdRowCompact(commaList) { } //Pad a string upto a certain size using a pad string -function padding(val, fieldSize, pad) { +function padding(val, size, pad) { var s=""+val; - for(var i=s.length;i 10) { + //Reset flag after ten attempts + console.log("Force release flag "+flag) + flagstore[flag]=1 + return true + } else { + //Previous call not returned + console.log("Flag not available "+flag) + flagstore[flag]=flagstore[flag]+1 + return false + } + } else { + flagstore[flag]=1 + return true + } +} +//Clear flag for parameter +function clearFlag(flag) { + flagstore[flag]=0 +} + //Status variables, for parameters values fetched from other simulators var mr1="", mr2="", mr3="", mr4="", mr5="", mr6=""; -//Status variables for agent +//Status variables for a1pms var ag1="" var ag2="" var ag3="" var ag4="" +var ag5="" //Status variables for callback receiver var cr1="" @@ -144,23 +183,60 @@ var simvar1=[] var simvar2=[] var simvar3=[] var simvar4=[] +var simvar5=[] +var simvar6=[] + +//Status variables, for parameters values fetched from ics +var ics1="", ics2="", ics3="", ics4="", ics_types="-", ics_producers="-"; +var ics_producer_arr=new Array(0) +var ics_producer_type_arr=new Array(0) +var ics_producer_jobs_arr=new Array(0) +var ics_producer_status_arr=new Array(0) +var ics_jobs=new Array(0) +var ics_job_status=new Array(0) + +//Status variables, for parameters values fetched from prodstub +var ps2="", ps3="", ps4="", ps_types="-", ps_producers="-"; +var ps_producer_type_arr=new Array(0) +var ps_producer_jobs_arr=new Array(0) +var ps_producer_delivery_arr=new Array(0) + +//Full CR DB +var cr_db={} //Counts the number of get request for the html page var getCtr=0 -var refreshInterval=2000 +var refreshCount_pol=-1 + +var refreshCount_ics=-1 + +var refreshCount_cr=-1 -function fetchAllMetrics() { +var refreshCount_rc=-1 + +var ricbasename="ricsim" + +var rc_services="" + +var a1pmsprefix="" + +function fetchAllMetrics_pol() { + + console.log("Fetching policy metrics " + refreshCount_pol) + + if (refreshCount_pol < 0) { + refreshCount_pol = -1 + return + } else { + refreshCount_pol = refreshCount_pol - 1 + } setTimeout(() => { - console.log("Fetching all metics data") - if (refreshInterval < 20000) { - refreshInterval+=100 - } if (getCtr%3 == 0) { //Extract the port numbers from the running simulators, for every 3 calls const { exec } = require('child_process'); - exec('docker ps --filter "name=ricsim" --format "{{.Names}} {{.Ports}}" | sed s/0.0.0.0:// | cut -d \'>\' -f1 | sed \'s/[[-]]*$//\'', (err, stdout, stderr) => { + exec('docker ps --filter "name='+ricbasename+'" --filter "network=nonrtric-docker-net" --format "{{.Names}} {{.Ports}}" | sed s/0.0.0.0:// | cut -d \'>\' -f1 | sed \'s/[[-]]*$//\'', (err, stdout, stderr) => { var simulators = "" simulators=`${stdout}`.replace(/(\r\n|\n|\r)/gm," "); @@ -168,7 +244,7 @@ function fetchAllMetrics() { var sims=simulators.split(" ") simnames=[] simports=[] - for(i=0;i 1) { + ag2=ag2+", " + } + ag2=ag2+(jd[key]["serviceName"]).trim() + } + } + catch (err) { + ag2=data + } + clearFlag("ag2") + }); + } + if (checkFunctionFlag("ag3")) { + getSimCtr(LOCALHOST+A1PMS_PORT+"/policy_types", 0, function(data, idx) { + ag3=""; + try { + var jd=JSON.parse(data); + for(var key in jd) { + if (ag3.length > 0) { + ag3=ag3+", " + } + ag3=ag3+jd[key].trim() + } + } + catch (err) { + ag3="" + } + clearFlag("ag3") + }); + } - //Agent - get metrics from the agent - getSimCtr(LOCALHOST+AGENT_PORT+"/status", 0, function(data, index) { - ag1 = data; - }); - getSimCtr(LOCALHOST+AGENT_PORT+"/services", 0, function(data, index) { - ag2=""; - try { - var jd=JSON.parse(data); - for(var key in jd) { - if (ag2.length > 1) { - ag2=ag2+", " + if (checkFunctionFlag("ag4")) { + getSimCtr(LOCALHOST+A1PMS_PORT+"/policy_ids", 0, function(data, idx) { + try { + var jd=JSON.parse(data); + ag4=""+jd.length + } + catch (err) { + ag4="" + } + clearFlag("ag4") + }); + } + + if (checkFunctionFlag("ag5")) { + getSimCtr(LOCALHOST+A1PMS_PORT+"/rics", 0, function(data, idx) { + try { + var jd=JSON.parse(data); + ag5=""+jd.length + } + catch (err) { + ag5="" + } + clearFlag("ag5") + }); + } + + fetchAllMetrics_pol(); + + }, 500) +} + +function fetchAllMetrics_ics() { + + console.log("Fetching information metrics - timer:" + refreshCount_ics) + + if (refreshCount_ics < 0) { + refreshCount_ics = -1 + return + } else { + refreshCount_ics = refreshCount_ics - 1 + } + setTimeout(() => { + + if (checkFunctionFlag("ics_stat")) { + getSimCtr(LOCALHOST+ICS_PORT+"/status", 0, function(data, index) { + try { + var jd=JSON.parse(data); + ics1=jd["status"] + ics2=""+jd["no_of_producers"] + ics3=""+jd["no_of_types"] + ics4=""+jd["no_of_jobs"] + } + catch (err) { + ics1="error response" + ics2="error response" + ics3="error response" + ics4="error response" + } + }); + clearFlag("ics_stat") + } + if (checkFunctionFlag("ics_types")) { + getSimCtr(LOCALHOST+ICS_PORT+"/ei-producer/v1/eitypes", 0, function(data, index) { + var tmp_ics_types="-" + try { + var jd=JSON.parse(data); + for(var i=0;i 0) { - ag3=ag3+", " + catch (err) { + tmp_ics_types="error response" + } + ics_types = tmp_ics_types + }); + clearFlag("ics_types") + } + if (checkFunctionFlag("ics_producers")) { + getSimCtr(LOCALHOST+ICS_PORT+"/ei-producer/v1/eiproducers", 0, function(data, index) { + var tmp_ics_producers="-" + try { + var jd=JSON.parse(data); + var tmp_ics_producer_arr=new Array(jd.length) + for(var i=0;i { - console.log("Setting interval "+refreshInterval+"ms") -}, refreshInterval) + console.log("Fetching CR DB - timer:" + refreshCount_ics) -app.get("/mon",function(req, res){ + if (refreshCount_cr < 0) { + refreshCount_cr = -1 + return + } else { + refreshCount_cr = refreshCount_cr - 1 + } + setTimeout(() => { + if (checkFunctionFlag("cr_stat")) { + getSimCtr(LOCALHOST+CR_PORT+"/db", 0, function(data, index) { + try { + cr_db=JSON.parse(data); + } + catch (err) { + cr_db={} + } + }); + clearFlag("cr_stat") + } + fetchAllMetrics_cr(); + }, 500) +} + +function fetchAllMetrics_rc() { - refreshInterval=2000 + console.log("Fetching RC services - timer:" + refreshCount_ics) + + if (refreshCount_rc < 0) { + refreshCount_rc = -1 + return + } else { + refreshCount_rc = refreshCount_rc - 1 + } + setTimeout(() => { + + if (checkFunctionFlag("rc_stat")) { + getSimCtr(LOCALHOST+RC_PORT+"/services", 0, function(data, index) { + var tmp_serv="" + try { + var jd=JSON.parse(data); + for(var i=0;i 0) { + tmp_serv=tmp_serv+"," + } + tmp_serv=tmp_serv+jd[i]["name"] + } + + } + catch (err) { + tmp_serv="no_response" + } + rc_services=tmp_serv + }); + clearFlag("rc_stat") + } + fetchAllMetrics_rc(); + }, 500) +} + +// Monitor for CR db +app.get("/mon3",function(req, res){ + + console.log("Creating CR DB page - timer: " + refreshCount_ics) + + if (refreshCount_cr < 0) { + refreshCount_cr=5 + fetchAllMetrics_cr() + } + refreshCount_cr=5 + var json_str=JSON.stringify(cr_db, null, 1) + var htmlStr = "" + + "" + + "" + + ""+ //2 sec auto refresh + "CR DB dump"+ + "" + + "" + + json_str + + "" + + ""; + res.send(htmlStr); +}) + +// Monitor for ICS +app.get("/mon2",function(req, res){ + + console.log("Creating information metrics - timer: " + refreshCount_ics) + + if (refreshCount_ics < 0) { + refreshCount_ics=5 + fetchAllMetrics_ics() + } + refreshCount_ics=5 + + var summary=req.query.summary + + if (summary == undefined) { + return res.redirect('/mon2?summary=false'); + } //Build web page var htmlStr = "" + "" + "" + ""+ //2 sec auto refresh - "Policy Agent and simulator monitor"+ + "information coordinator service and producer stub"+ + "" + + "" + + "" + if (summary == "false") { + htmlStr=htmlStr+"

Set query param '?summary' to true to only show summary statistics.

" + } else { + htmlStr=htmlStr+"

Set query param '?summary' to false to only show full statistics

" + } + if (ics_job_status.length > 10) { + htmlStr=htmlStr+"
Avoid running the server for large number of producers and/or jobs
" + } + htmlStr=htmlStr+"
" + + "

Information Coordinator Service

" + + "" + + "Status:..........." + formatDataRow(ics1) + "
" + + "Producers:........" + formatDataRow(ics2) + "
" + + "Types:............" + formatDataRow(ics3) + "
" + + "Jobs:............." + formatDataRow(ics4) + "
" + + "
" + if (summary == "false") { + htmlStr=htmlStr+ + "

Details

" + + "" + + "Producer ids:....." + formatDataRow(ics_producers) + "
" + + "Type ids:........." + formatDataRow(ics_types) + "
" + + "
"; + for(var i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"+"
" + + "
" + } + + htmlStr=htmlStr+ + "

Producer stub

" + + "" + + "Producers:........" + formatDataRow(ps2) + "
" + + "Types:............" + formatDataRow(ps3) + "
" + + "Jobs:............." + formatDataRow(ps4) + "
" + + "
" + if (summary == "false") { + htmlStr=htmlStr+ + "

Details

" + + "" + + "Producer ids:....." + formatDataRow(ps_producers) + "
" + + "Type ids:........." + formatDataRow(ps_types) + "
" + + "
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" + htmlStr=htmlStr+s + } + } + } + htmlStr=htmlStr+ + "
" + + "" + + ""; + res.send(htmlStr); +}) + +// Monitor for policy management +app.get("/mon",function(req, res){ + + console.log("Creating policy metrics page " + refreshCount_pol) + + if (refreshCount_pol < 0) { + refreshCount_pol=5 + fetchAllMetrics_pol() + } + refreshCount_pol=5 + + if (refreshCount_rc < 0) { + refreshCount_rc=5 + fetchAllMetrics_rc() + } + refreshCount_rc=5 + + var bn=req.query.basename + a1pmsprefix=req.query.a1pmsprefix + + console.log("A1PMS"+a1pmsprefix) + if ((bn == undefined) || (a1pmsprefix == undefined)) { + getCtr=0 + return res.redirect('/mon?basename=ricsim&a1pmsprefix=/a1-policy/v2'); + } else { + ricbasename=bn + } + + + //Build web page + var htmlStr = "" + + "" + + "" + + ""+ //2 sec auto refresh + "Policy Management Service and simulator monitor"+ "" + "" + - "

Policy agent

" + + "" + + "

Change basename in url if other ric sim prefix is used

" + + "

Change a1pmsprefix in url if a1pms with other prefix is used

" + + "
" + + "

Policy Management Service

" + "" + "Status:..............................." + formatDataRow(ag1) + "
" + "Services:............................." + formatIdRowCompact(ag2) + "
" + "Types:................................" + formatIdRowCompact(ag3) + "
" + "Number of instances:.................." + formatDataRow(ag4) + "
" + + "Near-RT RICs:........................." + formatDataRow(ag5) + "
" + "
" + "

MR Stub interface

" + ""+ @@ -313,24 +966,29 @@ app.get("/mon",function(req, res){ "Fetched responses.............................." + formatDataRow(mr5) + "
" + "Current responses waiting......................" + formatDataRow(mr6) + "
" + "
"+ - "

Callback receiver

" + + "

Callback|Notification receiver

" + "" + "Callbacks received:..................." + formatDataRow(cr1) + "
" + "Callbacks fetched:...................." + formatDataRow(cr2) + "
" + "Number of waiting callback messages:.." + formatDataRow(cr3) + "
" + "
" + - "

Near-RT RIC Simulators

" + + "

R-APP Catalogue

" + + "" + + "Services:............................." + formatIdRowCompact(rc_services) + "
" + + "
" + + "

Near-RT RIC | A1 Simulators

" + "" htmlStr=htmlStr+padding("Near-RT RIC Simulator name", 35," ") htmlStr=htmlStr+padding("Types", 10," ") - htmlStr=htmlStr+padding("Instances", 10," ") - htmlStr=htmlStr+"
"+padding("",55,"=")+"
" - + htmlStr=htmlStr+padding("Instances", 12," ") + htmlStr=htmlStr+padding("Data delivery", 12," ")+"
" + htmlStr=htmlStr+padding("",70,"=")+"
" for(var simIndex=0;simIndex"; } @@ -346,6 +1004,16 @@ app.get("/mon",function(req, res){ htmlStr=htmlStr+"
"; } + htmlStr=htmlStr+"
"; + htmlStr=htmlStr+padding("Near-RT RIC Simulator name", 35," ") + htmlStr=htmlStr+padding("Remote hosts", 50," ")+"
" + htmlStr=htmlStr+padding("",90,"=")+"
" + for(simIndex=0;simIndex"; + } + htmlStr=htmlStr+ "" + ""; @@ -356,4 +1024,6 @@ 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.") \ No newline at end of file +console.log("Open the web page on localhost:9999/mon to view the policy statistics page.") +console.log("Open the web page on localhost:9999/mon2 to view the information statistics page.") +console.log("Open the web page on localhost:9999/mon3 to view CR DB in json.") \ No newline at end of file