X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fsimulator-group%2Fsim-monitor.js;h=7d7ffdf80533bc1c381417b3ae61b07944fe468c;hb=6a39814272307d0207222c9229b0d765ac062bf0;hp=d56ad7f97fbd4a500ed146978c13b77256b8b5c2;hpb=bbd2e9d44475fe20086d1d87a9e9a53a019ae8c8;p=nonrtric.git diff --git a/test/simulator-group/sim-monitor.js b/test/simulator-group/sim-monitor.js index d56ad7f9..7d7ffdf8 100644 --- a/test/simulator-group/sim-monitor.js +++ b/test/simulator-group/sim-monitor.js @@ -24,9 +24,13 @@ var LOCALHOST="http://127.0.0.1:" var MRSTUB_PORT="3905" var AGENT_PORT="8081" var CR_PORT="8090" +var ECS_PORT="8083" +var PRODSTUB_PORT="8092" + var http = require('http'); var express = require('express'); +const { POINT_CONVERSION_HYBRID } = require('constants') var app = express(); var fieldSize=32; @@ -37,11 +41,10 @@ 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 = ''; - console.log("URL: "+ url + " - ") try { http.get(url, (resp) => { // A chunk of data has been recieved. @@ -162,6 +165,7 @@ var ag1="" var ag2="" var ag3="" var ag4="" +var ag5="" //Status variables for callback receiver var cr1="" @@ -179,23 +183,51 @@ var simvar2=[] var simvar3=[] var simvar4=[] var simvar5=[] +var simvar6=[] + +//Status variables, for parameters values fetched from ecs +var ecs1="", ecs2="", ecs3="", ecs4="", ecs_types="-", ecs_producers="-"; +var ecs_producer_arr=new Array(0) +var ecs_producer_type_arr=new Array(0) +var ecs_producer_jobs_arr=new Array(0) +var ecs_producer_status_arr=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=4000 +var refreshCount_pol=-1 + +var refreshCount_ecs=-1 -function fetchAllMetrics() { +var refreshCount_cr=-1 + +var ricbasename="ricsim" + +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+'" --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," "); @@ -248,6 +280,12 @@ function fetchAllMetrics() { clearFlag("simvar5_"+index) }); } + if (checkFunctionFlag("simvar6_"+index)) { + getSimCtr(LOCALHOST+simports[index]+"/counter/datadelivery", index, function(data,index) { + simvar6[index] = data; + clearFlag("simvar6_"+index) + }); + } } //MR - get metrics values from the MR stub @@ -350,9 +388,9 @@ function fetchAllMetrics() { clearFlag("ag3") }); } + if (checkFunctionFlag("ag4")) { getSimCtr(LOCALHOST+AGENT_PORT+"/policy_ids", 0, function(data, index) { - ag4="" try { var jd=JSON.parse(data); ag4=""+jd.length @@ -364,23 +402,411 @@ function fetchAllMetrics() { }); } + if (checkFunctionFlag("ag5")) { + getSimCtr(LOCALHOST+AGENT_PORT+"/rics", 0, function(data, index) { + try { + var jd=JSON.parse(data); + ag5=""+jd.length + } + catch (err) { + ag5="" + } + clearFlag("ag5") + }); + } + + fetchAllMetrics_pol(); - fetchAllMetrics(); - }, refreshInterval) + }, 500) } -fetchAllMetrics(); +function fetchAllMetrics_ecs() { -setInterval(() => { - console.log("Setting interval "+refreshInterval+"ms") -}, refreshInterval) + console.log("Fetching enrichment metrics - timer:" + refreshCount_ecs) -app.get("/mon",function(req, res){ + if (refreshCount_ecs < 0) { + refreshCount_ecs = -1 + return + } else { + refreshCount_ecs = refreshCount_ecs - 1 + } + setTimeout(() => { + + if (checkFunctionFlag("ecs_stat")) { + getSimCtr(LOCALHOST+ECS_PORT+"/status", 0, function(data, index) { + ecs1="" + ecs2="" + ecs3="" + ecs4="" + try { + var jd=JSON.parse(data); + ecs1=jd["status"] + ecs2=""+jd["no_of_producers"] + ecs3=""+jd["no_of_types"] + ecs4=""+jd["no_of_jobs"] + } + catch (err) { + ecs1="error response" + ecs2="error response" + ecs3="error response" + ecs4="error response" + } + }); + + getSimCtr(LOCALHOST+ECS_PORT+"/ei-producer/v1/eitypes", 0, function(data, index) { + ecs_types="-" + try { + var jd=JSON.parse(data); + for(var i=0;i { + + if (checkFunctionFlag("cr_stat")) { + getSimCtr(LOCALHOST+CR_PORT+"/db", 0, function(data, index) { + ecs4="" + try { + cr_db=JSON.parse(data); + } + catch (err) { + cr_db={} + } + }); + clearFlag("cr_stat") + } + fetchAllMetrics_cr(); + }, 500) +} + +// Monitor for CR db +app.get("/mon3",function(req, res){ + + console.log("Creating CR DB page - timer: " + refreshCount_ecs) + + 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 ECS +app.get("/mon2",function(req, res){ + + console.log("Creating enrichment metrics - timer: " + refreshCount_ecs) + + if (refreshCount_ecs < 0) { + refreshCount_ecs=5 + fetchAllMetrics_ecs() + } + refreshCount_ecs=5 + + var summary=req.query.summary + + if (summary == undefined) { + return res.redirect('/mon2?summary=false'); + } //Build web page + var htmlStr = "" + + "" + + "" + + ""+ //2 sec auto refresh + "Enrichment 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

" + } + htmlStr=htmlStr+"
" + + "

Enrichment Coordinator Service

" + + "" + + "Status:..........." + formatDataRow(ecs1) + "
" + + "Producers:........" + formatDataRow(ecs2) + "
" + + "Types:............" + formatDataRow(ecs3) + "
" + + "Jobs:............." + formatDataRow(ecs4) + "
" + + "
" + if (summary == "false") { + htmlStr=htmlStr+ + "

Details

" + + "" + + "Producer ids:....." + formatDataRow(ecs_producers) + "
" + + "Type ids:........." + formatDataRow(ecs_types) + "
" + + "
"; + for(var i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(var i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(var 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(var i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(var i=0;i" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(var 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 + + var bn=req.query.basename + + if (bn == undefined) { + getCtr=0 + return res.redirect('/mon?basename=ricsim'); + } else { + ricbasename=bn + } + + //Build web page var htmlStr = "" + "" + "" + @@ -388,12 +814,16 @@ app.get("/mon",function(req, res){ "Policy Agent and simulator monitor"+ "" + "" + + "" + + "

Change basename in url if other ric sim prefix is used

" + + "
" + "

Policy agent

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

MR Stub interface

" + ""+ @@ -415,12 +845,14 @@ app.get("/mon",function(req, res){ 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"; } @@ -456,4 +888,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 enrichment statistics page.") +console.log("Open the web page on localhost:9999/mon3 to view CR DB in json.") \ No newline at end of file